cmake.1.rst 38 KB

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