在 CMakeLists 中添加包含预编译模块的目录
Add directory containing pre compiled module in CMakeLists
我正在为 Fortran 代码修改 CMakeLists.txt 文件。我需要添加一个包含预编译模块的目录。
我怎样才能在 CMakeLists.txt 中做到这一点?
有一个名为 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.
手动指定它们
希望对您有所帮助。
我正在为 Fortran 代码修改 CMakeLists.txt 文件。我需要添加一个包含预编译模块的目录。 我怎样才能在 CMakeLists.txt 中做到这一点?
有一个名为 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.
手动指定它们希望对您有所帮助。