Compilation 在CMakeLists中添加包含预编译模块的目录

Compilation 在CMakeLists中添加包含预编译模块的目录,compilation,linker,cmake,fortran,Compilation,Linker,Cmake,Fortran,我正在修改一个CMakeLists.txt文件以获取fortran代码。我需要添加一个包含预编译模块的目录。 如何在CMakeLists.txt中执行此操作 有一个名为 为了更好地度量,我还将模块目录添加为include目录gfortran在include目录中查找.mod文件 set_target_properties( Target PROPERTIES Fortran_MODULE_DIRECTORY "dir" ) target_include_directories(Target PU

我正在修改一个CMakeLists.txt文件以获取fortran代码。我需要添加一个包含预编译模块的目录。
如何在CMakeLists.txt中执行此操作

有一个名为

为了更好地度量,我还将模块目录添加为include目录
gfortran
在include目录中查找
.mod
文件

set_target_properties( Target PROPERTIES Fortran_MODULE_DIRECTORY "dir" )
target_include_directories(Target PUBLIC "dir" )
编辑

再读一遍你的问题,我发现你感兴趣的模块已经编译好了
Fortran\u模块\u目录
指定将
.mod
文件放在何处,并将该目录添加为查找文件的位置
target\u include\u目录
语句只指定在何处查找它们。我最熟悉使用
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手动指定它们


希望这有帮助。

有一个名为

为了更好地度量,我还将模块目录添加为include目录
gfortran
在include目录中查找
.mod
文件

set_target_properties( Target PROPERTIES Fortran_MODULE_DIRECTORY "dir" )
target_include_directories(Target PUBLIC "dir" )
编辑

再读一遍你的问题,我发现你感兴趣的模块已经编译好了
Fortran\u模块\u目录
指定将
.mod
文件放在何处,并将该目录添加为查找文件的位置
target\u include\u目录
语句只指定在何处查找它们。我最熟悉使用
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手动指定它们


希望这能有所帮助。

set\u target\u属性会停止编译其他模块,所以我只放置target\u include\u目录,但我不知道我在做什么。我需要添加一些东西来设置\u TARGET\u属性吗?设置\u TARGET\u属性会停止编译其他模块,所以我只放了TARGET\u include\u目录,但我不知道我在做什么。我需要添加一些东西来设置\u TARGET\u属性吗?