使用CMake在子目录中添加依赖项 [英] Add a dependency not in a subdirectory using CMake
问题描述
假设有以下目录结构:
root
|
+--projects
| |
| +-test
| |
| +-CMakeFiles.txt
|
+--libs
|
+-testlib
|
+-CMakeFiles.txt
test
包含 CMakeFiles.txt
和 testlib
还包含 CMakeFiles.txt
。 测试生成可执行文件,测试库生成静态库。
test
contains CMakeFiles.txt
and testlib
also contains CMakeFiles.txt
. "test" produces an executable and "testlib" produces a static library.
我希望测试与测试库链接,而无需使用符号链接,也无需移动测试库
I want "test" to link with "testlib" without using symlinks and without moving "testlib" library into a 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不在 test子目录中。
In test's CMakeFiles.txt
- CMake will complain about "testlib" not being in the "test" subdirectory.
另外,由于系统具有几种不同的编译器,所以我不能简单地将 testlib库安装到某种中央目录中,因此我想进行 test
编译 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 a local copy of testlib
and link with it (i.e. as if testlib
was a subdirectory). I also want the "test" project to automatically rebuild "testlib" if it has been changed.
那么,我该如何处理呢?我在Windows XP SP3上使用CMake 2.8.4。
So, how can I deal with it? I am using CMake 2.8.4 on Windows XP SP3.
推荐答案
您可以在以下位置提供顶级CMakeLists.txt 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屋!