cmake.1.rst 43 KB

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