入门资料
https://www.cnblogs.com/sarexpine/p/17508589.html
https://baijiahao.baidu.com/s?id=1764572770560078399&wfr=spider&for=pc
专栏:https://blog.youkuaiyun.com/mataojie/category_11464097.html
常用预定义变量
使用变量的方式与shell脚本类似,${Var},Var是变量名
PROJECT_SOURCE_DIR:CMakeLists.txt文件所在的文件夹
链接已有静态库
假定静态库文件为libmine.a,可使用如下方法
add_executable(main main.cpp)
target_link_libraries(main ${CMAKE_SOURCE_DIR}/libmine.a)
增加字符串型选项
set(OPT "Default" CACHE STRING "Helpstring")
静态编译
option(STATICCOMPILE "Compile to static executable" ON)
if (STATICCOMPILE)
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
SET(CMAKE_EXE_LINKER_FLAGS "-static")
endif()
定义源代码中宏
OPTION(USE_MACRO "Build the project using macro" OFF)
IF(USE_MACRO)
add_definitions("-DUSE_MACRO")
endif()
运行 cmake -DUSE_MACRO=on 时,源代码中的#ifdef USE_MACRO 里的代码模块就会被编译
【待续】