cmake.1.rst 37 KB

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