cmake.1.rst 40 KB

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