我有以下目录结构和库依赖项:
./lib-a
./lib-b (depending on lib-a)
每个目录都包含一个CMakeLists.txt
用于生成自己的库的文件。我正在使用源外构建策略。
为了说 lib-b 依赖于 lib-a,我根据官方 CMake 教程add_subdirectory(../lib-a lib-a)
所教的内容,将命令放入。通过这种方式,我获得了一个子目录是在../lib-b/CMakeLists.txt
lib-a
./lib-b/build dir
这不是我想要的行为。我想获得的是 CMake 在生成 lib-b 时引用 lib-a,如果尚未生成 lib-a,CMake 应该使用 CMakeLists.txt 在 ./lib-a/build 内部生成它lib-a(在处理依赖项时的行为类似于 make 工具的行为)。
我还想补充一点,在我的示例中我没有使用根 CMakeLists.txt,但我想要的是 lib-b/CMakeLists.txt 声明对 lib-a 的依赖,从而使 lib-a如果尚未编译,则使用其自己的 lib-a/CMakeLists.txt 进行编译。
这是目录结构及其内容:
lib-a/
CMakeLists.txt (for compiling lib-a)
src/
test.cpp
include/
test.hpp
lib-b/
main.cpp
CMakeLists.txt (for compiling lib-b; here is the point where I would like to make reference to lib-a, that I need for the generation of lib-b)
lib-b/main.cpp
还包含test.hpp
of lib-a
,因为它使用了 lib-a 的功能。这应该在规范中加以考虑lib-b/CMakeLists.txt
。
lib-a/CMakeLists.txt
和lib-b/CMakeLists.txt
文件这两个的内容应该是什么?