【发布时间】:2015-10-22 15:59:35
【问题描述】:
我正在为 fortran 代码修改 CMakeLists.txt 文件。我需要添加一个包含预编译模块的目录。 如何在 CMakeLists.txt 中做到这一点?
【问题讨论】:
标签: compilation linker cmake fortran
我正在为 fortran 代码修改 CMakeLists.txt 文件。我需要添加一个包含预编译模块的目录。 如何在 CMakeLists.txt 中做到这一点?
【问题讨论】:
标签: compilation linker cmake fortran
有一个名为Fortran_MODULE_DIRECTORY的目标属性
为了更好地衡量,我还将模块目录添加为包含目录。 gfortran 在包含目录中查找 .mod 文件。
set_target_properties( Target PROPERTIES Fortran_MODULE_DIRECTORY "dir" )
target_include_directories(Target PUBLIC "dir" )
编辑
再次阅读您的问题,我看到您感兴趣的模块已经编译。 Fortran_MODULE_DIRECTORY 指定 PUT .mod 文件的位置,并将该目录添加为查找它们的位置。 target_include_directories 语句只是指定在哪里寻找它们。我最熟悉使用gfortran,它的手册页中有这个:
-Idir
These affect interpretation of the "INCLUDE" directive (as well as of the "#include" directive of the
cpp preprocessor).
Also note that the general behavior of -I and "INCLUDE" is pretty much the same as of -I with
"#include" in the cpp preprocessor, with regard to looking for header.gcc files and other such things.
This path is also used to search for .mod files when previously compiled modules are required by a
"USE" statement.
-Jdir
This option specifies where to put .mod files for compiled modules. It is also added to the list of
directories to searched by an "USE" statement.
The default is the current directory.
这就是 CMake 将为您和您的编译器做的事情;您不需要明确指定这些标志。在你的情况下,仅仅包含就足够了,因为模块已经被编译了。
但是,如果您发现它不适用于您的编译器,您可能必须通过设置变量 CMAKE_Fortran_FLAGS 手动指定它们。
希望这会有所帮助。
【讨论】: