Fortran: Cmake does not automatically add preprocessor -cpp flag
I have some fortran sources with preprocessor instructions. I usually compile them with ifort -cpp -DOPT1 -DOPT2 ...
in a Makefile. Now I'm trying to change to cmake, and to add these options I use target_compile_definitions(target PUBLIC OPT1)
. But when I run the compilation, the command shows only ifort -DOPT1 -DOPT2 ...
and therefore fails.
I've read that some compilers have this flag set by default, like gfortran:
-cpp -nocpp Enable preprocessing. The preprocessor is automatically invoked if the file extension is .fpp, .FPP, .F, .FOR, .FTN, .F90, .F95, .F03 or .F08. Use this option to manually enable preprocessing of any kind of Fortran file.
but it looks like this is not explicitly the case for ifort:
-cpp Runs the Fortran preprocessor on source files prior to compilation (same as the -fpp option).
Is there an option I missed in cmake to add this flag automatically or not ? If no, should it be added automatically if target_compile_definitions
with fortran is used ?
Thank you !
Edited by Brad King