├── 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中存放主函数代码
CMakeLits.txt最外层调用cmake/utils.cmake
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}")
function(zc_add_executable targetname srcs libs)
add_executable(${targetname} ${srcs})
target_link_libraries(${targetname} ${libs})
endfunction()
略