cmake.1.rst 36 KB

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