I use CMake to build a project that consists of multiple nested static libraries .A similar but simple structure is shown in the figure below:
TestProject:
|-CMakeLists.txt
|-Main.cpp
|-level2
| | - level2.cpp
| | - level2.h
| | - CMakeLists.txt
| | - level1
| | |-level1.cpp
| | |-level1.h
| | |-CMakeLists.txt
Run Code Online (Sandbox Code Playgroud)
现在,我使用 CMake 分别为每个级别构建静态库。根据我的测试,每一层的静态库只包含该层的.cpp和.h文件。但是我想在生成每一层的静态库时,将它与上一层引用的库结合起来。例如,我首先构建级别1的静态库。然后,在级别2的CMakeLists.txt中,我创建依赖于级别1的静态库的级别2的静态库( target_link_libraries(${PROJECT_NAME} LEVEL1) ) ,然后,我想将级别 2 和级别 1 的库合并到一个名为 level1_2.lib 的新静态库文件中。
这是我的 Level1 中的 CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
#projcet name
project(LEVEL1 LANGUAGES CXX)
add_library( ${PROJECT_NAME} …Run Code Online (Sandbox Code Playgroud)