cmake可以自动添加fortran预处理器-cpp标志吗?

Rem*_*y F 5 fortran cmake

我有一些带有预处理器指令的 Fortran 源代码。我通常将它们编译ifort -cpp -DOPT1 -DOPT2 ...在 Makefile 中。现在我正在尝试更改为 cmake,并添加我使用的这些选项target_compile_definitions(target PUBLIC OPT1)。但是当我运行编译时,该命令仅显示ifort -DOPT1 -DOPT2 ...,因此失败。

我读到有些编译器默认设置了这个标志,比如 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.
Run Code Online (Sandbox Code Playgroud)

但 ifort 的情况似乎并非如此:

-cpp   Runs the Fortran preprocessor on source files prior
       to compilation (same as the -fpp option).
Run Code Online (Sandbox Code Playgroud)

我在 cmake 中是否错过了添加此标志的选项?如果不是,使用 cmake 命令手动添加它的正确方法是什么?

谢谢 !

Mik*_*e T 3

如果您有 CMake 3.18 或更高版本,请使用以下Fortran_PREPROCESS属性:

set_source_files_properties(
  file1.fpp file2.fpp
  PROPERTIES Fortran_PREPROCESS ON
)
Run Code Online (Sandbox Code Playgroud)