cmake.1.rst 39 KB

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