cmake --
参数详解
**1. --build
**
同 cmake -
中的 --build
**2. --check-system-vars
**
同 cmake -
中的 --check-system-vars
**3. --debug-output
**
同 cmake -
中的 --debug-output
**4. --debug-trycompile
**
同 cmake -
中的 --debug-trycompile
**5. --find-package
**
同 cmake -
中的 --find-package
**6. --graphviz=
**
同 cmake -
中的 --graphviz=
**7. --help
**
同 cmake -
中的 --help
**8. --help-command <command>
**
解释:显示特定命令帮助
输入要求:CMake命令名称
示例:
cmake --help-command add_library
**9. --help-command-list
**
解释:列出所有命令
示例:
cmake --help-command-list
**10. --help-commands
**
解释:同 --help-command-list
(已弃用)
**11. --help-full
**
同 cmake -
中的 --help-full
**12. --help-manual
**
同 cmake -
中的 --help-manual
**13. --help-manual-list
**
同 cmake -
中的 --help-manual-list
**14. --help-module
**
同 cmake -
中的 --help-module
**15. --help-module-list
**
同 cmake -
中的 --help-module-list
**16. --help-modules
**
同 cmake -
中的 --help-modules
**17. --help-policies
**
同 cmake -
中的 --help-policies
**18. --help-policy
**
同 cmake -
中的 --help-policy
**19. --help-policy-list
**
同 cmake -
中的 --help-policy-list
**20. --help-properties
**
同 cmake -
中的 --help-properties
**21. --help-property
**
同 cmake -
中的 --help-property
**22. --help-property-list
**
同 cmake -
中的 --help-property-list
**23. --help-variable
**
同 cmake -
中的 --help-variable
**24. --help-variable-list
**
同 cmake -
中的 --help-variable-list
**25. --help-variables
**
同 cmake -
中的 --help-variables
**26. --install
**
同 cmake -
中的 --install
**27. --log-level=
**
同 cmake -
中的 --log-level=
**28. --no-warn-unused-cli
**
同 cmake -
中的 --no-warn-unused-cli
**29. --open
**
同 cmake -
中的 --open
**30. --system-information
**
同 cmake -
中的 --system-information
**31. --trace
**
同 cmake -
中的 --trace
**32. --trace-expand
**
同 cmake -
中的 --trace-expand
**33. --trace-redirect=
**
同 cmake -
中的 --trace-redirect=
**34. --trace-source=
**
同 cmake -
中的 --trace-source=
**35. --version
**
同 cmake -
中的 --version
**36. --warn-uninitialized
**
同 cmake -
中的 --warn-uninitialized
初学者快速参考表
任务 | 推荐命令 | 说明 |
---|---|---|
初始化项目 | cmake -B build -S . |
创建build目录并配置 |
编译项目 | cmake --build build |
执行实际编译 |
调试配置 | cmake -B build -DCMAKE_BUILD_TYPE=Debug |
设置调试模式 |
查看变量 | cmake -B build -LAH |
列出所有配置变量 |
安装程序 | cmake --install build |
安装到系统目录 |
清理构建 | cmake --build build --target clean |
删除编译文件 |
获取帮助 | cmake --help-command target_link_libraries |
查看命令帮助 |
最佳实践工作流
# 1. 创建并配置构建系统
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
# 2. 编译项目(4线程)
cmake --build build -j 4
# 3. 运行测试(如果有)
cmake --build build --target test
# 4. 安装程序
cmake --install build --prefix ./install
# 5. 清理构建
cmake --build build --target clean
提示:所有命令都使用
-B build
保持构建目录隔离,避免污染源代码目录。初学者应始终使用--warn-uninitialized
检测脚本错误。