cmake.1.rst 37 KB

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