1.cmake_minimum_required(VERSION 3.7.1) cmake最低版本
2.project
Sets the name of the project, and stores it in the variable PROJECT_NAME
. When called from the top-level CMakeLists.txt
also stores the project name in the variable CMAKE_PROJECT_NAME
.
3.set(SOURCE_FILES main.c)
用SOURCE_FILES代替文件main.c
4.message(STATUS "This is BINARY dir " ${PROJECT_BINARY_DIR})
${PROJECT_BINARY_DIR}:CMakeLists.txt所在目录,在终端会打印如下内容:
This is BINARY dir /home/zzz/WorkSpace/Program/learning-cmake/hello-world
5.add_executable(hello-world ${SOURCE_FILES})
hello-world:最后生成可执行文件名称
6.add_subdirectory(src)
添加一个子目录去编译
7.add_library(hello_dynamic SHARED ${LIBHELLO_SRC}
用源文件生成动态库
8.add_library(hello_static STATIC ${LIBHELLO_SRC}
用源文件生成静态库
原文:https://www.cnblogs.com/aelite/p/10977185.html