You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1524 lines
46 KiB

  1. .. cmake-manual-description: CMake Command-Line Reference
  2. cmake(1)
  3. ********
  4. Synopsis
  5. ========
  6. .. parsed-literal::
  7. `Generate a Project Buildsystem`_
  8. cmake [<options>] -B <path-to-build> [-S <path-to-source>]
  9. cmake [<options>] <path-to-source | path-to-existing-build>
  10. `Build a Project`_
  11. cmake --build <dir> [<options>] [-- <build-tool-options>]
  12. `Install a Project`_
  13. cmake --install <dir> [<options>]
  14. `Open a Project`_
  15. cmake --open <dir>
  16. `Run a Script`_
  17. cmake [-D <var>=<value>]... -P <cmake-script-file>
  18. `Run a Command-Line Tool`_
  19. cmake -E <command> [<options>]
  20. `Run the Find-Package Tool`_
  21. cmake --find-package [<options>]
  22. `Run a Workflow Preset`_
  23. cmake --workflow <options>
  24. `View Help`_
  25. cmake --help[-<topic>]
  26. Description
  27. ===========
  28. The :program:`cmake` executable is the command-line interface of the cross-platform
  29. buildsystem generator CMake. The above `Synopsis`_ lists various actions
  30. the tool can perform as described in sections below.
  31. To build a software project with CMake, `Generate a Project Buildsystem`_.
  32. Optionally use :program:`cmake` to `Build a Project`_, `Install a Project`_ or just
  33. run the corresponding build tool (e.g. ``make``) directly. :program:`cmake` can also
  34. be used to `View Help`_.
  35. The other actions are meant for use by software developers writing
  36. scripts in the :manual:`CMake language <cmake-language(7)>` to support
  37. their builds.
  38. For graphical user interfaces that may be used in place of :program:`cmake`,
  39. see :manual:`ccmake <ccmake(1)>` and :manual:`cmake-gui <cmake-gui(1)>`.
  40. For command-line interfaces to the CMake testing and packaging facilities,
  41. see :manual:`ctest <ctest(1)>` and :manual:`cpack <cpack(1)>`.
  42. For more information on CMake at large, `see also`_ the links at the end
  43. of this manual.
  44. Introduction to CMake Buildsystems
  45. ==================================
  46. A *buildsystem* describes how to build a project's executables and libraries
  47. from its source code using a *build tool* to automate the process. For
  48. example, a buildsystem may be a ``Makefile`` for use with a command-line
  49. ``make`` tool or a project file for an Integrated Development Environment
  50. (IDE). In order to avoid maintaining multiple such buildsystems, a project
  51. may specify its buildsystem abstractly using files written in the
  52. :manual:`CMake language <cmake-language(7)>`. From these files CMake
  53. generates a preferred buildsystem locally for each user through a backend
  54. called a *generator*.
  55. To generate a buildsystem with CMake, the following must be selected:
  56. Source Tree
  57. The top-level directory containing source files provided by the project.
  58. The project specifies its buildsystem using files as described in the
  59. :manual:`cmake-language(7)` manual, starting with a top-level file named
  60. ``CMakeLists.txt``. These files specify build targets and their
  61. dependencies as described in the :manual:`cmake-buildsystem(7)` manual.
  62. Build Tree
  63. The top-level directory in which buildsystem files and build output
  64. artifacts (e.g. executables and libraries) are to be stored.
  65. CMake will write a ``CMakeCache.txt`` file to identify the directory
  66. as a build tree and store persistent information such as buildsystem
  67. configuration options.
  68. To maintain a pristine source tree, perform an *out-of-source* build
  69. by using a separate dedicated build tree. An *in-source* build in
  70. which the build tree is placed in the same directory as the source
  71. tree is also supported, but discouraged.
  72. Generator
  73. This chooses the kind of buildsystem to generate. See the
  74. :manual:`cmake-generators(7)` manual for documentation of all generators.
  75. Run :option:`cmake --help` to see a list of generators available locally.
  76. Optionally use the :option:`-G <cmake -G>` option below to specify a
  77. generator, or simply accept the default CMake chooses for the current
  78. platform.
  79. When using one of the :ref:`Command-Line Build Tool Generators`
  80. CMake expects that the environment needed by the compiler toolchain
  81. is already configured in the shell. When using one of the
  82. :ref:`IDE Build Tool Generators`, no particular environment is needed.
  83. .. _`Generate a Project Buildsystem`:
  84. Generate a Project Buildsystem
  85. ==============================
  86. Run CMake with one of the following command signatures to specify the
  87. source and build trees and generate a buildsystem:
  88. ``cmake [<options>] -B <path-to-build> [-S <path-to-source>]``
  89. .. versionadded:: 3.13
  90. Uses ``<path-to-build>`` as the build tree and ``<path-to-source>``
  91. as the source tree. The specified paths may be absolute or relative
  92. to the current working directory. The source tree must contain a
  93. ``CMakeLists.txt`` file. The build tree will be created automatically
  94. if it does not already exist. For example:
  95. .. code-block:: console
  96. $ cmake -S src -B build
  97. ``cmake [<options>] <path-to-source>``
  98. Uses the current working directory as the build tree, and
  99. ``<path-to-source>`` as the source tree. The specified path may
  100. be absolute or relative to the current working directory.
  101. The source tree must contain a ``CMakeLists.txt`` file and must
  102. *not* contain a ``CMakeCache.txt`` file because the latter
  103. identifies an existing build tree. For example:
  104. .. code-block:: console
  105. $ mkdir build ; cd build
  106. $ cmake ../src
  107. ``cmake [<options>] <path-to-existing-build>``
  108. Uses ``<path-to-existing-build>`` as the build tree, and loads the
  109. path to the source tree from its ``CMakeCache.txt`` file, which must
  110. have already been generated by a previous run of CMake. The specified
  111. path may be absolute or relative to the current working directory.
  112. For example:
  113. .. code-block:: console
  114. $ cd build
  115. $ cmake .
  116. In all cases the ``<options>`` may be zero or more of the `Options`_ below.
  117. The above styles for specifying the source and build trees may be mixed.
  118. Paths specified with :option:`-S <cmake -S>` or :option:`-B <cmake -B>`
  119. are always classified as source or build trees, respectively. Paths
  120. specified with plain arguments are classified based on their content
  121. and the types of paths given earlier. If only one type of path is given,
  122. the current working directory (cwd) is used for the other. For example:
  123. ============================== ============ ===========
  124. Command Line Source Dir Build Dir
  125. ============================== ============ ===========
  126. ``cmake -B build`` *cwd* ``build``
  127. ``cmake -B build src`` ``src`` ``build``
  128. ``cmake -B build -S src`` ``src`` ``build``
  129. ``cmake src`` ``src`` *cwd*
  130. ``cmake build`` (existing) *loaded* ``build``
  131. ``cmake -S src`` ``src`` *cwd*
  132. ``cmake -S src build`` ``src`` ``build``
  133. ``cmake -S src -B build`` ``src`` ``build``
  134. ============================== ============ ===========
  135. .. versionchanged:: 3.23
  136. CMake warns when multiple source paths are specified. This has never
  137. been officially documented or supported, but older versions accidentally
  138. accepted multiple source paths and used the last path specified.
  139. Avoid passing multiple source path arguments.
  140. After generating a buildsystem one may use the corresponding native
  141. build tool to build the project. For example, after using the
  142. :generator:`Unix Makefiles` generator one may run ``make`` directly:
  143. .. code-block:: console
  144. $ make
  145. $ make install
  146. Alternatively, one may use :program:`cmake` to `Build a Project`_ by
  147. automatically choosing and invoking the appropriate native build tool.
  148. .. _`CMake Options`:
  149. Options
  150. -------
  151. .. program:: cmake
  152. .. include:: include/OPTIONS_BUILD.rst
  153. .. option:: --fresh
  154. .. versionadded:: 3.24
  155. Perform a fresh configuration of the build tree.
  156. This removes any existing ``CMakeCache.txt`` file and associated
  157. ``CMakeFiles/`` directory, and recreates them from scratch.
  158. .. versionchanged:: 3.30
  159. For dependencies previously populated by :module:`FetchContent` with the
  160. ``NEW`` setting for policy :policy:`CMP0168`, their stamp and script files
  161. from any previous run will be removed. The download, update, and patch
  162. steps will therefore be forced to re-execute.
  163. .. option:: -L[A][H]
  164. List non-advanced cached variables.
  165. List ``CACHE`` variables will run CMake and list all the variables from
  166. the CMake ``CACHE`` that are not marked as ``INTERNAL`` or :prop_cache:`ADVANCED`.
  167. This will effectively display current CMake settings, which can then be
  168. changed with :option:`-D <cmake -D>` option. Changing some of the variables
  169. may result in more variables being created. If ``A`` is specified, then it
  170. will display also advanced variables. If ``H`` is specified, it will also
  171. display help for each variable.
  172. .. option:: -LR[A][H] <regex>
  173. .. versionadded:: 3.31
  174. Show specific non-advanced cached variables
  175. Show non-``INTERNAL`` nor :prop_cache:`ADVANCED` variables from the CMake
  176. ``CACHE`` that match the given regex. If ``A`` is specified, then it
  177. will also show advanced variables. If ``H`` is specified, it will also
  178. display help for each variable.
  179. .. option:: -N
  180. View mode only.
  181. Only load the cache. Do not actually run configure and generate
  182. steps.
  183. .. option:: --graphviz=<file>
  184. Generate graphviz of dependencies, see :module:`CMakeGraphVizOptions` for more.
  185. Generate a graphviz input file that will contain all the library and
  186. executable dependencies in the project. See the documentation for
  187. :module:`CMakeGraphVizOptions` for more details.
  188. .. option:: --system-information [file]
  189. Dump information about this system.
  190. Dump a wide range of information about the current system. If run
  191. from the top of a binary tree for a CMake project it will dump
  192. additional information such as the cache, log files etc.
  193. .. option:: --print-config-dir
  194. .. versionadded:: 3.31
  195. Print CMake config directory for user-wide FileAPI queries.
  196. See :envvar:`CMAKE_CONFIG_DIR` for more details.
  197. .. option:: --log-level=<level>
  198. .. versionadded:: 3.16
  199. Set the log ``<level>``.
  200. The :command:`message` command will only output messages of the specified
  201. log level or higher. The valid log levels are ``ERROR``, ``WARNING``,
  202. ``NOTICE``, ``STATUS`` (default), ``VERBOSE``, ``DEBUG``, or ``TRACE``.
  203. To make a log level persist between CMake runs, set
  204. :variable:`CMAKE_MESSAGE_LOG_LEVEL` as a cache variable instead.
  205. If both the command line option and the variable are given, the command line
  206. option takes precedence.
  207. For backward compatibility reasons, ``--loglevel`` is also accepted as a
  208. synonym for this option.
  209. .. versionadded:: 3.25
  210. See the :command:`cmake_language` command for a way to
  211. :ref:`query the current message logging level <query_message_log_level>`.
  212. .. option:: --log-context
  213. Enable the :command:`message` command outputting context attached to each
  214. message.
  215. This option turns on showing context for the current CMake run only.
  216. To make showing the context persistent for all subsequent CMake runs, set
  217. :variable:`CMAKE_MESSAGE_CONTEXT_SHOW` as a cache variable instead.
  218. When this command line option is given, :variable:`CMAKE_MESSAGE_CONTEXT_SHOW`
  219. is ignored.
  220. .. option:: --sarif-output=<path>
  221. .. versionadded:: 4.0
  222. Enable logging of diagnostic messages produced by CMake in the SARIF format.
  223. Write diagnostic messages to a SARIF file at the path specified. Projects can
  224. also set :variable:`CMAKE_EXPORT_SARIF` to ``ON`` to enable this feature for a
  225. build tree.
  226. .. option:: --debug-trycompile
  227. Do not delete the files and directories created for
  228. :command:`try_compile` / :command:`try_run` calls.
  229. This is useful in debugging failed checks.
  230. Note that some uses of :command:`try_compile` may use the same build tree,
  231. which will limit the usefulness of this option if a project executes more
  232. than one :command:`try_compile`. For example, such uses may change results
  233. as artifacts from a previous try-compile may cause a different test to either
  234. pass or fail incorrectly. This option is best used only when debugging.
  235. (With respect to the preceding, the :command:`try_run` command
  236. is effectively a :command:`try_compile`. Any combination of the two
  237. is subject to the potential issues described.)
  238. .. versionadded:: 3.25
  239. When this option is enabled, every try-compile check prints a log
  240. message reporting the directory in which the check is performed.
  241. .. option:: --debug-output
  242. Put cmake in a debug mode.
  243. Print extra information during the cmake run like stack traces with
  244. :command:`message(SEND_ERROR)` calls.
  245. .. option:: --debug-find
  246. .. versionadded:: 3.17
  247. Put cmake find commands in a debug mode.
  248. Print extra find call information during the cmake run to standard
  249. error. Output is designed for human consumption and not for parsing.
  250. See also the :variable:`CMAKE_FIND_DEBUG_MODE` variable for debugging
  251. a more local part of the project.
  252. .. option:: --debug-find-pkg=<pkg>[,...]
  253. .. versionadded:: 3.23
  254. Put cmake find commands in a debug mode when running under calls
  255. to :command:`find_package(\<pkg\>) <find_package>`, where ``<pkg>``
  256. is an entry in the given comma-separated list of case-sensitive package
  257. names.
  258. Like :option:`--debug-find <cmake --debug-find>`, but limiting scope
  259. to the specified packages.
  260. .. option:: --debug-find-var=<var>[,...]
  261. .. versionadded:: 3.23
  262. Put cmake find commands in a debug mode when called with ``<var>``
  263. as the result variable, where ``<var>`` is an entry in the given
  264. comma-separated list.
  265. Like :option:`--debug-find <cmake --debug-find>`, but limiting scope
  266. to the specified variable names.
  267. .. option:: --trace
  268. Put cmake in trace mode.
  269. Print a trace of all calls made and from where.
  270. .. option:: --trace-expand
  271. Put cmake in trace mode.
  272. Like :option:`--trace <cmake --trace>`, but with variables expanded.
  273. .. option:: --trace-format=<format>
  274. .. versionadded:: 3.17
  275. Put cmake in trace mode and sets the trace output format.
  276. ``<format>`` can be one of the following values.
  277. ``human``
  278. Prints each trace line in a human-readable format. This is the
  279. default format.
  280. ``json-v1``
  281. Prints each line as a separate JSON document. Each document is
  282. separated by a newline (``\n``). It is guaranteed that no
  283. newline characters will be present inside a JSON document.
  284. .. code-block:: json
  285. :caption: JSON trace format
  286. {
  287. "file": "/full/path/to/the/CMake/file.txt",
  288. "line": 0,
  289. "cmd": "add_executable",
  290. "args": ["foo", "bar"],
  291. "time": 1579512535.9687231,
  292. "frame": 2,
  293. "global_frame": 4
  294. }
  295. The members are:
  296. ``file``
  297. The full path to the CMake source file where the function
  298. was called.
  299. ``line``
  300. The line in ``file`` where the function call begins.
  301. ``line_end``
  302. If the function call spans multiple lines, this field will
  303. be set to the line where the function call ends. If the function
  304. calls spans a single line, this field will be unset. This field
  305. was added in minor version 2 of the ``json-v1`` format.
  306. ``defer``
  307. Optional member that is present when the function call was deferred
  308. by :command:`cmake_language(DEFER)`. If present, its value is a
  309. string containing the deferred call ``<id>``.
  310. ``cmd``
  311. The name of the function that was called.
  312. ``args``
  313. A string list of all function parameters.
  314. ``time``
  315. Timestamp (seconds since epoch) of the function call.
  316. ``frame``
  317. Stack frame depth of the function that was called, within the
  318. context of the ``CMakeLists.txt`` being processed currently.
  319. ``global_frame``
  320. Stack frame depth of the function that was called, tracked globally
  321. across all ``CMakeLists.txt`` files involved in the trace. This field
  322. was added in minor version 2 of the ``json-v1`` format.
  323. Additionally, the first JSON document outputted contains the
  324. ``version`` key for the current major and minor version of the
  325. .. code-block:: json
  326. :caption: JSON version format
  327. {
  328. "version": {
  329. "major": 1,
  330. "minor": 2
  331. }
  332. }
  333. The members are:
  334. ``version``
  335. Indicates the version of the JSON format. The version has a
  336. major and minor components following semantic version conventions.
  337. .. option:: --trace-source=<file>
  338. Put cmake in trace mode, but output only lines of a specified file.
  339. Multiple options are allowed.
  340. .. option:: --trace-redirect=<file>
  341. Put cmake in trace mode and redirect trace output to a file instead of stderr.
  342. .. option:: --warn-uninitialized
  343. Warn about uninitialized values.
  344. Print a warning when an uninitialized variable is used.
  345. .. option:: --warn-unused-vars
  346. Does nothing. In CMake versions 3.2 and below this enabled warnings about
  347. unused variables. In CMake versions 3.3 through 3.18 the option was broken.
  348. In CMake 3.19 and above the option has been removed.
  349. .. option:: --no-warn-unused-cli
  350. Don't warn about command line options.
  351. Don't find variables that are declared on the command line, but not
  352. used.
  353. .. option:: --check-system-vars
  354. Find problems with variable usage in system files.
  355. Normally, unused and uninitialized variables are searched for only
  356. in :variable:`CMAKE_SOURCE_DIR` and :variable:`CMAKE_BINARY_DIR`.
  357. This flag tells CMake to warn about other files as well.
  358. .. option:: --compile-no-warning-as-error
  359. .. versionadded:: 3.24
  360. Ignore target property :prop_tgt:`COMPILE_WARNING_AS_ERROR` and variable
  361. :variable:`CMAKE_COMPILE_WARNING_AS_ERROR`, preventing warnings from being
  362. treated as errors on compile.
  363. .. option:: --link-no-warning-as-error
  364. .. versionadded:: 4.0
  365. Ignore target property :prop_tgt:`LINK_WARNING_AS_ERROR` and variable
  366. :variable:`CMAKE_LINK_WARNING_AS_ERROR`, preventing warnings from being
  367. treated as errors on link.
  368. .. option:: --profiling-output=<path>
  369. .. versionadded:: 3.18
  370. Used in conjunction with
  371. :option:`--profiling-format <cmake --profiling-format>` to output to a
  372. given path.
  373. .. option:: --profiling-format=<file>
  374. Enable the output of profiling data of CMake script in the given format.
  375. This can aid performance analysis of CMake scripts executed. Third party
  376. applications should be used to process the output into human readable format.
  377. Currently supported values are:
  378. ``google-trace`` Outputs in Google Trace Format, which can be parsed by the
  379. about:tracing tab of Google Chrome or using a plugin for a tool like Trace
  380. Compass.
  381. .. option:: --preset <preset>, --preset=<preset>
  382. Reads a :manual:`preset <cmake-presets(7)>` from ``CMakePresets.json`` and
  383. ``CMakeUserPresets.json`` files, which must be located in the same directory
  384. as the top level ``CMakeLists.txt`` file. The preset may specify the
  385. generator, the build directory, a list of variables, and other arguments to
  386. pass to CMake. At least one of ``CMakePresets.json`` or
  387. ``CMakeUserPresets.json`` must be present.
  388. The :manual:`CMake GUI <cmake-gui(1)>` also recognizes and supports
  389. ``CMakePresets.json`` and ``CMakeUserPresets.json`` files. For full details
  390. on these files, see :manual:`cmake-presets(7)`.
  391. The presets are read before all other command line options, although the
  392. :option:`-S <cmake -S>` option can be used to specify the source directory
  393. containing the ``CMakePresets.json`` and ``CMakeUserPresets.json`` files.
  394. If :option:`-S <cmake -S>` is not given, the current directory is assumed to
  395. be the top level source directory and must contain the presets files. The
  396. options specified by the chosen preset (variables, generator, etc.) can all
  397. be overridden by manually specifying them on the command line. For example,
  398. if the preset sets a variable called ``MYVAR`` to ``1``, but the user sets
  399. it to ``2`` with a ``-D`` argument, the value ``2`` is preferred.
  400. .. option:: --list-presets[=<type>]
  401. Lists the available presets of the specified ``<type>``. Valid values for
  402. ``<type>`` are ``configure``, ``build``, ``test``, ``package``, or ``all``.
  403. If ``<type>`` is omitted, ``configure`` is assumed. The current working
  404. directory must contain CMake preset files unless the :option:`-S <cmake -S>`
  405. option is used to specify a different top level source directory.
  406. .. option:: --debugger
  407. Enables interactive debugging of the CMake language. CMake exposes a debugging
  408. interface on the pipe named by :option:`--debugger-pipe <cmake --debugger-pipe>`
  409. that conforms to the `Debug Adapter Protocol`_ specification with the following
  410. modifications.
  411. The ``initialize`` response includes an additional field named ``cmakeVersion``
  412. which specifies the version of CMake being debugged.
  413. .. code-block:: json
  414. :caption: Debugger initialize response
  415. {
  416. "cmakeVersion": {
  417. "major": 3,
  418. "minor": 27,
  419. "patch": 0,
  420. "full": "3.27.0"
  421. }
  422. }
  423. The members are:
  424. ``major``
  425. An integer specifying the major version number.
  426. ``minor``
  427. An integer specifying the minor version number.
  428. ``patch``
  429. An integer specifying the patch version number.
  430. ``full``
  431. A string specifying the full CMake version.
  432. .. _`Debug Adapter Protocol`: https://microsoft.github.io/debug-adapter-protocol/
  433. .. option:: --debugger-pipe <pipe name>, --debugger-pipe=<pipe name>
  434. Name of the pipe (on Windows) or domain socket (on Unix) to use for
  435. debugger communication.
  436. .. option:: --debugger-dap-log <log path>, --debugger-dap-log=<log path>
  437. Logs all debugger communication to the specified file.
  438. .. _`Build Tool Mode`:
  439. Build a Project
  440. ===============
  441. .. program:: cmake
  442. CMake provides a command-line signature to build an already-generated
  443. project binary tree:
  444. .. code-block:: shell
  445. cmake --build <dir> [<options>] [-- <build-tool-options>]
  446. cmake --build --preset <preset> [<options>] [-- <build-tool-options>]
  447. This abstracts a native build tool's command-line interface with the
  448. following options:
  449. .. option:: --build <dir>
  450. Project binary directory to be built. This is required (unless a preset
  451. is specified) and must be first.
  452. .. program:: cmake--build
  453. .. option:: --preset <preset>, --preset=<preset>
  454. Use a build preset to specify build options. The project binary directory
  455. is inferred from the ``configurePreset`` key. The current working directory
  456. must contain CMake preset files.
  457. See :manual:`preset <cmake-presets(7)>` for more details.
  458. .. option:: --list-presets
  459. Lists the available build presets. The current working directory must
  460. contain CMake preset files.
  461. .. option:: -j [<jobs>], --parallel [<jobs>]
  462. .. versionadded:: 3.12
  463. The maximum number of concurrent processes to use when building.
  464. If ``<jobs>`` is omitted the native build tool's default number is used.
  465. The :envvar:`CMAKE_BUILD_PARALLEL_LEVEL` environment variable, if set,
  466. specifies a default parallel level when this option is not given.
  467. Some native build tools always build in parallel. The use of ``<jobs>``
  468. value of ``1`` can be used to limit to a single job.
  469. .. option:: -t <tgt>..., --target <tgt>...
  470. Build ``<tgt>`` instead of the default target. Multiple targets may be
  471. given, separated by spaces.
  472. .. option:: --config <cfg>
  473. For multi-configuration tools, choose configuration ``<cfg>``.
  474. .. option:: --clean-first
  475. Build target ``clean`` first, then build.
  476. (To clean only, use :option:`--target clean <cmake--build --target>`.)
  477. .. option:: --resolve-package-references=<value>
  478. .. versionadded:: 3.23
  479. Resolve remote package references from external package managers (e.g. NuGet)
  480. before build. When ``<value>`` is set to ``on`` (default), packages will be
  481. restored before building a target. When ``<value>`` is set to ``only``, the
  482. packages will be restored, but no build will be performed. When
  483. ``<value>`` is set to ``off``, no packages will be restored.
  484. If the target does not define any package references, this option does nothing.
  485. This setting can be specified in a build preset (using
  486. ``resolvePackageReferences``). The preset setting will be ignored, if this
  487. command line option is specified.
  488. If no command line parameter or preset option are provided, an environment-
  489. specific cache variable will be evaluated to decide, if package restoration
  490. should be performed.
  491. When using the Visual Studio generator, package references are defined
  492. using the :prop_tgt:`VS_PACKAGE_REFERENCES` property. Package references
  493. are restored using NuGet. It can be disabled by setting the
  494. ``CMAKE_VS_NUGET_PACKAGE_RESTORE`` variable to ``OFF``.
  495. .. option:: --use-stderr
  496. Ignored. Behavior is default in CMake >= 3.0.
  497. .. option:: -v, --verbose
  498. Enable verbose output - if supported - including the build commands to be
  499. executed.
  500. This option can be omitted if :envvar:`VERBOSE` environment variable or
  501. :variable:`CMAKE_VERBOSE_MAKEFILE` cached variable is set.
  502. .. option:: --
  503. Pass remaining options to the native tool.
  504. Run :option:`cmake --build` with no options for quick help.
  505. Install a Project
  506. =================
  507. .. program:: cmake
  508. CMake provides a command-line signature to install an already-generated
  509. project binary tree:
  510. .. code-block:: shell
  511. cmake --install <dir> [<options>]
  512. This may be used after building a project to run installation without
  513. using the generated build system or the native build tool.
  514. The options are:
  515. .. option:: --install <dir>
  516. Project binary directory to install. This is required and must be first.
  517. .. program:: cmake--install
  518. .. option:: --config <cfg>
  519. For multi-configuration generators, choose configuration ``<cfg>``.
  520. .. option:: --component <comp>
  521. Component-based install. Only install component ``<comp>``.
  522. .. option:: --default-directory-permissions <permissions>
  523. Default directory install permissions. Permissions in format ``<u=rwx,g=rx,o=rx>``.
  524. .. option:: --prefix <prefix>
  525. Override the installation prefix, :variable:`CMAKE_INSTALL_PREFIX`.
  526. .. option:: --strip
  527. Strip before installing.
  528. .. option:: -v, --verbose
  529. Enable verbose output.
  530. This option can be omitted if :envvar:`VERBOSE` environment variable is set.
  531. .. option:: -j <jobs>, --parallel <jobs>
  532. .. versionadded:: 3.31
  533. Install in parallel using the given number of jobs. Only available if
  534. :prop_gbl:`INSTALL_PARALLEL` is enabled. The
  535. :envvar:`CMAKE_INSTALL_PARALLEL_LEVEL` environment variable specifies a
  536. default parallel level when this option is not provided.
  537. Run :option:`cmake --install` with no options for quick help.
  538. Open a Project
  539. ==============
  540. .. program:: cmake
  541. .. code-block:: shell
  542. cmake --open <dir>
  543. Open the generated project in the associated application. This is only
  544. supported by some generators.
  545. .. _`Script Processing Mode`:
  546. Run a Script
  547. ============
  548. .. program:: cmake
  549. .. code-block:: shell
  550. cmake [-D <var>=<value>]... -P <cmake-script-file> [-- <unparsed-options>...]
  551. .. program:: cmake-P
  552. .. option:: -D <var>=<value>
  553. Define a variable for script mode.
  554. .. program:: cmake
  555. .. option:: -P <cmake-script-file>
  556. Process the given cmake file as a script written in the CMake
  557. language. No configure or generate step is performed and the cache
  558. is not modified. If variables are defined using ``-D``, this must be
  559. done before the ``-P`` argument.
  560. Any options after ``--`` are not parsed by CMake, but they are still included
  561. in the set of :variable:`CMAKE_ARGV<n> <CMAKE_ARGV0>` variables passed to the
  562. script (including the ``--`` itself).
  563. .. _`Run a Command-Line Tool`:
  564. Run a Command-Line Tool
  565. =======================
  566. .. program:: cmake
  567. CMake provides builtin command-line tools through the signature
  568. .. code-block:: shell
  569. cmake -E <command> [<options>]
  570. .. option:: -E [help]
  571. Run ``cmake -E`` or ``cmake -E help`` for a summary of commands.
  572. .. program:: cmake-E
  573. Available commands are:
  574. .. option:: capabilities
  575. .. versionadded:: 3.7
  576. Report cmake capabilities in JSON format. The output is a JSON object
  577. with the following keys:
  578. ``version``
  579. A JSON object with version information. Keys are:
  580. ``string``
  581. The full version string as displayed by cmake :option:`--version <cmake --version>`.
  582. ``major``
  583. The major version number in integer form.
  584. ``minor``
  585. The minor version number in integer form.
  586. ``patch``
  587. The patch level in integer form.
  588. ``suffix``
  589. The cmake version suffix string.
  590. ``isDirty``
  591. A bool that is set if the cmake build is from a dirty tree.
  592. ``generators``
  593. A list available generators. Each generator is a JSON object with the
  594. following keys:
  595. ``name``
  596. A string containing the name of the generator.
  597. ``toolsetSupport``
  598. ``true`` if the generator supports toolsets and ``false`` otherwise.
  599. ``platformSupport``
  600. ``true`` if the generator supports platforms and ``false`` otherwise.
  601. ``supportedPlatforms``
  602. .. versionadded:: 3.21
  603. Optional member that may be present when the generator supports
  604. platform specification via :variable:`CMAKE_GENERATOR_PLATFORM`
  605. (:option:`-A ... <cmake -A>`). The value is a list of platforms known to
  606. be supported.
  607. ``extraGenerators``
  608. A list of strings with all the :ref:`Extra Generators` compatible with
  609. the generator.
  610. ``fileApi``
  611. Optional member that is present when the :manual:`cmake-file-api(7)`
  612. is available. The value is a JSON object with one member:
  613. ``requests``
  614. A JSON array containing zero or more supported file-api requests.
  615. Each request is a JSON object with members:
  616. ``kind``
  617. Specifies one of the supported :ref:`file-api object kinds`.
  618. ``version``
  619. A JSON array whose elements are each a JSON object containing
  620. ``major`` and ``minor`` members specifying non-negative integer
  621. version components.
  622. ``serverMode``
  623. ``true`` if cmake supports server-mode and ``false`` otherwise.
  624. Always false since CMake 3.20.
  625. ``tls``
  626. .. versionadded:: 3.25
  627. ``true`` if TLS support is enabled and ``false`` otherwise.
  628. ``debugger``
  629. .. versionadded:: 3.27
  630. ``true`` if the :option:`--debugger <cmake --debugger>` mode
  631. is supported and ``false`` otherwise.
  632. .. option:: cat [--] <files>...
  633. .. versionadded:: 3.18
  634. Concatenate files and print on the standard output.
  635. .. program:: cmake-E_cat
  636. .. option:: --
  637. .. versionadded:: 3.24
  638. Added support for the double dash argument ``--``. This basic implementation
  639. of ``cat`` does not support any options, so using a option starting with
  640. ``-`` will result in an error. Use ``--`` to indicate the end of options, in
  641. case a file starts with ``-``.
  642. .. versionadded:: 3.29
  643. ``cat`` can now print the standard input by passing the ``-`` argument.
  644. .. program:: cmake-E
  645. .. option:: chdir <dir> <cmd> [<arg>...]
  646. Change the current working directory and run a command.
  647. .. option:: compare_files [--ignore-eol] <file1> <file2>
  648. Check if ``<file1>`` is same as ``<file2>``. If files are the same,
  649. then returns ``0``, if not it returns ``1``. In case of invalid
  650. arguments, it returns 2.
  651. .. program:: cmake-E_compare_files
  652. .. option:: --ignore-eol
  653. .. versionadded:: 3.14
  654. The option implies line-wise comparison and ignores LF/CRLF differences.
  655. .. program:: cmake-E
  656. .. option:: copy <file>... <destination>, copy -t <destination> <file>...
  657. Copy files to ``<destination>`` (either file or directory).
  658. If multiple files are specified, or if ``-t`` is specified, the
  659. ``<destination>`` must be directory and it must exist. If ``-t`` is not
  660. specified, the last argument is assumed to be the ``<destination>``.
  661. Wildcards are not supported. ``copy`` does follow symlinks. That means it
  662. does not copy symlinks, but the files or directories it point to.
  663. .. versionadded:: 3.5
  664. Support for multiple input files.
  665. .. versionadded:: 3.26
  666. Support for ``-t`` argument.
  667. .. option:: copy_directory <dir>... <destination>
  668. Copy content of ``<dir>...`` directories to ``<destination>`` directory.
  669. If ``<destination>`` directory does not exist it will be created.
  670. ``copy_directory`` does follow symlinks.
  671. .. versionadded:: 3.5
  672. Support for multiple input directories.
  673. .. versionadded:: 3.15
  674. The command now fails when the source directory does not exist.
  675. Previously it succeeded by creating an empty destination directory.
  676. .. option:: copy_directory_if_different <dir>... <destination>
  677. .. versionadded:: 3.26
  678. Copy changed content of ``<dir>...`` directories to ``<destination>`` directory.
  679. If ``<destination>`` directory does not exist it will be created.
  680. ``copy_directory_if_different`` does follow symlinks.
  681. The command fails when the source directory does not exist.
  682. .. option:: copy_if_different <file>... <destination>
  683. Copy files to ``<destination>`` (either file or directory) if
  684. they have changed.
  685. If multiple files are specified, the ``<destination>`` must be
  686. directory and it must exist.
  687. ``copy_if_different`` does follow symlinks.
  688. .. versionadded:: 3.5
  689. Support for multiple input files.
  690. .. option:: create_symlink <old> <new>
  691. Create a symbolic link ``<new>`` naming ``<old>``.
  692. .. versionadded:: 3.13
  693. Support for creating symlinks on Windows.
  694. .. note::
  695. Path to where ``<new>`` symbolic link will be created has to exist beforehand.
  696. .. option:: create_hardlink <old> <new>
  697. .. versionadded:: 3.19
  698. Create a hard link ``<new>`` naming ``<old>``.
  699. .. note::
  700. Path to where ``<new>`` hard link will be created has to exist beforehand.
  701. ``<old>`` has to exist beforehand.
  702. .. option:: echo [<string>...]
  703. Displays arguments as text.
  704. .. option:: echo_append [<string>...]
  705. Displays arguments as text but no new line.
  706. .. option:: env [<options>] [--] <command> [<arg>...]
  707. .. versionadded:: 3.1
  708. Run command in a modified environment. Options are:
  709. .. program:: cmake-E_env
  710. .. option:: NAME=VALUE
  711. Replaces the current value of ``NAME`` with ``VALUE``.
  712. .. option:: --unset=NAME
  713. Unsets the current value of ``NAME``.
  714. .. option:: --modify ENVIRONMENT_MODIFICATION
  715. .. versionadded:: 3.25
  716. Apply a single :prop_test:`ENVIRONMENT_MODIFICATION` operation to the
  717. modified environment.
  718. The ``NAME=VALUE`` and ``--unset=NAME`` options are equivalent to
  719. ``--modify NAME=set:VALUE`` and ``--modify NAME=unset:``, respectively.
  720. Note that ``--modify NAME=reset:`` resets ``NAME`` to the value it had
  721. when :program:`cmake` launched (or unsets it), not to the most recent
  722. ``NAME=VALUE`` option.
  723. .. option:: --
  724. .. versionadded:: 3.24
  725. Added support for the double dash argument ``--``. Use ``--`` to stop
  726. interpreting options/environment variables and treat the next argument as
  727. the command, even if it start with ``-`` or contains a ``=``.
  728. .. program:: cmake-E
  729. .. option:: environment
  730. Display the current environment variables.
  731. .. option:: false
  732. .. versionadded:: 3.16
  733. Do nothing, with an exit code of 1.
  734. .. option:: make_directory <dir>...
  735. Create ``<dir>`` directories. If necessary, create parent
  736. directories too. If a directory already exists it will be
  737. silently ignored.
  738. .. versionadded:: 3.5
  739. Support for multiple input directories.
  740. .. option:: md5sum <file>...
  741. Create MD5 checksum of files in ``md5sum`` compatible format::
  742. 351abe79cd3800b38cdfb25d45015a15 file1.txt
  743. 052f86c15bbde68af55c7f7b340ab639 file2.txt
  744. .. option:: sha1sum <file>...
  745. .. versionadded:: 3.10
  746. Create SHA1 checksum of files in ``sha1sum`` compatible format::
  747. 4bb7932a29e6f73c97bb9272f2bdc393122f86e0 file1.txt
  748. 1df4c8f318665f9a5f2ed38f55adadb7ef9f559c file2.txt
  749. .. option:: sha224sum <file>...
  750. .. versionadded:: 3.10
  751. Create SHA224 checksum of files in ``sha224sum`` compatible format::
  752. b9b9346bc8437bbda630b0b7ddfc5ea9ca157546dbbf4c613192f930 file1.txt
  753. 6dfbe55f4d2edc5fe5c9197bca51ceaaf824e48eba0cc453088aee24 file2.txt
  754. .. option:: sha256sum <file>...
  755. .. versionadded:: 3.10
  756. Create SHA256 checksum of files in ``sha256sum`` compatible format::
  757. 76713b23615d31680afeb0e9efe94d47d3d4229191198bb46d7485f9cb191acc file1.txt
  758. 15b682ead6c12dedb1baf91231e1e89cfc7974b3787c1e2e01b986bffadae0ea file2.txt
  759. .. option:: sha384sum <file>...
  760. .. versionadded:: 3.10
  761. Create SHA384 checksum of files in ``sha384sum`` compatible format::
  762. acc049fedc091a22f5f2ce39a43b9057fd93c910e9afd76a6411a28a8f2b8a12c73d7129e292f94fc0329c309df49434 file1.txt
  763. 668ddeb108710d271ee21c0f3acbd6a7517e2b78f9181c6a2ff3b8943af92b0195dcb7cce48aa3e17893173c0a39e23d file2.txt
  764. .. option:: sha512sum <file>...
  765. .. versionadded:: 3.10
  766. Create SHA512 checksum of files in ``sha512sum`` compatible format::
  767. 2a78d7a6c5328cfb1467c63beac8ff21794213901eaadafd48e7800289afbc08e5fb3e86aa31116c945ee3d7bf2a6194489ec6101051083d1108defc8e1dba89 file1.txt
  768. 7a0b54896fe5e70cca6dd643ad6f672614b189bf26f8153061c4d219474b05dad08c4e729af9f4b009f1a1a280cb625454bf587c690f4617c27e3aebdf3b7a2d file2.txt
  769. .. option:: remove [-f] <file>...
  770. .. deprecated:: 3.17
  771. Remove the file(s). The planned behavior was that if any of the
  772. listed files already do not exist, the command returns a non-zero exit code,
  773. but no message is logged. The ``-f`` option changes the behavior to return a
  774. zero exit code (i.e. success) in such situations instead.
  775. ``remove`` does not follow symlinks. That means it remove only symlinks
  776. and not files it point to.
  777. The implementation was buggy and always returned 0. It cannot be fixed without
  778. breaking backwards compatibility. Use ``rm`` instead.
  779. .. option:: remove_directory <dir>...
  780. .. deprecated:: 3.17
  781. Remove ``<dir>`` directories and their contents. If a directory does
  782. not exist it will be silently ignored.
  783. Use ``rm`` instead.
  784. .. versionadded:: 3.15
  785. Support for multiple directories.
  786. .. versionadded:: 3.16
  787. If ``<dir>`` is a symlink to a directory, just the symlink will be removed.
  788. .. option:: rename <oldname> <newname>
  789. Rename a file or directory (on one volume). If file with the ``<newname>`` name
  790. already exists, then it will be silently replaced.
  791. .. option:: rm [-rRf] [--] <file|dir>...
  792. .. versionadded:: 3.17
  793. Remove the files ``<file>`` or directories ``<dir>``.
  794. Use ``-r`` or ``-R`` to remove directories and their contents recursively.
  795. If any of the listed files/directories do not exist, the command returns a
  796. non-zero exit code, but no message is logged. The ``-f`` option changes
  797. the behavior to return a zero exit code (i.e. success) in such
  798. situations instead. Use ``--`` to stop interpreting options and treat all
  799. remaining arguments as paths, even if they start with ``-``.
  800. .. option:: sleep <number>
  801. .. versionadded:: 3.0
  802. Sleep for ``<number>`` seconds. ``<number>`` may be a floating point number.
  803. A practical minimum is about 0.1 seconds due to overhead in starting/stopping
  804. CMake executable. This can be useful in a CMake script to insert a delay:
  805. .. code-block:: cmake
  806. # Sleep for about 0.5 seconds
  807. execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 0.5)
  808. .. option:: tar [cxt][vf][zjJ] file.tar [<options>] [--] [<pathname>...]
  809. Create or extract a tar or zip archive. Options are:
  810. .. program:: cmake-E_tar
  811. .. option:: c
  812. Create a new archive containing the specified files.
  813. If used, the ``<pathname>...`` argument is mandatory.
  814. .. option:: x
  815. Extract to disk from the archive.
  816. .. versionadded:: 3.15
  817. The ``<pathname>...`` argument could be used to extract only selected files
  818. or directories.
  819. When extracting selected files or directories, you must provide their exact
  820. names including the path, as printed by list (``-t``).
  821. .. option:: t
  822. List archive contents.
  823. .. versionadded:: 3.15
  824. The ``<pathname>...`` argument could be used to list only selected files
  825. or directories.
  826. .. option:: v
  827. Produce verbose output.
  828. .. option:: z
  829. Compress the resulting archive with gzip.
  830. .. option:: j
  831. Compress the resulting archive with bzip2.
  832. .. option:: J
  833. .. versionadded:: 3.1
  834. Compress the resulting archive with XZ.
  835. .. option:: --zstd
  836. .. versionadded:: 3.15
  837. Compress the resulting archive with Zstandard.
  838. .. option:: --files-from=<file>
  839. .. versionadded:: 3.1
  840. Read file names from the given file, one per line.
  841. Blank lines are ignored. Lines may not start in ``-``
  842. except for ``--add-file=<name>`` to add files whose
  843. names start in ``-``.
  844. .. option:: --format=<format>
  845. .. versionadded:: 3.3
  846. Specify the format of the archive to be created.
  847. Supported formats are: ``7zip``, ``gnutar``, ``pax``,
  848. ``paxr`` (restricted pax, default), and ``zip``.
  849. .. option:: --mtime=<date>
  850. .. versionadded:: 3.1
  851. Specify modification time recorded in tarball entries.
  852. .. option:: --touch
  853. .. versionadded:: 3.24
  854. Use current local timestamp instead of extracting file timestamps
  855. from the archive.
  856. .. option:: --
  857. .. versionadded:: 3.1
  858. Stop interpreting options and treat all remaining arguments
  859. as file names, even if they start with ``-``.
  860. .. versionadded:: 3.1
  861. LZMA (7zip) support.
  862. .. versionadded:: 3.15
  863. The command now continues adding files to an archive even if some of the
  864. files are not readable. This behavior is more consistent with the classic
  865. ``tar`` tool. The command now also parses all flags, and if an invalid flag
  866. was provided, a warning is issued.
  867. .. program:: cmake-E
  868. .. option:: time <command> [<args>...]
  869. Run ``<command>`` and display elapsed time (including overhead of CMake frontend).
  870. .. versionadded:: 3.5
  871. The command now properly passes arguments with spaces or special characters
  872. through to the child process. This may break scripts that worked around the
  873. bug with their own extra quoting or escaping.
  874. .. option:: touch <file>...
  875. Creates ``<file>`` if file do not exist.
  876. If ``<file>`` exists, it is changing ``<file>`` access and modification times.
  877. .. option:: touch_nocreate <file>...
  878. Touch a file if it exists but do not create it. If a file does
  879. not exist it will be silently ignored.
  880. .. option:: true
  881. .. versionadded:: 3.16
  882. Do nothing, with an exit code of 0.
  883. Windows-specific Command-Line Tools
  884. -----------------------------------
  885. The following ``cmake -E`` commands are available only on Windows:
  886. .. option:: delete_regv <key>
  887. Delete Windows registry value.
  888. .. option:: env_vs8_wince <sdkname>
  889. .. versionadded:: 3.2
  890. Displays a batch file which sets the environment for the provided
  891. Windows CE SDK installed in VS2005.
  892. .. option:: env_vs9_wince <sdkname>
  893. .. versionadded:: 3.2
  894. Displays a batch file which sets the environment for the provided
  895. Windows CE SDK installed in VS2008.
  896. .. option:: write_regv <key> <value>
  897. Write Windows registry value.
  898. .. _`Find-Package Tool Mode`:
  899. Run the Find-Package Tool
  900. =========================
  901. .. program:: cmake--find-package
  902. CMake provides a pkg-config like helper for Makefile-based projects:
  903. .. code-block:: shell
  904. cmake --find-package [<options>]
  905. .. note::
  906. This mode is not well-supported due to some technical limitations.
  907. It is kept for compatibility but should not be used in new projects.
  908. .. option:: --find-package
  909. It searches a package using the :command:`find_package` command and prints the
  910. resulting flags to stdout. This can be used instead of pkg-config to find
  911. installed libraries in plain Makefile-based projects or in Autoconf-based
  912. projects, using auxiliary macros installed in ``share/aclocal/cmake.m4`` on
  913. the system.
  914. When using this option, the following variables are expected:
  915. ``NAME``
  916. Name of the package as called in ``find_package(<PackageName>)``.
  917. ``COMPILER_ID``
  918. :variable:`Compiler ID <CMAKE_<LANG>_COMPILER_ID>` used for searching the
  919. package, i.e. GNU/Intel/Clang/MSVC, etc.
  920. ``LANGUAGE``
  921. Language used for searching the package, i.e. C/CXX/Fortran/ASM, etc.
  922. ``MODE``
  923. The package search mode. Value can be one of:
  924. ``EXIST``
  925. Only checks for existence of the given package.
  926. ``COMPILE``
  927. Prints the flags needed for compiling an object file which uses the given
  928. package.
  929. ``LINK``
  930. Prints the flags needed for linking when using the given package.
  931. ``SILENT``
  932. (Optional) If TRUE, find result message is not printed.
  933. For example:
  934. .. code-block:: shell
  935. cmake --find-package -DNAME=CURL -DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=LINK
  936. .. _`Workflow Mode`:
  937. Run a Workflow Preset
  938. =====================
  939. .. versionadded:: 3.25
  940. .. program:: cmake
  941. :manual:`CMake Presets <cmake-presets(7)>` provides a way to execute multiple
  942. build steps in order:
  943. .. code-block:: shell
  944. cmake --workflow <options>
  945. The options are:
  946. .. option:: --workflow
  947. Select a :ref:`Workflow Preset` using one of the following options.
  948. .. program:: cmake--workflow
  949. .. option:: --preset <preset>, --preset=<preset>
  950. Use a workflow preset to specify a workflow. The project binary directory
  951. is inferred from the initial configure preset. The current working directory
  952. must contain CMake preset files.
  953. See :manual:`preset <cmake-presets(7)>` for more details.
  954. .. versionchanged:: 3.31
  955. When following immediately after the ``--workflow`` option,
  956. the ``--preset`` argument can be omitted and just the ``<preset>``
  957. name can be given. This means the following syntax is valid:
  958. .. code-block:: console
  959. $ cmake --workflow my-preset
  960. .. option:: --list-presets
  961. Lists the available workflow presets. The current working directory must
  962. contain CMake preset files.
  963. .. option:: --fresh
  964. Perform a fresh configuration of the build tree, which has the same effect
  965. as :option:`cmake --fresh`.
  966. View Help
  967. =========
  968. .. program:: cmake
  969. To print selected pages from the CMake documentation, use
  970. .. code-block:: shell
  971. cmake --help[-<topic>]
  972. with one of the following options:
  973. .. include:: include/OPTIONS_HELP.rst
  974. To view the presets available for a project, use
  975. .. code-block:: shell
  976. cmake <source-dir> --list-presets
  977. .. _`CMake Exit Code`:
  978. Return Value (Exit Code)
  979. ========================
  980. Upon regular termination, the :program:`cmake` executable returns the exit code ``0``.
  981. If termination is caused by the command :command:`message(FATAL_ERROR)`,
  982. or another error condition, then a non-zero exit code is returned.
  983. See Also
  984. ========
  985. .. include:: include/LINKS.rst