Incorrect Fortran module detection with Makefile generator and preprocessor conditionals
I'm trying to compile some external Fortran code that I cannot easily change. I encountered a problem with CMake's module detection for Fortran files which is likely related to #16590 and #16853.
The file in question looks like:
#if ( defined(FOO) )
MODULE foo
...
END MODULE foo
#else
MODULE bar
..
END MODULE bar
#endif
The problem is that CMake locates both foo and bar as modules and then assumes there will be *.mod files for both. At build time this leads to an error:
Error copying Fortran module "mod/foo". Tried "mod/FOO.mod" and "mod/foo.mod".
I use the Makefile generator and cannot switch to ninja.
Is there any work-around (no matter how hacky) for this particular problem? I somehow would have to tell CMake what modules there are actually in that file, overriding its own detection logic for this file only.