You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1012 lines
32 KiB

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