0
我正在修改Fortran代碼的CMakeLists.txt文件。我需要添加一個包含預編譯模塊的目錄。 我該如何在CMakeLists.txt中做到這一點?在CMakeLists中添加包含預編譯模塊的目錄
我正在修改Fortran代碼的CMakeLists.txt文件。我需要添加一個包含預編譯模塊的目錄。 我該如何在CMakeLists.txt中做到這一點?在CMakeLists中添加包含預編譯模塊的目錄
良好的措施一個目標屬性,我還添加模塊目錄的目錄裏。 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來手動指定它們。
希望這會有所幫助。
set_target_properties暫停編譯其他模塊,所以我只是把target_include_directories,但我不知道我在做什麼。我是否需要向SET_TARGET_PROPERTIES添加一些內容? – Gonzague
@Gonzague查看編輯答案 – dwwork