cmake.1.rst 50 KB

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