简体   繁体   English

设置库之间的依赖关系(CMake)

[英]Setting dependencies between libraries (CMake)

I am using CMake to build an application made up of a dozen projects. 我正在使用CMake来构建由十二个项目组成的应用程序。 We use CMake to automatically generate solutions for x86, x64, and both Visual Studio 2005 and Visual Studio 2010. 我们使用CMake自动为x86,x64和Visual Studio 2005和Visual Studio 2010生成解决方案。

Here is an idea of our organisation: 这是我们组织的构想:

  • a.lib, which has no dependency a.lib,没有依赖性
  • b.lib, which has no dependency b.lib,没有依赖性
  • c.lib, which depends on a and b c.lib,取决于a和b
  • d.exe, which depends on c d.exe,取决于c

Each project lies in its own subdirectory and has its own CMakeLists.txt file. 每个项目都位于其自己的子目录中,并具有其自己的CMakeLists.txt文件。 In order to keep track of the library/DLL file generated for our different platforms, we automatically post-fix each library/DLL file with _x86/_x64 and _vc80/_vc100 (eg, a_x86_vc100.lib), and with an _d for debug (eg, a_x86_vc100_d.lib). 为了跟踪为我们的不同平台生成的库/ DLL文件,我们使用_x86 / _x64和_vc80 / _vc100(例如a_x86_vc100.lib)以及_d自动调试每个库/ DLL文件(用于调试(例如a_x86_vc100_d.lib)。

In the CMakeLists.txt files, I use target_link_libraries to link each target with the corresponding libraries, for instance: CMakeLists.txt文件中,我使用target_link_libraries将每个目标链接到相应的库,例如:

TARGET_LINK_LIBRARIES( c debug a_${VS}_${PLATFORM} d optimized a ${VS_DIR} ${PLATFORM} debug b ${VS}_${PLATFORM} d optimized b ${VS_DIR}_${PLATFORM}) TARGET_LINK_LIBRARIES(c调试a _ $ {VS} _ $ {PLATFORM} d优化了 $ {VS_DIR} $ {PLATFORM}调试b $ {VS} _ $ {PLATFORM} d优化了b $ {VS_DIR} _ $ {PLATFORM})

In Visual Studio, the different "Project Dependencies" between the various projects do not appear. 在Visual Studio中,各个项目之间不会出现不同的“项目依赖关系”。 I wonder if there is something I miss, or if it is simply not compatible with our library post-fix. 我想知道是否有什么我想念的东西,或者根本就跟我们的库后缀不兼容。

If they are all in the same project, which I think that they are, you only need to specify the target name and the debug/release will be handled for you. 如果它们都在同一个项目中(我认为它们是同一项目),则只需指定目标名称,调试/发布便会为您处理。 I think that you are linking to the actual library file instead of the target. 我认为您正在链接到实际的库文件而不是目标。

Try: 尝试:

TARGET_LINK_LIBRARIES(c a b)

TARGET_LINK_LIBRARIES(d c)  # It knows that c depends on a and b

That is it! 这就对了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM