CMake 命令行参数完全指南

发布于:2025-08-04 ⋅ 阅读:(18) ⋅ 点赞:(0)

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 检测脚本错误。


网站公告

今日签到

点亮在社区的每一天
去签到