目录结构
├── app
│ ├── app1
│ │ ├── app1.c
│ │ ├── app1.h
│ │ └── cmakelists.txt
│ └── cmakelists.txt
├── cmake
│ └── utils.cmake
├── cmakelists.txt
└── main
├── cmakelists.txt
└── main.c
结构说明
本章节主要目的是将头文件的代码组织编译成接口库(接口目标)
app目录存放应用层代码
cmake存放cmake include的代码
main中存放主函数代码
cmakelists.txt
cmakelits.txt最外层调用cmake/utils.cmake
最外层的cmakelists
cmake_minimum_required (version 3.5)
include (cmake/utils.cmake)
project(subprojects)
# add sub directories
# 定义子目录src,用以递归的调用src中的makelists.txt
add_subdirectory(app)
set(zc_lib
lib::app1
)
zc_add_executable(test_main "main/main.c" "${zc_lib}")
utils.cmake
function(zc_add_executable targetname srcs libs)
add_executable(${
targetname} ${
srcs})
target_link_libraries(${
targetname} ${
libs})
endfunction()
编译
略