#cmake
- 来源:[CMake 是怎么工作的?](https://www.tisonkun.org/2022/04/15/how-cmake-works/#CMake-%E6%96%B0%E6%97%B6%E4%BB%A3%E7%9A%84%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5)
-------
# 围绕构建目标声明
- 使用 `target_xxx` 形式的命令
- `target_compile_options`
- `target_compile_definitions`
- 例如 `include_directories` 会修改全局状态,导致声明泄漏
> 现代 CMake 的最佳实践是牢记围绕构建目标组织声明,不仅能避免意外的声明泄漏,还能获得更好的表达力。
------
# 灵活支持三方库
## find_package
```cmake
find_package(<PackageName> [version] [REQUIRED] [[COMPONENTS] [components...]])|
```
> CMake 会在约定路径和通过选项指定的路径下搜索名为 FindPackageName.cmake 的文件,并执行其中的逻辑以设置一些关键的变量
## 依赖管理系统
- vcpkg
- conan
- CMake ExternalProject / FetchContent
------
# 新时代的最佳实践
- [Effective CMake - a random seletion of best practices](https://www.youtube.com/watch?v=bsXLMQ6WgIk)([slides](https://github.com/boostcon/cppnow_presentations_2017/blob/master/05-19-2017_friday/effective_cmake__daniel_pfeifer__cppnow_05-19-2017.pdf))
- [Using Modern CMake Patterns to Enforce a Good Modular Design](https://www.youtube.com/watch?v=eC9-iRN2b04)([slides](https://github.com/CppCon/CppCon2017/blob/master/Tutorials/Using%20Modern%20CMake%20Patterns%20to%20Enforce%20a%20Good%20Modular%20Design/Using%20Modern%20CMake%20Patterns%20to%20Enforce%20a%20Good%20Modular%20Design%20-%20Mathieu%20Ropert%20-%20CppCon%202017.pdf))
- [CMake Examples](https://github.com/ttroy50/cmake-examples)
- [How CMake Is Implemented](http://www.aosabook.org/en/cmake.html) [[cmake-architecture]]