cmake.1.rst 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  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>
  9. cmake [<options>] <path-to-existing-build>
  10. cmake [<options>] -S <path-to-source> -B <path-to-build>
  11. cmake [<options>] -S <path-to-source> --preset=<preset-name>
  12. `Build a Project`_
  13. cmake --build <dir> [<options>] [-- <build-tool-options>]
  14. `Install a Project`_
  15. cmake --install <dir> [<options>]
  16. `Open a Project`_
  17. cmake --open <dir>
  18. `Run a Script`_
  19. cmake [{-D <var>=<value>}...] -P <cmake-script-file>
  20. `Run a Command-Line Tool`_
  21. cmake -E <command> [<options>]
  22. `Run the Find-Package Tool`_
  23. cmake --find-package [<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 ``cmake --help`` to see a list of generators available locally.
  76. Optionally use the ``-G`` option below to specify a generator, or simply
  77. accept the default CMake chooses for the current platform.
  78. When using one of the :ref:`Command-Line Build Tool Generators`
  79. CMake expects that the environment needed by the compiler toolchain
  80. is already configured in the shell. When using one of the
  81. :ref:`IDE Build Tool Generators`, no particular environment is needed.
  82. Generate a Project Buildsystem
  83. ==============================
  84. Run CMake with one of the following command signatures to specify the
  85. source and build trees and generate a buildsystem:
  86. ``cmake [<options>] <path-to-source>``
  87. Uses the current working directory as the build tree, and
  88. ``<path-to-source>`` as the source tree. The specified path may
  89. be absolute or relative to the current working directory.
  90. The source tree must contain a ``CMakeLists.txt`` file and must
  91. *not* contain a ``CMakeCache.txt`` file because the latter
  92. identifies an existing build tree. For example:
  93. .. code-block:: console
  94. $ mkdir build ; cd build
  95. $ cmake ../src
  96. ``cmake [<options>] <path-to-existing-build>``
  97. Uses ``<path-to-existing-build>`` as the build tree, and loads the
  98. path to the source tree from its ``CMakeCache.txt`` file, which must
  99. have already been generated by a previous run of CMake. The specified
  100. path may be absolute or relative to the current working directory.
  101. For example:
  102. .. code-block:: console
  103. $ cd build
  104. $ cmake .
  105. ``cmake [<options>] -S <path-to-source> -B <path-to-build>``
  106. Uses ``<path-to-build>`` as the build tree and ``<path-to-source>``
  107. as the source tree. The specified paths may be absolute or relative
  108. to the current working directory. The source tree must contain a
  109. ``CMakeLists.txt`` file. The build tree will be created automatically
  110. if it does not already exist. For example:
  111. .. code-block:: console
  112. $ cmake -S src -B build
  113. ``cmake [<options>] -S <path-to-source> --preset=<preset-name>``
  114. Uses ``<path-to-source>`` as the source tree and reads a preset from
  115. ``<path-to-source>/CMakePresets.json`` and
  116. ``<path-to-source>/CMakeUserPresets.json``. The preset specifies the
  117. generator and the build directory, and optionally a list of variables and
  118. other arguments to pass to CMake. The :manual:`CMake GUI <cmake-gui(1)>` can
  119. also recognize ``CMakePresets.json`` and ``CMakeUserPresets.json`` files.
  120. ``CMakePresets.json`` and ``CMakeUserPresets.json`` have exactly the same
  121. format, and both are optional (though at least one must be present if
  122. ``--preset`` is specified.) ``CMakePresets.json`` is meant to save
  123. project-wide builds, while ``CMakeUserPresets.json`` is meant for developers
  124. to save their own local builds. ``CMakePresets.json`` may be checked into a
  125. version control system, and ``CMakeUserPresets.json`` should NOT be checked
  126. in. For example, if a project is using Git, ``CMakePresets.json`` may be
  127. tracked, and ``CMakeUserPresets.json`` should be added to the ``.gitignore``.
  128. The presets are read before all other command line options. The options
  129. specified by the preset (variables, generator, etc.) can all be overridden by
  130. manually specifying them on the command line. For example, if the preset sets
  131. a variable called ``MYVAR`` to ``1``, but the user sets it to ``2`` with a
  132. ``-D`` argument, the value ``2`` is preferred.
  133. The files are a JSON document with an object as the root:
  134. .. code-block:: json
  135. {
  136. "version": 1,
  137. "cmakeMinimumRequired": {
  138. "major": 3,
  139. "minor": 19,
  140. "patch": 0
  141. },
  142. "configurePresets": [
  143. {
  144. "name": "default",
  145. "displayName": "Default Config",
  146. "description": "Default build using Ninja generator",
  147. "generator": "Ninja",
  148. "binaryDir": "${sourceDir}/build/default",
  149. "cacheVariables": [
  150. {
  151. "name": "MY_CACHE_VARIABLE",
  152. "type": "BOOL",
  153. "value": "OFF"
  154. }
  155. ]
  156. }
  157. ]
  158. }
  159. The root object recognizes the following fields:
  160. ``version``
  161. A required integer representing the version of the JSON schema. Currently,
  162. the only supported version is 1.
  163. ``cmakeMinimumRequired``
  164. An optional object representing the minimum version of CMake needed to
  165. build this project. This object consists of the following fields:
  166. ``major``
  167. An optional integer representing the major version.
  168. ``minor``
  169. An optional integer representing the minor version.
  170. ``patch``
  171. An optional integer representing the patch version.
  172. ``vendor``
  173. An optional map containing vendor-specific information. CMake does not
  174. interpret the contents of this field except to verify that it is a map if
  175. it does exist. However, the keys should be a vendor-specific domain name
  176. followed by a ``/``-separated path. For example, the Example IDE 1.0 could
  177. use ``example.com/ExampleIDE/1.0``. The value of each field can be anything
  178. desired by the vendor, though will typically be a map. For example:
  179. .. code-block:: json
  180. {
  181. "version": 1,
  182. "vendor": {
  183. "example.com/ExampleIDE/1.0": {
  184. "autoFormat": true
  185. }
  186. },
  187. "configurePresets": []
  188. }
  189. ``configurePresets``
  190. An optional array of configure preset objects. Each preset may contain the
  191. following fields:
  192. ``name``
  193. A required string representing the machine-friendly name of the preset.
  194. This identifier is used in the ``--preset`` argument. There must not be
  195. two presets in the union of ``CMakePresets.json`` and
  196. ``CMakeUserPresets.json`` in the same directory with the same name.
  197. ``hidden``
  198. An optional boolean specifying whether or not a preset should be hidden.
  199. If a preset is hidden, it cannot be used in the ``--preset=`` argument,
  200. will not show up in the :manual:`CMake GUI <cmake-gui(1)>`, and does not
  201. have to have a valid ``generator`` or ``binaryDir``, even from
  202. inheritance. ``hidden`` presets are intended to be used as a base for
  203. other presets to inherit via the ``inherits`` field.
  204. ``inherits``
  205. An optional array of strings representing the names of presets to inherit
  206. from. The preset will inherit all of the fields from the ``inherits``
  207. presets by default (except ``name``, ``hidden``, ``inherits``,
  208. ``description``, and ``longDescription``), but can override them as
  209. desired. If multiple ``inherits`` presets provide conflicting values for
  210. the same field, the earlier preset in the ``inherits`` list will be
  211. preferred. Presets in ``CMakePresets.json`` may not inherit from presets
  212. in ``CMakeUserPresets.json``.
  213. This field can also be a string, which is equivalent to an array
  214. containing one string.
  215. ``vendor``
  216. An optional map containing vendor-specific information. CMake does not
  217. interpret the contents of this field except to verify that it is a map
  218. if it does exist. However, it should follow the same conventions as the
  219. root-level ``vendor`` field. If vendors use their own per-preset
  220. ``vendor`` field, they should implement inheritance in a sensible manner
  221. when appropriate.
  222. ``displayName``
  223. An optional string with a human-friendly name of the preset.
  224. ``description``
  225. An optional string with a human-friendly description of the preset.
  226. ``generator``
  227. An optional string representing the generator to use for the preset. If
  228. ``generator`` is not specified, it must be inherited from the
  229. ``inherits`` preset (unless this preset is ``hidden``).
  230. Note that for Visual Studio generators, unlike in the command line ``-G``
  231. argument, you cannot include the platform name in the generator name. Use
  232. the ``architecture`` field instead.
  233. ``architecture``
  234. An optional string representing the platform name to use for Visual
  235. Studio generators.
  236. ``toolset``
  237. An optional string representing the toolset name to use for Visual Studio
  238. generators.
  239. ``cmakeGeneratorConfig``
  240. An optional string telling CMake how to handle the ``architecture`` and
  241. ``toolset`` fields. Valid values are:
  242. ``"default"``
  243. Set the platform and toolset using the ``architecture`` and ``toolset``
  244. fields respectively. On non-Visual Studio generators, this will result
  245. in an error if ``architecture`` or ``toolset`` are set.
  246. ``"ignore"``
  247. Do not set the platform or toolset at all, even on Visual Studio
  248. generators. This is useful if, for example, a preset uses the Ninja
  249. generator, and an IDE knows how to set up the Visual C++ environment
  250. from the ``architecture`` and ``toolset`` fields. In that case, CMake
  251. will ignore ``architecture`` and ``toolset``, but the IDE can use them
  252. to set up the environment before invoking CMake.
  253. ``binaryDir``
  254. An optional string representing the path to the output binary directory.
  255. This field supports macro expansion. If a relative path is specified, it
  256. is calculated relative to the source directory. If ``binaryDir`` is not
  257. specified, it must be inherited from the ``inherits`` preset (unless this
  258. preset is ``hidden``).
  259. ``cmakeExecutable``
  260. An optional string representing the path to the CMake executable to use
  261. for this preset. This is reserved for use by IDEs, and is not used by
  262. CMake itself. IDEs that use this field should expand any macros in it.
  263. ``cacheVariables``
  264. An optional map of cache variables. The key is the variable name, and the
  265. value is either ``null``, a string representing the value of the variable
  266. (which supports macro expansion), or an object with the following fields:
  267. ``type``
  268. An optional string representing the type of the variable.
  269. ``value``
  270. A required string representing the value of the variable. This field
  271. supports macro expansion.
  272. Cache variables are inherited through the ``inherits`` field, and the
  273. preset's variables will be the union of its own ``cacheVariables`` and
  274. the ``cacheVariables`` from all its parents. If multiple presets in this
  275. union define the same variable, the standard rules of ``inherits`` are
  276. applied. Setting a variable to ``null`` causes it to not be set, even if
  277. a value was inherited from another preset.
  278. ``environment``
  279. An optional map of environment variables. The key is the variable name,
  280. and the value is either ``null`` or a string representing the value of
  281. the variable. Each variable is set regardless of whether or not a value
  282. was given to it by the process's environment. This field supports macro
  283. expansion, and environment variables in this map may reference each
  284. other, and may be listed in any order, as long as such references do not
  285. cause a cycle (for example, if ``ENV_1`` is ``$env{ENV_2}``, ``ENV_2``
  286. may not be ``$env{ENV_1}``.)
  287. Environment variables are inherited through the ``inherits`` field, and
  288. the preset's environment will be the union of its own ``environment`` and
  289. the ``environment`` from all its parents. If multiple presets in this
  290. union define the same variable, the standard rules of ``inherits`` are
  291. applied. Setting a variable to ``null`` causes it to not be set, even if
  292. a value was inherited from another preset.
  293. ``warnings``
  294. An optional object specifying warnings. The object may contain the
  295. following fields:
  296. ``dev``
  297. An optional boolean. Equivalent to passing ``-Wdev`` or ``-Wno-dev``
  298. on the command line. This may not be set to ``false`` if ``errors.dev``
  299. is set to ``true``.
  300. ``deprecated``
  301. An optional boolean. Equivalent to passing ``-Wdeprecated`` or
  302. ``-Wno-deprecated`` on the command line. This may not be set to
  303. ``false`` if ``errors.deprecated`` is set to ``true``.
  304. ``uninitialized``
  305. An optional boolean. Setting this to ``true`` is equivalent to passing
  306. ``--warn-uninitialized`` on the command line.
  307. ``unusedVars``
  308. An optional boolean. Setting this to ``false`` is equivalent to passing
  309. ``--no-warn-unused-cli`` on the command line.
  310. ``systemVars``
  311. An optional boolean. Setting this to ``true`` is equivalent to passing
  312. ``--check-system-vars`` on the command line.
  313. ``errors``
  314. An optional object specifying errors. The object may contain the
  315. following fields:
  316. ``dev``
  317. An optional boolean. Equivalent to passing ``-Werror=dev`` or
  318. ``-Wno-error=dev`` on the command line. This may not be set to ``true``
  319. if ``warnings.dev`` is set to ``false``.
  320. ``deprecated``
  321. An optional boolean. Equivalent to passing ``-Werror=deprecated`` or
  322. ``-Wno-error=deprecated`` on the command line. This may not be set to
  323. ``true`` if ``warnings.deprecated`` is set to ``false``.
  324. As mentioned above, some fields support macro expansion. Macros are
  325. recognized in the form ``$<macro-namespace>{<macro-name>}``. All macros are
  326. evaluated in the context of the preset being used, even if the macro is in a
  327. field that was inherited from another preset. For example, if the ``Base``
  328. preset sets variable ``PRESET_NAME`` to ``${presetName}``, and the
  329. ``Derived`` preset inherits from ``Base``, ``PRESET_NAME`` will be set to
  330. ``Derived``.
  331. It is an error to not put a closing brace at the end of a macro name. For
  332. example, ``${sourceDir`` is invalid. A dollar sign (``$``) followed by
  333. anything other than a left curly brace (``{``) with a possible namespace is
  334. interpreted as a literal dollar sign.
  335. Recognized macros include:
  336. ``${sourceDir}``
  337. Path to the project source directory.
  338. ``${sourceParentDir}``
  339. Path to the project source directory's parent directory.
  340. ``${presetName}``
  341. Name specified in the preset's ``name`` field.
  342. ``${generator}``
  343. Generator specified in the preset's ``generator`` field.
  344. ``${dollar}``
  345. A literal dollar sign (``$``).
  346. ``$env{<variable-name>}``
  347. Environment variable with name ``<variable-name>``. If the variable is
  348. defined in the ``environment`` field, that value is used instead of the
  349. value from the parent environment. If the environment variable is not
  350. defined, this evaluates as an empty string.
  351. Note that while Windows environment variable names are case-insensitive,
  352. variable names within a preset are still case-sensitive. This may lead to
  353. unexpected results when using inconsistent casing. For best results, keep
  354. the casing of environment variable names consistent.
  355. ``$penv{<variable-name>}``
  356. Similar to ``$env{<variable-name>}``, except that the value only comes from
  357. the parent environment, and never from the ``environment`` field. This
  358. allows you to prepend or append values to existing environment variables.
  359. For example, setting ``PATH`` to ``/path/to/ninja/bin:$penv{PATH}`` will
  360. prepend ``/path/to/ninja/bin`` to the ``PATH`` environment variable. This
  361. is needed because ``$env{<variable-name>}`` does not allow circular
  362. references.
  363. ``$vendor{<macro-name>}``
  364. An extension point for vendors to insert their own macros. CMake will not
  365. be able to use presets which have a ``$vendor{<macro-name>}`` macro, and
  366. effectively ignores such presets. However, it will still be able to use
  367. other presets from the same file.
  368. CMake does not make any attempt to interpret ``$vendor{<macro-name>}``
  369. macros. However, to avoid name collisions, IDE vendors should prefix
  370. ``<macro-name>`` with a very short (preferably <= 4 characters) vendor
  371. identifier prefix, followed by a ``.``, followed by the macro name. For
  372. example, the Example IDE could have ``$vendor{xide.ideInstallDir}``.
  373. In all cases the ``<options>`` may be zero or more of the `Options`_ below.
  374. After generating a buildsystem one may use the corresponding native
  375. build tool to build the project. For example, after using the
  376. :generator:`Unix Makefiles` generator one may run ``make`` directly:
  377. .. code-block:: console
  378. $ make
  379. $ make install
  380. Alternatively, one may use **cmake** to `Build a Project`_ by
  381. automatically choosing and invoking the appropriate native build tool.
  382. .. _`CMake Options`:
  383. Options
  384. -------
  385. .. include:: OPTIONS_BUILD.txt
  386. ``-L[A][H]``
  387. List non-advanced cached variables.
  388. List ``CACHE`` variables will run CMake and list all the variables from
  389. the CMake ``CACHE`` that are not marked as ``INTERNAL`` or :prop_cache:`ADVANCED`.
  390. This will effectively display current CMake settings, which can then be
  391. changed with ``-D`` option. Changing some of the variables may result
  392. in more variables being created. If ``A`` is specified, then it will
  393. display also advanced variables. If ``H`` is specified, it will also
  394. display help for each variable.
  395. ``-N``
  396. View mode only.
  397. Only load the cache. Do not actually run configure and generate
  398. steps.
  399. ``--graphviz=[file]``
  400. Generate graphviz of dependencies, see :module:`CMakeGraphVizOptions` for more.
  401. Generate a graphviz input file that will contain all the library and
  402. executable dependencies in the project. See the documentation for
  403. :module:`CMakeGraphVizOptions` for more details.
  404. ``--system-information [file]``
  405. Dump information about this system.
  406. Dump a wide range of information about the current system. If run
  407. from the top of a binary tree for a CMake project it will dump
  408. additional information such as the cache, log files etc.
  409. ``--log-level=<ERROR|WARNING|NOTICE|STATUS|VERBOSE|DEBUG|TRACE>``
  410. Set the log level.
  411. The :command:`message` command will only output messages of the specified
  412. log level or higher. The default log level is ``STATUS``.
  413. To make a log level persist between CMake runs, set
  414. :variable:`CMAKE_MESSAGE_LOG_LEVEL` as a cache variable instead.
  415. If both the command line option and the variable are given, the command line
  416. option takes precedence.
  417. For backward compatibility reasons, ``--loglevel`` is also accepted as a
  418. synonym for this option.
  419. ``--log-context``
  420. Enable the :command:`message` command outputting context attached to each
  421. message.
  422. This option turns on showing context for the current CMake run only.
  423. To make showing the context persistent for all subsequent CMake runs, set
  424. :variable:`CMAKE_MESSAGE_CONTEXT_SHOW` as a cache variable instead.
  425. When this command line option is given, :variable:`CMAKE_MESSAGE_CONTEXT_SHOW`
  426. is ignored.
  427. ``--debug-trycompile``
  428. Do not delete the :command:`try_compile` build tree.
  429. Only useful on one :command:`try_compile` at a time.
  430. Do not delete the files and directories created for :command:`try_compile`
  431. calls. This is useful in debugging failed try_compiles. It may
  432. however change the results of the try-compiles as old junk from a
  433. previous try-compile may cause a different test to either pass or
  434. fail incorrectly. This option is best used for one try-compile at a
  435. time, and only when debugging.
  436. ``--debug-output``
  437. Put cmake in a debug mode.
  438. Print extra information during the cmake run like stack traces with
  439. :command:`message(SEND_ERROR)` calls.
  440. ``--debug-find``
  441. Put cmake find commands in a debug mode.
  442. Print extra find call information during the cmake run to standard
  443. error. Output is designed for human consumption and not for parsing.
  444. See also the :variable:`CMAKE_FIND_DEBUG_MODE` variable for debugging
  445. a more local part of the project.
  446. ``--trace``
  447. Put cmake in trace mode.
  448. Print a trace of all calls made and from where.
  449. ``--trace-expand``
  450. Put cmake in trace mode.
  451. Like ``--trace``, but with variables expanded.
  452. ``--trace-format=<format>``
  453. Put cmake in trace mode and sets the trace output format.
  454. ``<format>`` can be one of the following values.
  455. ``human``
  456. Prints each trace line in a human-readable format. This is the
  457. default format.
  458. ``json-v1``
  459. Prints each line as a separate JSON document. Each document is
  460. separated by a newline ( ``\n`` ). It is guaranteed that no
  461. newline characters will be present inside a JSON document.
  462. JSON trace format:
  463. .. code-block:: json
  464. {
  465. "file": "/full/path/to/the/CMake/file.txt",
  466. "line": 0,
  467. "cmd": "add_executable",
  468. "args": ["foo", "bar"],
  469. "time": 1579512535.9687231,
  470. "frame": 2
  471. }
  472. The members are:
  473. ``file``
  474. The full path to the CMake source file where the function
  475. was called.
  476. ``line``
  477. The line in ``file`` of the function call.
  478. ``defer``
  479. Optional member that is present when the function call was deferred
  480. by :command:`cmake_language(DEFER)`. If present, its value is a
  481. string containing the deferred call ``<id>``.
  482. ``cmd``
  483. The name of the function that was called.
  484. ``args``
  485. A string list of all function parameters.
  486. ``time``
  487. Timestamp (seconds since epoch) of the function call.
  488. ``frame``
  489. Stack frame depth of the function that was called.
  490. Additionally, the first JSON document outputted contains the
  491. ``version`` key for the current major and minor version of the
  492. JSON trace format:
  493. .. code-block:: json
  494. {
  495. "version": {
  496. "major": 1,
  497. "minor": 1
  498. }
  499. }
  500. The members are:
  501. ``version``
  502. Indicates the version of the JSON format. The version has a
  503. major and minor components following semantic version conventions.
  504. ``--trace-source=<file>``
  505. Put cmake in trace mode, but output only lines of a specified file.
  506. Multiple options are allowed.
  507. ``--trace-redirect=<file>``
  508. Put cmake in trace mode and redirect trace output to a file instead of stderr.
  509. ``--warn-uninitialized``
  510. Warn about uninitialized values.
  511. Print a warning when an uninitialized variable is used.
  512. ``--warn-unused-vars``
  513. Does nothing. In CMake versions 3.2 and below this enabled warnings about
  514. unused variables. In CMake versions 3.3 through 3.18 the option was broken.
  515. In CMake 3.19 and above the option has been removed.
  516. ``--no-warn-unused-cli``
  517. Don't warn about command line options.
  518. Don't find variables that are declared on the command line, but not
  519. used.
  520. ``--check-system-vars``
  521. Find problems with variable usage in system files.
  522. Normally, unused and uninitialized variables are searched for only
  523. in :variable:`CMAKE_SOURCE_DIR` and :variable:`CMAKE_BINARY_DIR`.
  524. This flag tells CMake to warn about other files as well.
  525. ``--profiling-output=<path>``
  526. Used in conjunction with ``--profiling-format`` to output to a given path.
  527. ``--profiling-format=<file>``
  528. Enable the output of profiling data of CMake script in the given format.
  529. This can aid performance analysis of CMake scripts executed. Third party
  530. applications should be used to process the output into human readable format.
  531. Currently supported values are:
  532. ``google-trace`` Outputs in Google Trace Format, which can be parsed by the
  533. about:tracing tab of Google Chrome or using a plugin for a tool like Trace
  534. Compass.
  535. .. _`Build Tool Mode`:
  536. Build a Project
  537. ===============
  538. CMake provides a command-line signature to build an already-generated
  539. project binary tree:
  540. .. code-block:: shell
  541. cmake --build <dir> [<options>] [-- <build-tool-options>]
  542. This abstracts a native build tool's command-line interface with the
  543. following options:
  544. ``--build <dir>``
  545. Project binary directory to be built. This is required and must be first.
  546. ``--parallel [<jobs>], -j [<jobs>]``
  547. The maximum number of concurrent processes to use when building.
  548. If ``<jobs>`` is omitted the native build tool's default number is used.
  549. The :envvar:`CMAKE_BUILD_PARALLEL_LEVEL` environment variable, if set,
  550. specifies a default parallel level when this option is not given.
  551. Some native build tools always build in parallel. The use of ``<jobs>``
  552. value of ``1`` can be used to limit to a single job.
  553. ``--target <tgt>..., -t <tgt>...``
  554. Build ``<tgt>`` instead of the default target. Multiple targets may be
  555. given, separated by spaces.
  556. ``--config <cfg>``
  557. For multi-configuration tools, choose configuration ``<cfg>``.
  558. ``--clean-first``
  559. Build target ``clean`` first, then build.
  560. (To clean only, use ``--target clean``.)
  561. ``--use-stderr``
  562. Ignored. Behavior is default in CMake >= 3.0.
  563. ``--verbose, -v``
  564. Enable verbose output - if supported - including the build commands to be
  565. executed.
  566. This option can be omitted if :envvar:`VERBOSE` environment variable or
  567. :variable:`CMAKE_VERBOSE_MAKEFILE` cached variable is set.
  568. ``--``
  569. Pass remaining options to the native tool.
  570. Run ``cmake --build`` with no options for quick help.
  571. Install a Project
  572. =================
  573. CMake provides a command-line signature to install an already-generated
  574. project binary tree:
  575. .. code-block:: shell
  576. cmake --install <dir> [<options>]
  577. This may be used after building a project to run installation without
  578. using the generated build system or the native build tool.
  579. The options are:
  580. ``--install <dir>``
  581. Project binary directory to install. This is required and must be first.
  582. ``--config <cfg>``
  583. For multi-configuration generators, choose configuration ``<cfg>``.
  584. ``--component <comp>``
  585. Component-based install. Only install component ``<comp>``.
  586. ``--default-directory-permissions <permissions>``
  587. Default directory install permissions. Permissions in format ``<u=rwx,g=rx,o=rx>``.
  588. ``--prefix <prefix>``
  589. Override the installation prefix, :variable:`CMAKE_INSTALL_PREFIX`.
  590. ``--strip``
  591. Strip before installing.
  592. ``-v, --verbose``
  593. Enable verbose output.
  594. This option can be omitted if :envvar:`VERBOSE` environment variable is set.
  595. Run ``cmake --install`` with no options for quick help.
  596. Open a Project
  597. ==============
  598. .. code-block:: shell
  599. cmake --open <dir>
  600. Open the generated project in the associated application. This is only
  601. supported by some generators.
  602. .. _`Script Processing Mode`:
  603. Run a Script
  604. ============
  605. .. code-block:: shell
  606. cmake [{-D <var>=<value>}...] -P <cmake-script-file> [-- <unparsed-options>...]
  607. Process the given cmake file as a script written in the CMake
  608. language. No configure or generate step is performed and the cache
  609. is not modified. If variables are defined using ``-D``, this must be
  610. done before the ``-P`` argument.
  611. Any options after ``--`` are not parsed by CMake, but they are still included
  612. in the set of :variable:`CMAKE_ARGV<n> <CMAKE_ARGV0>` variables passed to the
  613. script (including the ``--`` itself).
  614. Run a Command-Line Tool
  615. =======================
  616. CMake provides builtin command-line tools through the signature
  617. .. code-block:: shell
  618. cmake -E <command> [<options>]
  619. Run ``cmake -E`` or ``cmake -E help`` for a summary of commands.
  620. Available commands are:
  621. ``capabilities``
  622. Report cmake capabilities in JSON format. The output is a JSON object
  623. with the following keys:
  624. ``version``
  625. A JSON object with version information. Keys are:
  626. ``string``
  627. The full version string as displayed by cmake ``--version``.
  628. ``major``
  629. The major version number in integer form.
  630. ``minor``
  631. The minor version number in integer form.
  632. ``patch``
  633. The patch level in integer form.
  634. ``suffix``
  635. The cmake version suffix string.
  636. ``isDirty``
  637. A bool that is set if the cmake build is from a dirty tree.
  638. ``generators``
  639. A list available generators. Each generator is a JSON object with the
  640. following keys:
  641. ``name``
  642. A string containing the name of the generator.
  643. ``toolsetSupport``
  644. ``true`` if the generator supports toolsets and ``false`` otherwise.
  645. ``platformSupport``
  646. ``true`` if the generator supports platforms and ``false`` otherwise.
  647. ``extraGenerators``
  648. A list of strings with all the extra generators compatible with
  649. the generator.
  650. ``fileApi``
  651. Optional member that is present when the :manual:`cmake-file-api(7)`
  652. is available. The value is a JSON object with one member:
  653. ``requests``
  654. A JSON array containing zero or more supported file-api requests.
  655. Each request is a JSON object with members:
  656. ``kind``
  657. Specifies one of the supported :ref:`file-api object kinds`.
  658. ``version``
  659. A JSON array whose elements are each a JSON object containing
  660. ``major`` and ``minor`` members specifying non-negative integer
  661. version components.
  662. ``serverMode``
  663. ``true`` if cmake supports server-mode and ``false`` otherwise.
  664. ``cat <files>...``
  665. Concatenate files and print on the standard output.
  666. ``chdir <dir> <cmd> [<arg>...]``
  667. Change the current working directory and run a command.
  668. ``compare_files [--ignore-eol] <file1> <file2>``
  669. Check if ``<file1>`` is same as ``<file2>``. If files are the same,
  670. then returns ``0``, if not it returns ``1``. In case of invalid
  671. arguments, it returns 2. The ``--ignore-eol`` option
  672. implies line-wise comparison and ignores LF/CRLF differences.
  673. ``copy <file>... <destination>``
  674. Copy files to ``<destination>`` (either file or directory).
  675. If multiple files are specified, the ``<destination>`` must be
  676. directory and it must exist. Wildcards are not supported.
  677. ``copy`` does follow symlinks. That means it does not copy symlinks,
  678. but the files or directories it point to.
  679. ``copy_directory <dir>... <destination>``
  680. Copy content of ``<dir>...`` directories to ``<destination>`` directory.
  681. If ``<destination>`` directory does not exist it will be created.
  682. ``copy_directory`` does follow symlinks.
  683. ``copy_if_different <file>... <destination>``
  684. Copy files to ``<destination>`` (either file or directory) if
  685. they have changed.
  686. If multiple files are specified, the ``<destination>`` must be
  687. directory and it must exist.
  688. ``copy_if_different`` does follow symlinks.
  689. ``create_symlink <old> <new>``
  690. Create a symbolic link ``<new>`` naming ``<old>``.
  691. .. note::
  692. Path to where ``<new>`` symbolic link will be created has to exist beforehand.
  693. ``create_hardlink <old> <new>``
  694. Create a hard link ``<new>`` naming ``<old>``.
  695. .. note::
  696. Path to where ``<new>`` hard link will be created has to exist beforehand.
  697. ``<old>`` has to exist beforehand.
  698. ``echo [<string>...]``
  699. Displays arguments as text.
  700. ``echo_append [<string>...]``
  701. Displays arguments as text but no new line.
  702. ``env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...``
  703. Run command in a modified environment.
  704. ``environment``
  705. Display the current environment variables.
  706. ``false``
  707. Do nothing, with an exit code of 1.
  708. ``make_directory <dir>...``
  709. Create ``<dir>`` directories. If necessary, create parent
  710. directories too. If a directory already exists it will be
  711. silently ignored.
  712. ``md5sum <file>...``
  713. Create MD5 checksum of files in ``md5sum`` compatible format::
  714. 351abe79cd3800b38cdfb25d45015a15 file1.txt
  715. 052f86c15bbde68af55c7f7b340ab639 file2.txt
  716. ``sha1sum <file>...``
  717. Create SHA1 checksum of files in ``sha1sum`` compatible format::
  718. 4bb7932a29e6f73c97bb9272f2bdc393122f86e0 file1.txt
  719. 1df4c8f318665f9a5f2ed38f55adadb7ef9f559c file2.txt
  720. ``sha224sum <file>...``
  721. Create SHA224 checksum of files in ``sha224sum`` compatible format::
  722. b9b9346bc8437bbda630b0b7ddfc5ea9ca157546dbbf4c613192f930 file1.txt
  723. 6dfbe55f4d2edc5fe5c9197bca51ceaaf824e48eba0cc453088aee24 file2.txt
  724. ``sha256sum <file>...``
  725. Create SHA256 checksum of files in ``sha256sum`` compatible format::
  726. 76713b23615d31680afeb0e9efe94d47d3d4229191198bb46d7485f9cb191acc file1.txt
  727. 15b682ead6c12dedb1baf91231e1e89cfc7974b3787c1e2e01b986bffadae0ea file2.txt
  728. ``sha384sum <file>...``
  729. Create SHA384 checksum of files in ``sha384sum`` compatible format::
  730. acc049fedc091a22f5f2ce39a43b9057fd93c910e9afd76a6411a28a8f2b8a12c73d7129e292f94fc0329c309df49434 file1.txt
  731. 668ddeb108710d271ee21c0f3acbd6a7517e2b78f9181c6a2ff3b8943af92b0195dcb7cce48aa3e17893173c0a39e23d file2.txt
  732. ``sha512sum <file>...``
  733. Create SHA512 checksum of files in ``sha512sum`` compatible format::
  734. 2a78d7a6c5328cfb1467c63beac8ff21794213901eaadafd48e7800289afbc08e5fb3e86aa31116c945ee3d7bf2a6194489ec6101051083d1108defc8e1dba89 file1.txt
  735. 7a0b54896fe5e70cca6dd643ad6f672614b189bf26f8153061c4d219474b05dad08c4e729af9f4b009f1a1a280cb625454bf587c690f4617c27e3aebdf3b7a2d file2.txt
  736. ``remove [-f] <file>...``
  737. .. deprecated:: 3.17
  738. Remove the file(s). The planned behaviour was that if any of the
  739. listed files already do not exist, the command returns a non-zero exit code,
  740. but no message is logged. The ``-f`` option changes the behavior to return a
  741. zero exit code (i.e. success) in such situations instead.
  742. ``remove`` does not follow symlinks. That means it remove only symlinks
  743. and not files it point to.
  744. The implementation was buggy and always returned 0. It cannot be fixed without
  745. breaking backwards compatibility. Use ``rm`` instead.
  746. ``remove_directory <dir>...``
  747. .. deprecated:: 3.17
  748. Remove ``<dir>`` directories and their contents. If a directory does
  749. not exist it will be silently ignored. If ``<dir>`` is a symlink to
  750. a directory, just the symlink will be removed.
  751. Use ``rm`` instead.
  752. ``rename <oldname> <newname>``
  753. Rename a file or directory (on one volume). If file with the ``<newname>`` name
  754. already exists, then it will be silently replaced.
  755. ``rm [-rRf] <file> <dir>...``
  756. Remove the files ``<file>`` or directories ``dir``.
  757. Use ``-r`` or ``-R`` to remove directories and their contents recursively.
  758. If any of the listed files/directories do not exist, the command returns a
  759. non-zero exit code, but no message is logged. The ``-f`` option changes
  760. the behavior to return a zero exit code (i.e. success) in such
  761. situations instead.
  762. ``server``
  763. Launch :manual:`cmake-server(7)` mode.
  764. ``sleep <number>...``
  765. Sleep for given number of seconds.
  766. ``tar [cxt][vf][zjJ] file.tar [<options>] [--] [<pathname>...]``
  767. Create or extract a tar or zip archive. Options are:
  768. ``c``
  769. Create a new archive containing the specified files.
  770. If used, the ``<pathname>...`` argument is mandatory.
  771. ``x``
  772. Extract to disk from the archive.
  773. The ``<pathname>...`` argument could be used to extract only selected files
  774. or directories.
  775. When extracting selected files or directories, you must provide their exact
  776. names including the path, as printed by list (``-t``).
  777. ``t``
  778. List archive contents.
  779. The ``<pathname>...`` argument could be used to list only selected files
  780. or directories.
  781. ``v``
  782. Produce verbose output.
  783. ``z``
  784. Compress the resulting archive with gzip.
  785. ``j``
  786. Compress the resulting archive with bzip2.
  787. ``J``
  788. Compress the resulting archive with XZ.
  789. ``--zstd``
  790. Compress the resulting archive with Zstandard.
  791. ``--files-from=<file>``
  792. Read file names from the given file, one per line.
  793. Blank lines are ignored. Lines may not start in ``-``
  794. except for ``--add-file=<name>`` to add files whose
  795. names start in ``-``.
  796. ``--format=<format>``
  797. Specify the format of the archive to be created.
  798. Supported formats are: ``7zip``, ``gnutar``, ``pax``,
  799. ``paxr`` (restricted pax, default), and ``zip``.
  800. ``--mtime=<date>``
  801. Specify modification time recorded in tarball entries.
  802. ``--``
  803. Stop interpreting options and treat all remaining arguments
  804. as file names, even if they start with ``-``.
  805. ``time <command> [<args>...]``
  806. Run command and display elapsed time.
  807. ``touch <file>...``
  808. Creates ``<file>`` if file do not exist.
  809. If ``<file>`` exists, it is changing ``<file>`` access and modification times.
  810. ``touch_nocreate <file>...``
  811. Touch a file if it exists but do not create it. If a file does
  812. not exist it will be silently ignored.
  813. ``true``
  814. Do nothing, with an exit code of 0.
  815. Windows-specific Command-Line Tools
  816. -----------------------------------
  817. The following ``cmake -E`` commands are available only on Windows:
  818. ``delete_regv <key>``
  819. Delete Windows registry value.
  820. ``env_vs8_wince <sdkname>``
  821. Displays a batch file which sets the environment for the provided
  822. Windows CE SDK installed in VS2005.
  823. ``env_vs9_wince <sdkname>``
  824. Displays a batch file which sets the environment for the provided
  825. Windows CE SDK installed in VS2008.
  826. ``write_regv <key> <value>``
  827. Write Windows registry value.
  828. Run the Find-Package Tool
  829. =========================
  830. CMake provides a pkg-config like helper for Makefile-based projects:
  831. .. code-block:: shell
  832. cmake --find-package [<options>]
  833. It searches a package using :command:`find_package()` and prints the
  834. resulting flags to stdout. This can be used instead of pkg-config
  835. to find installed libraries in plain Makefile-based projects or in
  836. autoconf-based projects (via ``share/aclocal/cmake.m4``).
  837. .. note::
  838. This mode is not well-supported due to some technical limitations.
  839. It is kept for compatibility but should not be used in new projects.
  840. View Help
  841. =========
  842. To print selected pages from the CMake documentation, use
  843. .. code-block:: shell
  844. cmake --help[-<topic>]
  845. with one of the following options:
  846. .. include:: OPTIONS_HELP.txt
  847. To view the presets available for a project, use
  848. .. code-block::shell
  849. cmake <source-dir> --list-presets
  850. See Also
  851. ========
  852. .. include:: LINKS.txt