【发布时间】:2011-02-23 13:32:32
【问题描述】:
我正在尝试将我的项目迁移到 CMake,同时对编译过程进行一些优化。
这是交易:
- 我有几个子目录(必须)每个都编译成一个静态库(这可行)。
- 我想将每个子目录中的所有目标文件收集到另一个更大、更完整的静态库中。
看起来像这样:
.
libBig.a # made from object from subdir1 and subdir2
subdir1/
src/
libSubdir1.a
subdir2/
src/
libSubdir2.a
今天,我设法使用了一个全局变量,其中每个子目录 CMakeLists.txt 都将附加自己的源文件。我在我的大库中将此变量用作“源”输入:
# the big library depends on all the source files
# ${all_src} is automatically filled with each subdir's cpp file
get_property( BigLib_src GLOBAL PROPERTY all_src)
add_library( Big STATIC ${BigLib_src}) # recompiles all the sources
现在,这行得通,还不错,但问题是,我所有的源文件都被编译了两次:一次用于 subdir 库,一次用于大库。
CMake 似乎忘记了它已经构建了它们。
我有保留子目录库,ar 不能合并两个静态库。
你知道怎么做吗?
【问题讨论】:
-
你是从什么迁移到 CMake 的?为什么?
-
来自手工制作的 Makefile!我希望它易于跨平台编译,易于与 IDE 集成,我想:为什么不呢?