cmake.1.rst 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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=<level>
  179. Set the log ``<level>``.
  180. The :command:`message` command will only output messages of the specified
  181. log level or higher. The valid log levels are ``ERROR``, ``WARNING``,
  182. ``NOTICE``, ``STATUS`` (default), ``VERBOSE``, ``DEBUG``, or ``TRACE``.
  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[=<type>]
  353. Lists the available presets of the specified ``<type>``. Valid values for
  354. ``<type>`` are ``configure``, ``build``, ``test``, or ``all``. If ``<type>``
  355. is omitted, ``configure`` is assumed. The current working directory must
  356. contain CMake preset files.
  357. .. _`Build Tool Mode`:
  358. Build a Project
  359. ===============
  360. CMake provides a command-line signature to build an already-generated
  361. project binary tree:
  362. .. code-block:: shell
  363. cmake --build <dir> [<options>] [-- <build-tool-options>]
  364. cmake --build --preset <preset> [<options>] [-- <build-tool-options>]
  365. This abstracts a native build tool's command-line interface with the
  366. following options:
  367. .. option:: --build <dir>
  368. Project binary directory to be built. This is required (unless a preset
  369. is specified) and must be first.
  370. .. option:: --preset <preset>, --preset=<preset>
  371. Use a build preset to specify build options. The project binary directory
  372. is inferred from the ``configurePreset`` key. The current working directory
  373. must contain CMake preset files.
  374. See :manual:`preset <cmake-presets(7)>` for more details.
  375. .. option:: --list-presets
  376. Lists the available build presets. The current working directory must
  377. contain CMake preset files.
  378. .. option:: -j [<jobs>], --parallel [<jobs>]
  379. The maximum number of concurrent processes to use when building.
  380. If ``<jobs>`` is omitted the native build tool's default number is used.
  381. The :envvar:`CMAKE_BUILD_PARALLEL_LEVEL` environment variable, if set,
  382. specifies a default parallel level when this option is not given.
  383. Some native build tools always build in parallel. The use of ``<jobs>``
  384. value of ``1`` can be used to limit to a single job.
  385. .. option:: -t <tgt>..., --target <tgt>...
  386. Build ``<tgt>`` instead of the default target. Multiple targets may be
  387. given, separated by spaces.
  388. .. option:: --config <cfg>
  389. For multi-configuration tools, choose configuration ``<cfg>``.
  390. .. option:: --clean-first
  391. Build target ``clean`` first, then build.
  392. (To clean only, use :option:`--target clean <cmake --target>`.)
  393. .. option:: --resolve-package-references=<value>
  394. .. versionadded:: 3.23
  395. Resolve remote package references from external package managers (e.g. NuGet)
  396. before build. When ``<value>`` is set to ``on`` (default), packages will be
  397. restored before building a target. When ``<value>`` is set to ``only``, the
  398. packages will be restored, but no build will be performed. When
  399. ``<value>`` is set to ``off``, no packages will be restored.
  400. If the target does not define any package references, this option does nothing.
  401. This setting can be specified in a build preset (using
  402. ``resolvePackageReferences``). The preset setting will be ignored, if this
  403. command line option is specified.
  404. If no command line parameter or preset option are provided, an environment-
  405. specific cache variable will be evaluated to decide, if package restoration
  406. should be performed.
  407. When using the Visual Studio generator, package references are defined
  408. using the :prop_tgt:`VS_PACKAGE_REFERENCES` property. Package references
  409. are restored using NuGet. It can be disabled by setting the
  410. ``CMAKE_VS_NUGET_PACKAGE_RESTORE`` variable to ``OFF``.
  411. .. option:: --use-stderr
  412. Ignored. Behavior is default in CMake >= 3.0.
  413. .. option:: -v, --verbose
  414. Enable verbose output - if supported - including the build commands to be
  415. executed.
  416. This option can be omitted if :envvar:`VERBOSE` environment variable or
  417. :variable:`CMAKE_VERBOSE_MAKEFILE` cached variable is set.
  418. .. option:: --
  419. Pass remaining options to the native tool.
  420. Run :option:`cmake --build` with no options for quick help.
  421. Install a Project
  422. =================
  423. CMake provides a command-line signature to install an already-generated
  424. project binary tree:
  425. .. code-block:: shell
  426. cmake --install <dir> [<options>]
  427. This may be used after building a project to run installation without
  428. using the generated build system or the native build tool.
  429. The options are:
  430. .. option:: --install <dir>
  431. Project binary directory to install. This is required and must be first.
  432. .. option:: --config <cfg>
  433. For multi-configuration generators, choose configuration ``<cfg>``.
  434. .. option:: --component <comp>
  435. Component-based install. Only install component ``<comp>``.
  436. .. option:: --default-directory-permissions <permissions>
  437. Default directory install permissions. Permissions in format ``<u=rwx,g=rx,o=rx>``.
  438. .. option:: --prefix <prefix>
  439. Override the installation prefix, :variable:`CMAKE_INSTALL_PREFIX`.
  440. .. option:: --strip
  441. Strip before installing.
  442. .. option:: -v, --verbose
  443. Enable verbose output.
  444. This option can be omitted if :envvar:`VERBOSE` environment variable is set.
  445. Run :option:`cmake --install` with no options for quick help.
  446. Open a Project
  447. ==============
  448. .. code-block:: shell
  449. cmake --open <dir>
  450. Open the generated project in the associated application. This is only
  451. supported by some generators.
  452. .. _`Script Processing Mode`:
  453. Run a Script
  454. ============
  455. .. program:: cmake_P
  456. .. code-block:: shell
  457. cmake [-D <var>=<value>]... -P <cmake-script-file> [-- <unparsed-options>...]
  458. .. option:: -D <var>=<value>
  459. Define a variable for script mode.
  460. .. option:: -P <cmake-script-file>
  461. Process the given cmake file as a script written in the CMake
  462. language. No configure or generate step is performed and the cache
  463. is not modified. If variables are defined using ``-D``, this must be
  464. done before the ``-P`` argument.
  465. Any options after ``--`` are not parsed by CMake, but they are still included
  466. in the set of :variable:`CMAKE_ARGV<n> <CMAKE_ARGV0>` variables passed to the
  467. script (including the ``--`` itself).
  468. .. _`Run a Command-Line Tool`:
  469. Run a Command-Line Tool
  470. =======================
  471. .. program:: cmake_E
  472. CMake provides builtin command-line tools through the signature
  473. .. code-block:: shell
  474. cmake -E <command> [<options>]
  475. .. option:: -E [help]
  476. Run ``cmake -E`` or ``cmake -E help`` for a summary of commands.
  477. Available commands are:
  478. .. option:: capabilities
  479. .. versionadded:: 3.7
  480. Report cmake capabilities in JSON format. The output is a JSON object
  481. with the following keys:
  482. ``version``
  483. A JSON object with version information. Keys are:
  484. ``string``
  485. The full version string as displayed by cmake :option:`--version <cmake --version>`.
  486. ``major``
  487. The major version number in integer form.
  488. ``minor``
  489. The minor version number in integer form.
  490. ``patch``
  491. The patch level in integer form.
  492. ``suffix``
  493. The cmake version suffix string.
  494. ``isDirty``
  495. A bool that is set if the cmake build is from a dirty tree.
  496. ``generators``
  497. A list available generators. Each generator is a JSON object with the
  498. following keys:
  499. ``name``
  500. A string containing the name of the generator.
  501. ``toolsetSupport``
  502. ``true`` if the generator supports toolsets and ``false`` otherwise.
  503. ``platformSupport``
  504. ``true`` if the generator supports platforms and ``false`` otherwise.
  505. ``supportedPlatforms``
  506. .. versionadded:: 3.21
  507. Optional member that may be present when the generator supports
  508. platform specification via :variable:`CMAKE_GENERATOR_PLATFORM`
  509. (:option:`-A ... <cmake -A>`). The value is a list of platforms known to
  510. be supported.
  511. ``extraGenerators``
  512. A list of strings with all the extra generators compatible with
  513. the generator.
  514. ``fileApi``
  515. Optional member that is present when the :manual:`cmake-file-api(7)`
  516. is available. The value is a JSON object with one member:
  517. ``requests``
  518. A JSON array containing zero or more supported file-api requests.
  519. Each request is a JSON object with members:
  520. ``kind``
  521. Specifies one of the supported :ref:`file-api object kinds`.
  522. ``version``
  523. A JSON array whose elements are each a JSON object containing
  524. ``major`` and ``minor`` members specifying non-negative integer
  525. version components.
  526. ``serverMode``
  527. ``true`` if cmake supports server-mode and ``false`` otherwise.
  528. Always false since CMake 3.20.
  529. ``tls``
  530. .. versionadded:: 3.25
  531. ``true`` if TLS support is enabled and ``false`` otherwise.
  532. .. option:: cat [--] <files>...
  533. .. versionadded:: 3.18
  534. Concatenate files and print on the standard output.
  535. .. versionadded:: 3.24
  536. Added support for the double dash argument ``--``. This basic implementation
  537. of ``cat`` does not support any options, so using a option starting with
  538. ``-`` will result in an error. Use ``--`` to indicate the end of options, in
  539. case a file starts with ``-``.
  540. .. option:: chdir <dir> <cmd> [<arg>...]
  541. Change the current working directory and run a command.
  542. .. option:: compare_files [--ignore-eol] <file1> <file2>
  543. Check if ``<file1>`` is same as ``<file2>``. If files are the same,
  544. then returns ``0``, if not it returns ``1``. In case of invalid
  545. arguments, it returns 2.
  546. .. versionadded:: 3.14
  547. The ``--ignore-eol`` option implies line-wise comparison and ignores
  548. LF/CRLF differences.
  549. .. option:: copy <file>... <destination>
  550. Copy files to ``<destination>`` (either file or directory).
  551. If multiple files are specified, the ``<destination>`` must be
  552. directory and it must exist. Wildcards are not supported.
  553. ``copy`` does follow symlinks. That means it does not copy symlinks,
  554. but the files or directories it point to.
  555. .. versionadded:: 3.5
  556. Support for multiple input files.
  557. .. option:: copy_directory <dir>... <destination>
  558. Copy content of ``<dir>...`` directories to ``<destination>`` directory.
  559. If ``<destination>`` directory does not exist it will be created.
  560. ``copy_directory`` does follow symlinks.
  561. .. versionadded:: 3.5
  562. Support for multiple input directories.
  563. .. versionadded:: 3.15
  564. The command now fails when the source directory does not exist.
  565. Previously it succeeded by creating an empty destination directory.
  566. .. option:: copy_if_different <file>... <destination>
  567. Copy files to ``<destination>`` (either file or directory) if
  568. they have changed.
  569. If multiple files are specified, the ``<destination>`` must be
  570. directory and it must exist.
  571. ``copy_if_different`` does follow symlinks.
  572. .. versionadded:: 3.5
  573. Support for multiple input files.
  574. .. option:: create_symlink <old> <new>
  575. Create a symbolic link ``<new>`` naming ``<old>``.
  576. .. versionadded:: 3.13
  577. Support for creating symlinks on Windows.
  578. .. note::
  579. Path to where ``<new>`` symbolic link will be created has to exist beforehand.
  580. .. option:: create_hardlink <old> <new>
  581. .. versionadded:: 3.19
  582. Create a hard link ``<new>`` naming ``<old>``.
  583. .. note::
  584. Path to where ``<new>`` hard link will be created has to exist beforehand.
  585. ``<old>`` has to exist beforehand.
  586. .. option:: echo [<string>...]
  587. Displays arguments as text.
  588. .. option:: echo_append [<string>...]
  589. Displays arguments as text but no new line.
  590. .. option:: env [<options>] [--] <command> [<arg>...]
  591. .. versionadded:: 3.1
  592. Run command in a modified environment. Options are:
  593. ``NAME=VALUE``
  594. Replaces the current value of ``NAME`` with ``VALUE``.
  595. ``--unset=NAME``
  596. Unsets the current value of ``NAME``.
  597. ``--modify ENVIRONMENT_MODIFICATION``
  598. .. versionadded:: 3.25
  599. Apply a single :prop_test:`ENVIRONMENT_MODIFICATION` operation to the
  600. modified environment.
  601. The ``NAME=VALUE`` and ``--unset=NAME`` options are equivalent to
  602. ``--modify NAME=set:VALUE`` and ``--modify NAME=unset:``, respectively.
  603. Note that ``--modify NAME=reset:`` resets ``NAME`` to the value it had
  604. when ``cmake`` launched (or unsets it), not to the most recent
  605. ``NAME=VALUE`` option.
  606. .. versionadded:: 3.24
  607. Added support for the double dash argument ``--``. Use ``--`` to stop
  608. interpreting options/environment variables and treat the next argument as
  609. the command, even if it start with ``-`` or contains a ``=``.
  610. .. option:: environment
  611. Display the current environment variables.
  612. .. option:: false
  613. .. versionadded:: 3.16
  614. Do nothing, with an exit code of 1.
  615. .. option:: make_directory <dir>...
  616. Create ``<dir>`` directories. If necessary, create parent
  617. directories too. If a directory already exists it will be
  618. silently ignored.
  619. .. versionadded:: 3.5
  620. Support for multiple input directories.
  621. .. option:: md5sum <file>...
  622. Create MD5 checksum of files in ``md5sum`` compatible format::
  623. 351abe79cd3800b38cdfb25d45015a15 file1.txt
  624. 052f86c15bbde68af55c7f7b340ab639 file2.txt
  625. .. option:: sha1sum <file>...
  626. .. versionadded:: 3.10
  627. Create SHA1 checksum of files in ``sha1sum`` compatible format::
  628. 4bb7932a29e6f73c97bb9272f2bdc393122f86e0 file1.txt
  629. 1df4c8f318665f9a5f2ed38f55adadb7ef9f559c file2.txt
  630. .. option:: sha224sum <file>...
  631. .. versionadded:: 3.10
  632. Create SHA224 checksum of files in ``sha224sum`` compatible format::
  633. b9b9346bc8437bbda630b0b7ddfc5ea9ca157546dbbf4c613192f930 file1.txt
  634. 6dfbe55f4d2edc5fe5c9197bca51ceaaf824e48eba0cc453088aee24 file2.txt
  635. .. option:: sha256sum <file>...
  636. .. versionadded:: 3.10
  637. Create SHA256 checksum of files in ``sha256sum`` compatible format::
  638. 76713b23615d31680afeb0e9efe94d47d3d4229191198bb46d7485f9cb191acc file1.txt
  639. 15b682ead6c12dedb1baf91231e1e89cfc7974b3787c1e2e01b986bffadae0ea file2.txt
  640. .. option:: sha384sum <file>...
  641. .. versionadded:: 3.10
  642. Create SHA384 checksum of files in ``sha384sum`` compatible format::
  643. acc049fedc091a22f5f2ce39a43b9057fd93c910e9afd76a6411a28a8f2b8a12c73d7129e292f94fc0329c309df49434 file1.txt
  644. 668ddeb108710d271ee21c0f3acbd6a7517e2b78f9181c6a2ff3b8943af92b0195dcb7cce48aa3e17893173c0a39e23d file2.txt
  645. .. option:: sha512sum <file>...
  646. .. versionadded:: 3.10
  647. Create SHA512 checksum of files in ``sha512sum`` compatible format::
  648. 2a78d7a6c5328cfb1467c63beac8ff21794213901eaadafd48e7800289afbc08e5fb3e86aa31116c945ee3d7bf2a6194489ec6101051083d1108defc8e1dba89 file1.txt
  649. 7a0b54896fe5e70cca6dd643ad6f672614b189bf26f8153061c4d219474b05dad08c4e729af9f4b009f1a1a280cb625454bf587c690f4617c27e3aebdf3b7a2d file2.txt
  650. .. option:: remove [-f] <file>...
  651. .. deprecated:: 3.17
  652. Remove the file(s). The planned behavior was that if any of the
  653. listed files already do not exist, the command returns a non-zero exit code,
  654. but no message is logged. The ``-f`` option changes the behavior to return a
  655. zero exit code (i.e. success) in such situations instead.
  656. ``remove`` does not follow symlinks. That means it remove only symlinks
  657. and not files it point to.
  658. The implementation was buggy and always returned 0. It cannot be fixed without
  659. breaking backwards compatibility. Use ``rm`` instead.
  660. .. option:: remove_directory <dir>...
  661. .. deprecated:: 3.17
  662. Remove ``<dir>`` directories and their contents. If a directory does
  663. not exist it will be silently ignored.
  664. Use ``rm`` instead.
  665. .. versionadded:: 3.15
  666. Support for multiple directories.
  667. .. versionadded:: 3.16
  668. If ``<dir>`` is a symlink to a directory, just the symlink will be removed.
  669. .. option:: rename <oldname> <newname>
  670. Rename a file or directory (on one volume). If file with the ``<newname>`` name
  671. already exists, then it will be silently replaced.
  672. .. option:: rm [-rRf] [--] <file|dir>...
  673. .. versionadded:: 3.17
  674. Remove the files ``<file>`` or directories ``<dir>``.
  675. Use ``-r`` or ``-R`` to remove directories and their contents recursively.
  676. If any of the listed files/directories do not exist, the command returns a
  677. non-zero exit code, but no message is logged. The ``-f`` option changes
  678. the behavior to return a zero exit code (i.e. success) in such
  679. situations instead. Use ``--`` to stop interpreting options and treat all
  680. remaining arguments as paths, even if they start with ``-``.
  681. .. option:: server
  682. Launch :manual:`cmake-server(7)` mode.
  683. .. option:: sleep <number>...
  684. .. versionadded:: 3.0
  685. Sleep for given number of seconds.
  686. .. option:: tar [cxt][vf][zjJ] file.tar [<options>] [--] [<pathname>...]
  687. Create or extract a tar or zip archive. Options are:
  688. ``c``
  689. Create a new archive containing the specified files.
  690. If used, the ``<pathname>...`` argument is mandatory.
  691. ``x``
  692. Extract to disk from the archive.
  693. .. versionadded:: 3.15
  694. The ``<pathname>...`` argument could be used to extract only selected files
  695. or directories.
  696. When extracting selected files or directories, you must provide their exact
  697. names including the path, as printed by list (``-t``).
  698. ``t``
  699. List archive contents.
  700. .. versionadded:: 3.15
  701. The ``<pathname>...`` argument could be used to list only selected files
  702. or directories.
  703. ``v``
  704. Produce verbose output.
  705. ``z``
  706. Compress the resulting archive with gzip.
  707. ``j``
  708. Compress the resulting archive with bzip2.
  709. ``J``
  710. .. versionadded:: 3.1
  711. Compress the resulting archive with XZ.
  712. ``--zstd``
  713. .. versionadded:: 3.15
  714. Compress the resulting archive with Zstandard.
  715. ``--files-from=<file>``
  716. .. versionadded:: 3.1
  717. Read file names from the given file, one per line.
  718. Blank lines are ignored. Lines may not start in ``-``
  719. except for ``--add-file=<name>`` to add files whose
  720. names start in ``-``.
  721. ``--format=<format>``
  722. .. versionadded:: 3.3
  723. Specify the format of the archive to be created.
  724. Supported formats are: ``7zip``, ``gnutar``, ``pax``,
  725. ``paxr`` (restricted pax, default), and ``zip``.
  726. ``--mtime=<date>``
  727. .. versionadded:: 3.1
  728. Specify modification time recorded in tarball entries.
  729. ``--touch``
  730. .. versionadded:: 3.24
  731. Use current local timestamp instead of extracting file timestamps
  732. from the archive.
  733. ``--``
  734. .. versionadded:: 3.1
  735. Stop interpreting options and treat all remaining arguments
  736. as file names, even if they start with ``-``.
  737. .. versionadded:: 3.1
  738. LZMA (7zip) support.
  739. .. versionadded:: 3.15
  740. The command now continues adding files to an archive even if some of the
  741. files are not readable. This behavior is more consistent with the classic
  742. ``tar`` tool. The command now also parses all flags, and if an invalid flag
  743. was provided, a warning is issued.
  744. .. option:: time <command> [<args>...]
  745. Run command and display elapsed time.
  746. .. versionadded:: 3.5
  747. The command now properly passes arguments with spaces or special characters
  748. through to the child process. This may break scripts that worked around the
  749. bug with their own extra quoting or escaping.
  750. .. option:: touch <file>...
  751. Creates ``<file>`` if file do not exist.
  752. If ``<file>`` exists, it is changing ``<file>`` access and modification times.
  753. .. option:: touch_nocreate <file>...
  754. Touch a file if it exists but do not create it. If a file does
  755. not exist it will be silently ignored.
  756. .. option:: true
  757. .. versionadded:: 3.16
  758. Do nothing, with an exit code of 0.
  759. Windows-specific Command-Line Tools
  760. -----------------------------------
  761. The following ``cmake -E`` commands are available only on Windows:
  762. .. option:: delete_regv <key>
  763. Delete Windows registry value.
  764. .. option:: env_vs8_wince <sdkname>
  765. .. versionadded:: 3.2
  766. Displays a batch file which sets the environment for the provided
  767. Windows CE SDK installed in VS2005.
  768. .. option:: env_vs9_wince <sdkname>
  769. .. versionadded:: 3.2
  770. Displays a batch file which sets the environment for the provided
  771. Windows CE SDK installed in VS2008.
  772. .. option:: write_regv <key> <value>
  773. Write Windows registry value.
  774. Run the Find-Package Tool
  775. =========================
  776. CMake provides a pkg-config like helper for Makefile-based projects:
  777. .. code-block:: shell
  778. cmake --find-package [<options>]
  779. It searches a package using :command:`find_package()` and prints the
  780. resulting flags to stdout. This can be used instead of pkg-config
  781. to find installed libraries in plain Makefile-based projects or in
  782. autoconf-based projects (via ``share/aclocal/cmake.m4``).
  783. .. note::
  784. This mode is not well-supported due to some technical limitations.
  785. It is kept for compatibility but should not be used in new projects.
  786. View Help
  787. =========
  788. To print selected pages from the CMake documentation, use
  789. .. code-block:: shell
  790. cmake --help[-<topic>]
  791. with one of the following options:
  792. .. program:: cmake
  793. .. include:: OPTIONS_HELP.txt
  794. To view the presets available for a project, use
  795. .. code-block:: shell
  796. cmake <source-dir> --list-presets
  797. .. _`CMake Exit Code`:
  798. Return Value (Exit Code)
  799. ========================
  800. Upon regular termination, the ``cmake`` executable returns the exit code ``0``.
  801. If termination is caused by the command :command:`message(FATAL_ERROR)`,
  802. or another error condition, then a non-zero exit code is returned.
  803. See Also
  804. ========
  805. .. include:: LINKS.txt