目录
Cmake 学习日志...........................................................................................................................................1
一、编译构建一个简单的源程序 ....................................................................................................3
1.编写一个 CMakeLists.txt ........................................................................................................3
2.在相同目录下创建.cpp 文件、build 目录 .........................................................................3
二、为工程添加头文件......................................................................................................................4
① 先创建一个头文件,TutorialConfig.h.in ..........................................................................4
②重新配置 CMakeLists.txt 文件 .............................................................................................4
☆为工程加上 C++11 特性-CMAKE_CXX_STANDARD .....................................................7
三、为工程添加库 library .................................................................................................................8
①如何生成库 ..............................................................................................................................8
② 如何使用库 ..............................................................................................................................9
③ 设置库为可选的 .................................................................................................................. 10
④ ★为库增加使用要求.......................................................................................................... 13
第四步-安装与测试 ......................................................................................................................... 16
1.测试安装 ................................................................................................................................. 16
2.测试支持 ................................................................................................................................. 17
第五步-添加系统自检(System Introspection) ..................................................................... 19
1.CheckSymbolExists 模块 ..................................................................................................... 19
2.在 TutorialConfig.h 头文件中定义上述模块变量 ......................................................... 20
3.然后在 MathFunctions/mysqrt.cpp 文件中使用它们。 .............................................. 20
4.需要修改 MathFunctions/CMakeLists.txt,让 mysqrt.cpp 知道该头文件在哪。. 22
★优化上述过程-指定编译定义 .......................................................................................... 22
六、CMakeLists.txt 自定义命令以及动态生成文件 ................................................................. 23
在 MathFunctions 目录下创建用于生成表的源文件 MakeTable.cpp......................... 24
配置 MathFunctions/CMakeLists.txt 让其生成 MakeTable 的可执行文件 ................ 24
在 mysqtr.cpp 源文件中引入头文件 Table.h,重写 mysqrt.cpp ................................. 25
第七步-构建安装程序 ..................................................................................................................... 26
CPakc 模块 ................................................................................................................................ 26
①加入模块 InstallRequiredSystemLibraries ...................................................................... 26
②设置一些 CPack 变量,用于设置存储该工程的发行信息文件、版本信息等。 26
③将 CPack 模块包含进来 ..................................................................................................... 27
④按照正常顺序,先构建工程(build) ................................................................................. 27
⑤是 cmake --build . 目录列表如下(就多了一个可执行文件): ........................... 27
⑥然后执行 cpack,目录列表如下 ..................................................................................... 27
cpack 命令 ................................................................................................................................. 27
⑧验证生成的安装包 .............................................................................................................. 28
第八步-增加仪表板(Dashboard)支持 ................................................................................... 28
①引入 CTest 模块 ................................................................................................................... 28
②创建 CTestConfig.cmake 文件.......................................................................................... 28
第九步-如何构建静态库和动态库 ............................................................................................... 28
第十步-增加生成器表达式(Generator Expressions) ......................................................... 34
第十一步-增加输出配置 ................................................................................................................ 35