我有一个大型项目,可以通过cmake / make在linux和mac上很好地编译。我现在正尝试通过CMake生成Visual Studio解决方案以支持Windows。在add_library
和add_executable
调用之前,cmake项目运行一个自定义命令来生成一系列fortran文件,这些文件是后续库和可执行文件的源文件。在cmake生成的VS解决方案中,custom命令生成预期文件及其对应的.mod
。但是,似乎目标库和可执行文件在编译之前不会等待.mod
文件生成,因为我收到此错误:
error #7002: Error in opening the compiled module file. Check INCLUDE paths. [MYMOD_TYPES]
但是.mod
文件确实存在于应有的位置!实际上,如果我重建解决方案,目标成功编译,因为现在.mod
文件存在于目标构建之前。
这是我在cmake中配置库的示例:
# this is a cmake function for writing out the autogenerated code
generate_f90_types(src/MyLib.txt MyLib_Types.f90)
set(SOURCES
src/source1.f90
src/source2.f90
# Autogenerated files
MyMod_Types.f90 <-- This .f90 is autogenerated and the .mod files are not found before compiling mylib
)
add_library(mylib ${SOURCES})
target_link_libraries(mylib otherlibs)
install(TARGETS mylib
EXPORT "${CMAKE_PROJECT_NAME}Libraries"
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
是否有任何关于如何在cmake中将fortran .mod
作为依赖项添加到目标中的想法?