cmake:添加依赖不在子目录中 [英] cmake: add dependency not in subdirectory
问题描述
我们假设有以下目录结构:
Let's say there's following directory structure:
root
|
+--projects
| |
| +-test
| |
| +-CMakeFiles.txt
|
+--libs
|
+-testlib
|
+-CMakeFiles.txt
test包含CMakeFiles.txt,testlib也包含CMakeFiles.txt 。 test生成可执行文件,testlib生成静态库。
test contains CMakeFiles.txt and testlib also contains CMakeFiles.txt. "test" produces executable and "testlib" produces static library.
我想要test链接到testlib而不使用符号链接,子目录test。
I want "test" to link with "testlib" without using symlinks and without moving "testlib" library into subdirectory within "test".
因为testlib不是test的子目录,所以我不能这样做
Because "testlib" isn't a subdirectory of "test", I can't do
add_subdirectory("../../libs/testlib")
在测试的CMakeFiles.txt - cmake将抱怨testlib不在测试子目录。
In test's CMakeFiles.txt - cmake will complain about "testlib" not being in "test" subdirectory.
此外,因为系统有几个不同的编译器,我不能只需将testlib库安装到某种中央目录中,因此我想测试编译testlib的本地副本并链接它(即如同testlib是一个子目录)。我还希望测试项目自动重建testlib,如果它已经改变。
Also, because system has several different compilers, I can't simply install "testlib" libraries into some kind of central directory, so I want test to compile local copy of testlib and link with it (i.e. as if testlib was a subdirectory). I also want "test" project to automatically rebuild "testlib" if it has been changed.
那么,我该如何处理呢? cmake 2.8.4,winxp sp3。
So, how can I deal with it? cmake 2.8.4, winxp sp3.
推荐答案
您可以在 root
,或者为 add_subdirectory
命令提供二进制目录;例如
You could either provide a top-level CMakeLists.txt in root
, or provide a binary directory to the add_subdirectory
command; e.g.
add_subdirectory("../../libs/testlib" "${CMAKE_CURRENT_BINARY_DIR}/testlib_build")
这将在当前构建目录中创建一个名为 testlib_build
的子目录
This creates a subdirectory called testlib_build
in your current build directory which contains the generated project files for testlib, but not the source.
有关更多信息,请运行
cmake --help-command ADD_SUBDIRECTORY
这篇关于cmake:添加依赖不在子目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!