我正在使用CMake构建一个由四个项目组成的应用程序:
每个项目(或CMake术语中的目标)位于其自己的子目录中,并具有自己的 CMakeLists.txt 文件。此外,还有一个顶层的 CMakeLists.txt 文件,将它们全部绑定(使用add_subdirectory
)。
在 b.dll , c.exe 和 d.exe 的 CMakeLists.txt 文件中,我正在使用target_link_libraries
将这些目标链接到 a.dll 和 b.dll 的导入库。这工作正常。到目前为止,非常好。
现在,在Visual Studio中,似乎CMake没有在解决方案的各个项目之间设置任何“项目依赖关系”:如果我转到项目 - &gt;项目依赖... ,我可以看到 b.dll 确实没有依赖 a.dll , c.exe < / em>既不依赖于 a.dll 也不依赖于 b.dll 等。结果是项目的构建顺序基本上是随机的,并且在实践中,解决方案根本无法构建(因为,例如, c.exe 是在 a.dll 之前构建的,因此相应的导入库 a.lib 尚未生成。)
我很困惑。我一直在网上寻找答案非常彻底,但没有运气(这让我觉得这对大多数CMake用户来说都不是问题,而且我一定做错了。)
请注意,我也尝试使用add_dependencies
命令,但这没有效果。
我正在使用CMake 2.8.1和Visual Studio 2008(9.0)。
谢谢, 弗朗兹
以下是 CMakeLists.txt 文件,供参考:
顶级 CMakeLists.txt :
add_subdirectory(a)
add_subdirectory(b)
add_subdirectory(c)
add_subdirectory(d)
A /的CMakeLists.txt :
add_library(a SHARED a.cpp)
B /的CMakeLists.txt :
add_library(b SHARED b.cpp)
target_link_libraries(b a)
# also tried to add add_dependencies(b a) here
C /的CMakeLists.txt :
add_executable(c c.cpp)
target_link_libraries(c a b)
# also tried to add add_dependencies(c a b) here
d /的CMakeLists.txt :
add_executable(d d.cpp)
target_link_libraries(d a b)
# also tried to add add_dependencies(d a b) here
答案 0 :(得分:0)
我的问题中描述的设置是正确的,并按预期工作。请参阅上面的评论。