推荐一个示例仓库

https://github.com/ttroy50/cmake-examples.git 入门CMake,看这个仓库就可以了

2021/10/25

  1. .
  2. ├── 01-basic
  3. | ├── A-hello-cmake
  4. │ ├── B-hello-headers .h;.cpp分开管理
  5. │ ├── C-static-library 静态库
  6. │ ├── D-shared-library 动态库
  7. │ ├── E-installing 分模块管理;安装
  8. │ ├── F-build-type 编译类型
  9. │ ├── G-compile-flags 编译标记
  10. │ ├── H-third-party-library 使用第三方库
  11. │ ├── I-compiling-with-clang 使用clang编译器
  12. │ ├── J-building-with-ninja 使用Ninja构建工程
  13. │ ├── J-building-with-ninja 使用Ninja构建工程
  14. │ ├── K-imported-targets 引用第三方库指定模块
  15. │ └── L-cpp-standard 指定C++的版本
  16. |
  17. ├── 02-sub-projects 划分子模块
  18. | ├── subbinary exe工程
  19. │ ├── sublibrary1 有cpp文件的子工程
  20. │ └── sublibrary2 纯接口的子工程
  21. |
  22. ├── 03-code-generation 代码生成
  23. | ├── configure-files 使用CMake的configure_file功能,将CMake的变量注入到C++中
  24. | └── protobuf 使用protobuf生成C++的源代码文件
  25. |
  26. ├── 04-static-analysis 静态分析(不执行代码的分析,用于发现常见的编程错误、执行编码准则)
  27. | ├── clang-analyzer clang分析与scan-build工具
  28. | ├── clang-format 使用Clang格式来检查代码风格
  29. | ├── cppcheck 使用CppCheck工具做静态分析
  30. | └── cppcheck-compile-commands 如何使用项目和编译数据库
  31. |
  32. ├── 05-unit-testing 单元测试
  33. | ├── google-test-download Google测试(自动下载GoolgeTest)
  34. | ├── catch2-vendored
  35. | └── boost
  36. |
  37. ├── 06-installer 用CPack创建安装程序
  38. | ├── deb 生成linux安装包
  39. │ │ ├── i-basic
  40. | │ └── ii-basic-targets
  41. |
  42. └── 07-package-management 包管理
  43. ├── A-using-system-provide-packages 使用系统所安装的包
  44. ├── B-vendoring-code Vendoring code方法(将第三方库放在工程中)。如果第三方库不支持CMake,可以使用shim层
  45. ├── C-external-project-add 用CMake自动下载和构建一个外部工程
  46. └── D-conan Conan是一个开源、去中心化、多平台的包管理器