Cmake笔记
最简单的,只有一个源文件的 CMakeList.txt: cmake_minimum_required (VERSION 2.8) project (learn_cmake) add_executable(hello hello.cpp) $ mkdir build $ cd build/ $ cmake .. $ make 定义变量 set(SRC_LIST 1.c 2.c 3.c) add_executable(app ${SRC_LIST}) 通过EXECUTABLE_PUTPUT_PATH可以指定输出路径: set(HOME /home/xyc) set(EXECUTABLE_OUTPUT_PATH ${HOME}/bin) 搜索文件 方式 1:aux_source_directory 方式 2:file file(GLOB/GLOB_RECURSE 变量名 要搜索的文件路径和文件类型) file(GLOB app_sources src/*.c) target_sources(app PRIVATE ${app_sources}) GLOB: 将指定目录下搜索到的满足条件的所有文件名生成一个列表,并将其存储到变量中。 GLOB_RECURSE:递归搜索指定目录,将搜索到的满足条件的文件名生成一个列表,并将其存储到变量中。 包含头文件 include_directories(path) 动态库/静态库 制作静态库 add_library(库名称 STATIC 源文件1 [源文件2] ...) # 指定静态库输出路径 set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) 制作动态库 add_library(库名称 SHARED 源文件1 [源文件2] ...) # 指定动态库输出路径 set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) # 动态库默认是有执行权限的,可以通过这种方式。 链接静态库 # 指明库路径 link_directories(${PROJECT_SOURCE_DIR}/lib) # 链接库 link_libraries(calc) # 可以是全名libxxx....