设置库之间的依赖关系(cmake) [英] Setting dependencies between libraries (cmake)

查看:1513
本文介绍了设置库之间的依赖关系(cmake)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cmake来构建一个由十几个项目组成的应用程序。我们使用cmake为x86,x64以及VS 2005和2010自动生成解决方案。



这里是我们组织的一个想法:




  • a.lib没有依赖性

  • b.lib没有依赖性

  • c.lib,它取决于a和b

  • d.exe,这取决于c



每个项目都在其自己的子目录中,并且有自己的CMakeLists.txt文件。为了跟踪为我们的不同平台生成的lib / dll,我们使用_x86 / _x64和_vc80 / _vc100(例如,a_x86_vc100.lib)以及用于调试的_d自动后修复每个lib / dll(例如, a_x86_vc100_d.lib)。



在CMakeLists.txt文件中,我使用target_link_libraries链接每个目标与相应的库,例如:



< blockquote>

TARGET_LINK_LIBRARIES(c debug a _ $ {VS} _ $ {PLATFORM} d optimized
a
$ {VS_DIR} $ {PLATFORM} debug b $ {VS} _ $ {PLATFORM} d optimized
b
$ {VS_DIR} _ $ {PLATFORM})


在Visual Studio中,不同项目之间的不同项目依赖不会出现。



干杯,


$ b我不知道有没有什么我想念的,或者如果它不符合我们的图书馆修复。 $ b

Ludovic

解决方案

如果他们都在同一个项目中,我认为他们是,指定目标名称和调试/发行将为您处理。我认为您正在链接到实际的lib文件而不是目标。



尝试



TARGET_LINK_LIBRARIES )



TARGET_LINK_LIBRARIES(dc)#它知道c取决于a和b



/ p>

I am using cmake to build an application made up of a dozen projects. We use cmake to automatically generate solutions for x86, x64, and both VS 2005 and 2010.

Here is an idea of our organisation:

  • a.lib, which has no dependency
  • b.lib, which has no dependency
  • c.lib, which depends on a and b
  • d.exe, which depends on c

Each project lies in its own subdirectory, and has its own CMakeLists.txt file. In order to keep track of the lib/dll generated for our different platforms, we automatically post-fix each lib/dll with _x86/_x64 and _vc80/_vc100 (e.g., a_x86_vc100.lib), and with an _d for debug (e.g., 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:

TARGET_LINK_LIBRARIES( c debug a_${VS}_${PLATFORM}d optimized a${VS_DIR}${PLATFORM} debug b${VS}_${PLATFORM}d optimized b${VS_DIR}_${PLATFORM})

In Visual Studio, the different "Project Dependencies" between the various projects do not appear. I wonder if there is something I miss, or if it is simply not compatible with our library post-fix.

Cheers,

Ludovic

解决方案

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 lib 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!

这篇关于设置库之间的依赖关系(cmake)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆