本文将以一个最小化的例子,介绍CMake的入门知识,包含以下内容:
目录结构
1 2 3 4 5 6 7 8 9 10
| ├─main.cpp ├─CMakeLists.txt ├─src │ └─lb1.cpp ├─lib │ └─liblb2.a ├─include │ ├─lib1.h │ └─lib2.h └─build
|
CMakeLists.txt 逐行解析
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| cmake_minimum_required(VERSION 3.18)
project(test CXX)
include_directories(./include)
find_library(LIB2 liblb2.a ./lib)
file(GLOB SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
add_library(MYLIB STATIC ${SOURCES})
add_executable(t ./main.cpp)
target_link_libraries(t PRIVATE MYLIB) target_link_libraries(t PRIVATE ${LIB2})
|
代码
CODE