【汇总】CMake 命令说明
前言全局说明
CMake 命令说明
一、说明
cmake --version
cmake version 3.19.8
CMake suite maintained and supported by Kitware (kitware.com/cmake).
二、CMake 自带帮助说明
2.1 cmake --help
D:\Temp>cmake --help
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
cmake [options] -S <path-to-source> -B <path-to-build>
Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Options
-S <path-to-source> = Explicitly specify a source directory.
-B <path-to-build> = Explicitly specify a build directory.
-C <initial-cache> = Pre-load a script to populate the cache.
-D <var>[:<type>]=<value> = Create or update a cmake cache entry.
-U <globbing_expr> = Remove matching entries from CMake cache.
-G <generator-name> = Specify a build system generator.
-T <toolset-name> = Specify toolset name if supported by generator.
-A <platform-name> = Specify platform name if supported by
generator.
-Wdev = Enable developer warnings.
-Wno-dev = Suppress developer warnings.
-Werror=dev = Make developer warnings errors.
-Wno-error=dev = Make developer warnings not errors.
-Wdeprecated = Enable deprecation warnings.
-Wno-deprecated = Suppress deprecation warnings.
-Werror=deprecated = Make deprecated macro and function warnings errors.
-Wno-error=deprecated = Make deprecated macro and function warnings not errors.
--preset=<preset> = Specify a configure preset.
--list-presets = List available presets.
-E = CMake command mode.
-L[A][H] = List non-advanced cached variables.
--build <dir> = Build a CMake-generated project binary tree.
--install <dir> = Install a CMake-generated project binary tree.
--open <dir> = Open generated project in the associated application.
-N = View mode only.
-P <file> = Process script mode.
--find-package = Legacy pkg-config like mode. Do not use.
--graphviz=[file] = Generate graphviz of dependencies, see
CMakeGraphVizOptions.cmake for more.
--system-information [file] = Dump information about this system.
--log-level=<ERROR|WARNING|NOTICE|STATUS|VERBOSE|DEBUG|TRACE>
= Set the verbosity of messages from CMake
files. --loglevel is also accepted for
backward compatibility reasons.
--log-context = Prepend log messages with context, if given
--debug-trycompile = Do not delete the try_compile build tree.
Only useful on one try_compile at a time.
--debug-output = Put cmake in a debug mode.
--debug-find = Put cmake find in a debug mode.
--trace = Put cmake in trace mode.
--trace-expand = Put cmake in trace mode with variable
expansion.
--trace-format=<human|json-v1>
= Set the output format of the trace.
--trace-source=<file> = Trace only this CMake file/module. Multiple
options allowed.
--trace-redirect=<file> = Redirect trace output to a file instead of
stderr.
--warn-uninitialized = Warn about uninitialized values.
--no-warn-unused-cli = Don't warn about command line options.
--check-system-vars = Find problems with variable usage in system
files.
--profiling-format=<fmt> = Output data for profiling CMake scripts.
Supported formats: google-trace
--profiling-output=<file> = Select an output path for the profiling data
enabled through --profiling-format.
--help,-help,-usage,-h,-H,/? = Print usage information and exit.
--version,-version,/V [<f>] = Print version number and exit.
--help-full [<f>] = Print all help manuals and exit.
--help-manual <man> [<f>] = Print one help manual and exit.
--help-manual-list [<f>] = List help manuals available and exit.
--help-command <cmd> [<f>] = Print help for one command and exit.
--help-command-list [<f>] = List commands with help available and exit.
--help-commands [<f>] = Print cmake-commands manual and exit.
--help-module <mod> [<f>] = Print help for one module and exit.
--help-module-list [<f>] = List modules with help available and exit.
--help-modules [<f>] = Print cmake-modules manual and exit.
--help-policy <cmp> [<f>] = Print help for one policy and exit.
--help-policy-list [<f>] = List policies with help available and exit.
--help-policies [<f>] = Print cmake-policies manual and exit.
--help-property <prop> [<f>] = Print help for one property and exit.
--help-property-list [<f>] = List properties with help available and
exit.
--help-properties [<f>] = Print cmake-properties manual and exit.
--help-variable var [<f>] = Print help for one variable and exit.
--help-variable-list [<f>] = List variables with help available and exit.
--help-variables [<f>] = Print cmake-variables manual and exit.
Generators
The following generators are available on this platform (* marks default):
Visual Studio 16 2019 = Generates Visual Studio 2019 project files.
Use -A option to specify architecture.
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
* Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files.
Optional [arch] can be "Win64" or "IA64".
Borland Makefiles = Generates Borland makefiles.
NMake Makefiles = Generates NMake makefiles.
NMake Makefiles JOM = Generates JOM makefiles.
MSYS Makefiles = Generates MSYS makefiles.
MinGW Makefiles = Generates a make file for use with
mingw32-make.
Green Hills MULTI = Generates Green Hills MULTI files
(experimental, work-in-progress).
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files.
Ninja Multi-Config = Generates build-<Config>.ninja files.
Watcom WMake = Generates Watcom WMake makefiles.
CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles JOM
= Generates CodeBlocks project files.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
CodeLite - MinGW Makefiles = Generates CodeLite project files.
CodeLite - NMake Makefiles = Generates CodeLite project files.
CodeLite - Ninja = Generates CodeLite project files.
CodeLite - Unix Makefiles = Generates CodeLite project files.
Eclipse CDT4 - NMake Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - MinGW Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
Kate - MinGW Makefiles = Generates Kate project files.
Kate - NMake Makefiles = Generates Kate project files.
Kate - Ninja = Generates Kate project files.
Kate - Unix Makefiles = Generates Kate project files.
Sublime Text 2 - MinGW Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - NMake Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.
2.2 参数,表格版说明
参数 | 英文说明 | 中文说明 | 备注 |
---|---|---|---|
-S <path-to-source> | Explicitly specify a source directory. | 选项用于指定源代码目录。这是你的项目的根目录,包含了 CMakeLists.txt 文件,这些文件描述了项目的配置和构建过程。 | |
-B <path-to-build> | Explicitly specify a build directory. | 选项用于指定构建目录。这是 CMake 生成的 Makefile 和其他构建系统文件的输出目录。在这个目录中,你可以运行构建命令。 | 例如 make,来构建你的项目。 |
-C <initial-cache> | Pre-load a script to populate the cache. | ||
-D <var>[:<type>]=<value> | Create or update a cmake cache entry. | 用于设置 CMake 变量。 | 例如,-DVAR_NAME=VALUE 可以设置一个 CMake 变量的值 |
-U <globbing_expr> | Remove matching entries from CMake cache. | ||
-G <generator-name> | Specify a build system generator. | 用于指定生成器(generator)。生成器决定了 CMake 会生成哪种类型的构建系统文件。 | 例如,-G "Unix Makefiles" 可以指定使用 Unix Makefile 生成器。 |
-T <toolset-name> | Specify toolset name if supported by generator. | ||
-A <platform-name> | Specify platform name if supported by generator. | ||
-Wdev | Enable developer warnings. | ||
-Wno-dev | Suppress developer warnings. | ||
-Werror=dev | Make developer warnings errors. | ||
-Wno-error=dev | Make developer warnings not errors. | ||
-Wdeprecated | Enable deprecation warnings. | ||
-Wno-deprecated | Suppress deprecation warnings. | ||
-Werror=deprecated | Make deprecated macro and function warnings errors. | ||
-Wno-error=deprecated | Make deprecated macro and function warnings not errors. | ||
--preset=<preset> | Specify a configure preset. | ||
--list-presets | List available presets. | ||
-E <command> [arguments...] | CMake command mode. | 执行命令,比如新建文件 | |
-L[A][H] | List non-advanced cached variables. | ||
--build <dir> | Build a CMake-generated project binary tree. | 用于执行构建过程。指定编译的目录。 | 例如,--build path_to_build_directory 可以执行构建操作。 |
--install <dir> | Install a CMake-generated project binary | ||
--open <dir> | Open generated project in the associated application. | ||
-N | View mode only. | ||
-P <file> | Process script mode. | ||
--find-package | Legacy pkg-config like mode. Do not use. | ||
--graphviz=[file] | Generate graphviz of dependencies, see CMakeGraphVizOptions.cmake for more. | ||
--system-information [file] | Dump information about this system. | ||
--log-level=<ERROR|WARNING|NOTICE|STATUS|VERBOSE|DEBUG|TRACE> | Set the verbosity of messages from CMake files. --loglevel is also accepted for backward compatibility reasons. | ||
--log-context | Prepend log messages with context, if given | ||
--debug-trycompile | Do not delete the try_compile build tree. Only useful on one try_compile at a time. | ||
--debug-output | Put cmake in a debug mode. | ||
--debug-find | Put cmake find in a debug mode. | ||
--trace | Put cmake in trace mode. | ||
--trace-expand | Put cmake in trace mode with variable expansion. | ||
--trace-format=<human|json-v1 | Set the output format of the trace. | ||
--trace-source=<file> | Trace only this CMake file/module. Multiple tree. options allowed. | ||
--trace-redirect=<file> | Redirect trace output to a file instead of stderr. | ||
--warn-uninitialized | Warn about uninitialized values. | ||
--no-warn-unused-cli | Don't warn about command line options. | 不警告在命令行声明但未使用的变量。 | |
--check-system-vars | Find problems with variable usage in system files. | ||
--profiling-format=<fmt> | Output data for profiling CMake scripts. Supported formats: google-trace | ||
--profiling-output=<file> | Select an output path for the profiling data enabled through --profiling-format. | ||
--help,-help,-usage,-h,-H,/? | Print usage information and exit. | ||
--version,-version,/V [<f>] | Print version number and exit. | ||
--help-full [<f>] | Print all help manuals and exit. | ||
--help-manual <man> [<f>] | Print one help manual and exit. | ||
--help-manual-list [<f>] | List help manuals available and exit. | ||
--help-command <cmd> [<f>] | Print help for one command and exit. | ||
--help-command-list [<f>] | List commands with help available and exit. | ||
--help-commands [<f>] | Print cmake-commands manual and exit. | ||
--help-module <mod> [<f>] | Print help for one module and exit. | ||
--help-module-list [<f>] | List modules with help available and exit. | ||
--help-modules [<f>] | Print cmake-modules manual and exit. | ||
--help-policy <cmp> [<f>] | Print help for one policy and exit. | ||
--help-policy-list [<f>] | List policies with help available and exit. | ||
--help-policies [<f>] | Print cmake-policies manual and exit. | ||
--help-property <prop> [<f>] | Print help for one property and exit. | ||
--help-property-list [<f>] | List properties with help available and exit. | ||
--help-properties [<f>] | Print cmake-properties manual and exit. | ||
--help-variable var [<f>] | Print help for one variable and exit. | ||
--help-variable-list [<f>] | List variables with help available and exit. | ||
--help-variables [<f>] | Print cmake-variables manual and exit. |
2.2 生成,表格版说明
Generators
The following generators are available on this platform (* marks default):
参数 | 英文说明 | 中文说明 | 备注 |
---|---|---|---|
Visual Studio 16 2019 | Generates Visual Studio 2019 project files. Use -A option to specify architecture. | ||
Visual Studio 15 2017 [arch] | Generates Visual Studio 2017 project files. Optional [arch] can be "Win64" or "ARM". | ||
Visual Studio 14 2015 [arch] | Generates Visual Studio 2015 project files. Optional [arch] can be "Win64" or "ARM". | ||
Visual Studio 12 2013 [arch] | Generates Visual Studio 2013 project files. Optional [arch] can be "Win64" or "ARM". | ||
Visual Studio 11 2012 [arch] | Generates Visual Studio 2012 project files. Optional [arch] can be "Win64" or "ARM". | ||
Visual Studio 10 2010 [arch] | Generates Visual Studio 2010 project files. Optional [arch] can be "Win64" or "IA64". | ||
Visual Studio 9 2008 [arch] | Generates Visual Studio 2008 project files. Optional [arch] can be "Win64" or "IA64". | ||
Borland Makefiles | Generates Borland makefiles. | ||
NMake Makefiles | Generates NMake makefiles. | ||
NMake Makefiles JOM | Generates JOM makefiles. | ||
MSYS Makefiles | Generates MSYS makefiles. | ||
MinGW Makefiles | Generates a make file for use with mingw32-make. | ||
Green Hills MULTI | Generates Green Hills MULTI files (experimental, work-in-progress). | ||
Unix Makefiles | Generates standard UNIX makefiles. | ||
Ninja | Generates build.ninja files. | ||
Ninja Multi-Config | Generates build-<Config>.ninja files. | ||
Watcom WMake | Generates Watcom WMake makefiles. | ||
CodeBlocks - MinGW Makefiles | Generates CodeBlocks project files. | ||
CodeBlocks - NMake Makefiles | Generates CodeBlocks project files. | ||
CodeBlocks - NMake Makefiles JOM | Generates CodeBlocks project files. | ||
CodeBlocks - Ninja | Generates CodeBlocks project files. | ||
CodeBlocks - Unix Makefiles | Generates CodeBlocks project files. | ||
CodeLite - MinGW Makefiles | Generates CodeLite project files. | ||
CodeLite - NMake Makefiles | Generates CodeLite project files. | ||
CodeLite - Ninja | Generates CodeLite project files. | ||
CodeLite - Unix Makefiles | Generates CodeLite project files. | ||
Eclipse CDT4 - NMake Makefiles | Generates Eclipse CDT 4.0 project files. | ||
Eclipse CDT4 - MinGW Makefiles | Generates Eclipse CDT 4.0 project files. | ||
Eclipse CDT4 - Ninja | Generates Eclipse CDT 4.0 project files. | ||
Eclipse CDT4 - Unix Makefiles | Generates Eclipse CDT 4.0 project files. | ||
Kate - MinGW Makefiles | Generates Kate project files. | ||
Kate - NMake Makefiles | Generates Kate project files. | ||
Kate - Ninja | Generates Kate project files. | ||
Kate - Unix Makefiles | Generates Kate project files. | ||
Sublime Text 2 - MinGW Makefiles | Generates Sublime Text 2 project files. | ||
Sublime Text 2 - NMake Makefiles | Generates Sublime Text 2 project files. | ||
Sublime Text 2 - Ninja | Generates Sublime Text 2 project files. | ||
Sublime Text 2 - Unix Makefiles | Generates Sublime Text 2 project files. |
三、示例
管理员打开cmd窗口执行命令
3.1 在当前目录下生成解决方案
如果是在 WIN 下,会自动生成 Visual Studio 的项目工程解决方案
cmake .
(图片来源于网络)
3.2 生成 Debu 模式, 项目工程解决方案
cmake --build .
注意:结尾有.(点),代表当前目录,这个要指定项目的 CMakeLists.txt 路径
3.2 Release模式:
cmake --build . -- /p:Configuration=Release
3.2 -E:用于执行与构建无关的命令,如创建目录、复制文件等
语法:
Usage: cmake -E \<command> [arguments...]
示例:
当前目录新建一个 abc 的文件夹
cmake -E make_directory build\abc
3.2
四、
4.1
文件名:
4.2
文件名:
免责声明:本号所涉及内容仅供安全研究与教学使用,如出现其他风险,后果自负。
参考、来源:
https://blog.csdn.net/qq_50791664/article/details/128822314 (【CMake】掌握CMake基本操作,变量、函数)
https://blog.csdn.net/finghting321/article/details/105528436
https://www.cnblogs.com/eezhijun/p/17675289.html
https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&ch=8&tn=98012088_4_oem_dg&wd=cmake 命令行参数&oq=cmake%2520%25E5%258F%2582%25E6%2595%25B0&rsv_pq=91132f46007b67ba&rsv_t=5025RGdHdNbth201PPmUzKAZ9xZbs7lkObjv0cePw5mpaDoLGi2Zg6qysT76%2FCF0z5lQCplsY2Q&rqlang=cn&rsv_dl=tb&rsv_enter=1&rsv_sug3=8&rsv_sug2=0&rsv_btype=t&inputT=1417&rsv_sug4=2454&bs=cmake 参数&rsv_jmp=fail
https://blog.csdn.net/as3luyuan123/article/details/116887311