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.

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