cmake常用的一些命令
推荐网址:CMake 保姆级教程(上) | 爱编程的大丙
cmake_minimum_required(VERSION 3.0)
project(CALC)
# 增加-std=c++11
set(CMAKE_CXX_STANDARD 11)
# 指定输出的路径
set(HOME ${CMAKE_CURRENT_SOURCE_DIR})
# 可执行文件输出路径
set(EXECUTABLE_OUTPUT_PATH ${HOME}/bin)
# 设置动态库/静态库生成路径
set(LIBRARY_OUTPUT_PATH ${HOME}/lib)# 定义编译文件变量
# set(SRC add.c div.c main.c mult.c sub.c)
# 查找某个路径下的所有源文件
# CMAKE_CURRENT_SOURCE_DIR 指CMakeLists.txt 的路径
# aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SRC)
# file(GLOB SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.c)
# 包含头文件
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
# 生成可执行文件
# add_executable(app ${SRC})
# 生成静态库
# add_library(calc STATIC ${SRC})
# 生成动态库
# add_library(calc SHARED ${SRC})# 包含静态库或动态库路径
link_directories(${PROJECT_SOURCE_DIR}/lib)
# 链接静态库
# link_libraries(calc)
# aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SRC)
# 生成可执行文件
# add_executable(app ${SRC})
# 指定要链接的动态库
# target_link_libraries(app
# PUBLIC pthread
# PUBLIC calc)
# 输出一般日志信息
message(STATUS "PROJECT_SOURCE_DIR path: ${PROJECT_SOURCE_DIR}")
message(STATUS "CMAKE_CURRENT_SOURCE_DIR path: ${CMAKE_CURRENT_SOURCE_DIR}")
set(TEMP "hello,world")
file(GLOB SRC_1 ${PROJECT_SOURCE_DIR}/*.c)
file(GLOB SRC_2 ${PROJECT_SOURCE_DIR}/src/*.c)
# set 追加(拼接)
set(SRC_1 ${SRC_1} ${SRC_2} ${TEMP})
message(STATUS "set拼接: ${SRC_1}")
# list 追加(拼接)
list(APPEND SRC_1 ${SRC_1} ${SRC_2} ${TEMP})
message(STATUS "list拼接: ${SRC_1}")