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.

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