cmake.1.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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. ==============================
  83. Run CMake with one of the following command signatures to specify the
  84. source and build trees and generate a buildsystem:
  85. ``cmake [<options>] <path-to-source>``
  86. Uses the current working directory as the build tree, and
  87. ``<path-to-source>`` as the source tree. The specified path may
  88. be absolute or relative to the current working directory.
  89. The source tree must contain a ``CMakeLists.txt`` file and must
  90. *not* contain a ``CMakeCache.txt`` file because the latter
  91. identifies an existing build tree. For example:
  92. .. code-block:: console
  93. $ mkdir build ; cd build
  94. $ cmake ../src
  95. ``cmake [<options>] <path-to-existing-build>``
  96. Uses ``<path-to-existing-build>`` as the build tree, and loads the
  97. path to the source tree from its ``CMakeCache.txt`` file, which must
  98. have already been generated by a previous run of CMake. The specified
  99. path may be absolute or relative to the current working directory.
  100. For example:
  101. .. code-block:: console
  102. $ cd build
  103. $ cmake .
  104. ``cmake [<options>] -S <path-to-source> -B <path-to-build>``
  105. Uses ``<path-to-build>`` as the build tree and ``<path-to-source>``
  106. as the source tree. The specified paths may be absolute or relative
  107. to the current working directory. The source tree must contain a
  108. ``CMakeLists.txt`` file. The build tree will be created automatically
  109. if it does not already exist. For example:
  110. .. code-block:: console
  111. $ cmake -S src -B build
  112. In all cases the ``<options>`` may be zero or more of the `Options`_ below.
  113. After generating a buildsystem one may use the corresponding native
  114. build tool to build the project. For example, after using the
  115. :generator:`Unix Makefiles` generator one may run ``make`` directly:
  116. .. code-block:: console
  117. $ make
  118. $ make install
  119. Alternatively, one may use **cmake** to `Build a Project`_ by
  120. automatically choosing and invoking the appropriate native build tool.
  121. .. _`CMake Options`:
  122. Options
  123. -------
  124. .. include:: OPTIONS_BUILD.txt
  125. ``-L[A][H]``
  126. List non-advanced cached variables.
  127. List ``CACHE`` variables will run CMake and list all the variables from
  128. the CMake ``CACHE`` that are not marked as ``INTERNAL`` or :prop_cache:`ADVANCED`.
  129. This will effectively display current CMake settings, which can then be
  130. changed with ``-D`` option. Changing some of the variables may result
  131. in more variables being created. If ``A`` is specified, then it will
  132. display also advanced variables. If ``H`` is specified, it will also
  133. display help for each variable.
  134. ``-N``
  135. View mode only.
  136. Only load the cache. Do not actually run configure and generate
  137. steps.
  138. ``--graphviz=[file]``
  139. Generate graphviz of dependencies, see :module:`CMakeGraphVizOptions` for more.
  140. Generate a graphviz input file that will contain all the library and
  141. executable dependencies in the project. See the documentation for
  142. :module:`CMakeGraphVizOptions` for more details.
  143. ``--system-information [file]``
  144. Dump information about this system.
  145. Dump a wide range of information about the current system. If run
  146. from the top of a binary tree for a CMake project it will dump
  147. additional information such as the cache, log files etc.
  148. ``--loglevel=<ERROR|WARNING|NOTICE|STATUS|VERBOSE|DEBUG|TRACE>``
  149. Set the log level.
  150. The :command:`message` command will only output messages of the specified
  151. log level or higher. The default log level is ``STATUS``.
  152. ``--debug-trycompile``
  153. Do not delete the :command:`try_compile` build tree.
  154. Only useful on one :command:`try_compile` at a time.
  155. Do not delete the files and directories created for :command:`try_compile`
  156. calls. This is useful in debugging failed try_compiles. It may
  157. however change the results of the try-compiles as old junk from a
  158. previous try-compile may cause a different test to either pass or
  159. fail incorrectly. This option is best used for one try-compile at a
  160. time, and only when debugging.
  161. ``--debug-output``
  162. Put cmake in a debug mode.
  163. Print extra information during the cmake run like stack traces with
  164. :command:`message(SEND_ERROR)` calls.
  165. ``--trace``
  166. Put cmake in trace mode.
  167. Print a trace of all calls made and from where.
  168. ``--trace-expand``
  169. Put cmake in trace mode.
  170. Like ``--trace``, but with variables expanded.
  171. ``--trace-source=<file>``
  172. Put cmake in trace mode, but output only lines of a specified file.
  173. Multiple options are allowed.
  174. ``--trace-redirect=<file>``
  175. Put cmake in trace mode and redirect trace output to a file instead of stderr.
  176. ``--warn-uninitialized``
  177. Warn about uninitialized values.
  178. Print a warning when an uninitialized variable is used.
  179. ``--warn-unused-vars``
  180. Warn about unused variables.
  181. Find variables that are declared or set, but not used.
  182. ``--no-warn-unused-cli``
  183. Don't warn about command line options.
  184. Don't find variables that are declared on the command line, but not
  185. used.
  186. ``--check-system-vars``
  187. Find problems with variable usage in system files.
  188. Normally, unused and uninitialized variables are searched for only
  189. in :variable:`CMAKE_SOURCE_DIR` and :variable:`CMAKE_BINARY_DIR`.
  190. This flag tells CMake to warn about other files as well.
  191. .. _`Build Tool Mode`:
  192. Build a Project
  193. ===============
  194. CMake provides a command-line signature to build an already-generated
  195. project binary tree:
  196. .. code-block:: shell
  197. cmake --build <dir> [<options>] [-- <build-tool-options>]
  198. This abstracts a native build tool's command-line interface with the
  199. following options:
  200. ``--build <dir>``
  201. Project binary directory to be built. This is required and must be first.
  202. ``--parallel [<jobs>], -j [<jobs>]``
  203. The maximum number of concurrent processes to use when building.
  204. If ``<jobs>`` is omitted the native build tool's default number is used.
  205. The :envvar:`CMAKE_BUILD_PARALLEL_LEVEL` environment variable, if set,
  206. specifies a default parallel level when this option is not given.
  207. Some native build tools always build in parallel. The use of ``<jobs>``
  208. value of ``1`` can be used to limit to a single job.
  209. ``--target <tgt>..., -t <tgt>...``
  210. Build ``<tgt>`` instead of the default target. Multiple targets may be
  211. given, separated by spaces.
  212. ``--config <cfg>``
  213. For multi-configuration tools, choose configuration ``<cfg>``.
  214. ``--clean-first``
  215. Build target ``clean`` first, then build.
  216. (To clean only, use ``--target clean``.)
  217. ``--use-stderr``
  218. Ignored. Behavior is default in CMake >= 3.0.
  219. ``--verbose, -v``
  220. Enable verbose output - if supported - including the build commands to be
  221. executed.
  222. This option can be omitted if :envvar:`VERBOSE` environment variable or
  223. :variable:`CMAKE_VERBOSE_MAKEFILE` cached variable is set.
  224. ``--``
  225. Pass remaining options to the native tool.
  226. Run ``cmake --build`` with no options for quick help.
  227. Install a Project
  228. =================
  229. CMake provides a command-line signature to install an already-generated
  230. project binary tree:
  231. .. code-block:: shell
  232. cmake --install <dir> [<options>]
  233. This may be used after building a project to run installation without
  234. using the generated build system or the native build tool.
  235. The options are:
  236. ``--install <dir>``
  237. Project binary directory to install. This is required and must be first.
  238. ``--config <cfg>``
  239. For multi-configuration generators, choose configuration ``<cfg>``.
  240. ``--component <comp>``
  241. Component-based install. Only install component ``<comp>``.
  242. ``--prefix <prefix>``
  243. Override the installation prefix, :variable:`CMAKE_INSTALL_PREFIX`.
  244. ``--strip``
  245. Strip before installing.
  246. ``-v, --verbose``
  247. Enable verbose output.
  248. This option can be omitted if :envvar:`VERBOSE` environment variable is set.
  249. Run ``cmake --install`` with no options for quick help.
  250. Open a Project
  251. ==============
  252. .. code-block:: shell
  253. cmake --open <dir>
  254. Open the generated project in the associated application. This is only
  255. supported by some generators.
  256. .. _`Script Processing Mode`:
  257. Run a Script
  258. ============
  259. .. code-block:: shell
  260. cmake [{-D <var>=<value>}...] -P <cmake-script-file>
  261. Process the given cmake file as a script written in the CMake
  262. language. No configure or generate step is performed and the cache
  263. is not modified. If variables are defined using ``-D``, this must be
  264. done before the ``-P`` argument.
  265. Run a Command-Line Tool
  266. =======================
  267. CMake provides builtin command-line tools through the signature
  268. .. code-block:: shell
  269. cmake -E <command> [<options>]
  270. Run ``cmake -E`` or ``cmake -E help`` for a summary of commands.
  271. Available commands are:
  272. ``capabilities``
  273. Report cmake capabilities in JSON format. The output is a JSON object
  274. with the following keys:
  275. ``version``
  276. A JSON object with version information. Keys are:
  277. ``string``
  278. The full version string as displayed by cmake ``--version``.
  279. ``major``
  280. The major version number in integer form.
  281. ``minor``
  282. The minor version number in integer form.
  283. ``patch``
  284. The patch level in integer form.
  285. ``suffix``
  286. The cmake version suffix string.
  287. ``isDirty``
  288. A bool that is set if the cmake build is from a dirty tree.
  289. ``generators``
  290. A list available generators. Each generator is a JSON object with the
  291. following keys:
  292. ``name``
  293. A string containing the name of the generator.
  294. ``toolsetSupport``
  295. ``true`` if the generator supports toolsets and ``false`` otherwise.
  296. ``platformSupport``
  297. ``true`` if the generator supports platforms and ``false`` otherwise.
  298. ``extraGenerators``
  299. A list of strings with all the extra generators compatible with
  300. the generator.
  301. ``fileApi``
  302. Optional member that is present when the :manual:`cmake-file-api(7)`
  303. is available. The value is a JSON object with one member:
  304. ``requests``
  305. A JSON array containing zero or more supported file-api requests.
  306. Each request is a JSON object with members:
  307. ``kind``
  308. Specifies one of the supported :ref:`file-api object kinds`.
  309. ``version``
  310. A JSON array whose elements are each a JSON object containing
  311. ``major`` and ``minor`` members specifying non-negative integer
  312. version components.
  313. ``serverMode``
  314. ``true`` if cmake supports server-mode and ``false`` otherwise.
  315. ``chdir <dir> <cmd> [<arg>...]``
  316. Change the current working directory and run a command.
  317. ``compare_files [--ignore-eol] <file1> <file2>``
  318. Check if ``<file1>`` is same as ``<file2>``. If files are the same,
  319. then returns ``0``, if not it returns ``1``. The ``--ignore-eol`` option
  320. implies line-wise comparison and ignores LF/CRLF differences.
  321. ``copy <file>... <destination>``
  322. Copy files to ``<destination>`` (either file or directory).
  323. If multiple files are specified, the ``<destination>`` must be
  324. directory and it must exist. Wildcards are not supported.
  325. ``copy`` does follow symlinks. That means it does not copy symlinks,
  326. but the files or directories it point to.
  327. ``copy_directory <dir>... <destination>``
  328. Copy directories to ``<destination>`` directory.
  329. If ``<destination>`` directory does not exist it will be created.
  330. ``copy_directory`` does follow symlinks.
  331. ``copy_if_different <file>... <destination>``
  332. Copy files to ``<destination>`` (either file or directory) if
  333. they have changed.
  334. If multiple files are specified, the ``<destination>`` must be
  335. directory and it must exist.
  336. ``copy_if_different`` does follow symlinks.
  337. ``echo [<string>...]``
  338. Displays arguments as text.
  339. ``echo_append [<string>...]``
  340. Displays arguments as text but no new line.
  341. ``env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...``
  342. Run command in a modified environment.
  343. ``environment``
  344. Display the current environment variables.
  345. ``make_directory <dir>...``
  346. Create ``<dir>`` directories. If necessary, create parent
  347. directories too. If a directory already exists it will be
  348. silently ignored.
  349. ``md5sum <file>...``
  350. Create MD5 checksum of files in ``md5sum`` compatible format::
  351. 351abe79cd3800b38cdfb25d45015a15 file1.txt
  352. 052f86c15bbde68af55c7f7b340ab639 file2.txt
  353. ``sha1sum <file>...``
  354. Create SHA1 checksum of files in ``sha1sum`` compatible format::
  355. 4bb7932a29e6f73c97bb9272f2bdc393122f86e0 file1.txt
  356. 1df4c8f318665f9a5f2ed38f55adadb7ef9f559c file2.txt
  357. ``sha224sum <file>...``
  358. Create SHA224 checksum of files in ``sha224sum`` compatible format::
  359. b9b9346bc8437bbda630b0b7ddfc5ea9ca157546dbbf4c613192f930 file1.txt
  360. 6dfbe55f4d2edc5fe5c9197bca51ceaaf824e48eba0cc453088aee24 file2.txt
  361. ``sha256sum <file>...``
  362. Create SHA256 checksum of files in ``sha256sum`` compatible format::
  363. 76713b23615d31680afeb0e9efe94d47d3d4229191198bb46d7485f9cb191acc file1.txt
  364. 15b682ead6c12dedb1baf91231e1e89cfc7974b3787c1e2e01b986bffadae0ea file2.txt
  365. ``sha384sum <file>...``
  366. Create SHA384 checksum of files in ``sha384sum`` compatible format::
  367. acc049fedc091a22f5f2ce39a43b9057fd93c910e9afd76a6411a28a8f2b8a12c73d7129e292f94fc0329c309df49434 file1.txt
  368. 668ddeb108710d271ee21c0f3acbd6a7517e2b78f9181c6a2ff3b8943af92b0195dcb7cce48aa3e17893173c0a39e23d file2.txt
  369. ``sha512sum <file>...``
  370. Create SHA512 checksum of files in ``sha512sum`` compatible format::
  371. 2a78d7a6c5328cfb1467c63beac8ff21794213901eaadafd48e7800289afbc08e5fb3e86aa31116c945ee3d7bf2a6194489ec6101051083d1108defc8e1dba89 file1.txt
  372. 7a0b54896fe5e70cca6dd643ad6f672614b189bf26f8153061c4d219474b05dad08c4e729af9f4b009f1a1a280cb625454bf587c690f4617c27e3aebdf3b7a2d file2.txt
  373. ``remove [-f] <file>...``
  374. Remove the file(s). If any of the listed files already do not
  375. exist, the command returns a non-zero exit code, but no message
  376. is logged. The ``-f`` option changes the behavior to return a
  377. zero exit code (i.e. success) in such situations instead.
  378. ``remove`` does not follow symlinks. That means it remove only symlinks
  379. and not files it point to.
  380. ``remove_directory <dir>...``
  381. Remove ``<dir>`` directories and their contents. If a directory does
  382. not exist it will be silently ignored.
  383. ``rename <oldname> <newname>``
  384. Rename a file or directory (on one volume). If file with the ``<newname>`` name
  385. already exists, then it will be silently replaced.
  386. ``server``
  387. Launch :manual:`cmake-server(7)` mode.
  388. ``sleep <number>...``
  389. Sleep for given number of seconds.
  390. ``tar [cxt][vf][zjJ] file.tar [<options>] [--] [<pathname>...]``
  391. Create or extract a tar or zip archive. Options are:
  392. ``c``
  393. Create a new archive containing the specified files.
  394. If used, the ``<pathname>...`` argument is mandatory.
  395. ``x``
  396. Extract to disk from the archive.
  397. The ``<pathname>...`` argument could be used to extract only selected files
  398. or directories.
  399. When extracting selected files or directories, you must provide their exact
  400. names including the path, as printed by list (``-t``).
  401. ``t``
  402. List archive contents.
  403. The ``<pathname>...`` argument could be used to list only selected files
  404. or directories.
  405. ``v``
  406. Produce verbose output.
  407. ``z``
  408. Compress the resulting archive with gzip.
  409. ``j``
  410. Compress the resulting archive with bzip2.
  411. ``J``
  412. Compress the resulting archive with XZ.
  413. ``--zstd``
  414. Compress the resulting archive with Zstandard.
  415. ``--files-from=<file>``
  416. Read file names from the given file, one per line.
  417. Blank lines are ignored. Lines may not start in ``-``
  418. except for ``--add-file=<name>`` to add files whose
  419. names start in ``-``.
  420. ``--format=<format>``
  421. Specify the format of the archive to be created.
  422. Supported formats are: ``7zip``, ``gnutar``, ``pax``,
  423. ``paxr`` (restricted pax, default), and ``zip``.
  424. ``--mtime=<date>``
  425. Specify modification time recorded in tarball entries.
  426. ``--``
  427. Stop interpreting options and treat all remaining arguments
  428. as file names, even if they start with ``-``.
  429. ``time <command> [<args>...]``
  430. Run command and display elapsed time.
  431. ``touch <file>...``
  432. Creates ``<file>`` if file do not exist.
  433. If ``<file>`` exists, it is changing ``<file>`` access and modification times.
  434. ``touch_nocreate <file>...``
  435. Touch a file if it exists but do not create it. If a file does
  436. not exist it will be silently ignored.
  437. ``create_symlink <old> <new>``
  438. Create a symbolic link ``<new>`` naming ``<old>``.
  439. .. note::
  440. Path to where ``<new>`` symbolic link will be created has to exist beforehand.
  441. ``true``
  442. Do nothing, with an exit code of 0.
  443. ``false``
  444. Do nothing, with an exit code of 1.
  445. Windows-specific Command-Line Tools
  446. -----------------------------------
  447. The following ``cmake -E`` commands are available only on Windows:
  448. ``delete_regv <key>``
  449. Delete Windows registry value.
  450. ``env_vs8_wince <sdkname>``
  451. Displays a batch file which sets the environment for the provided
  452. Windows CE SDK installed in VS2005.
  453. ``env_vs9_wince <sdkname>``
  454. Displays a batch file which sets the environment for the provided
  455. Windows CE SDK installed in VS2008.
  456. ``write_regv <key> <value>``
  457. Write Windows registry value.
  458. Run the Find-Package Tool
  459. =========================
  460. CMake provides a pkg-config like helper for Makefile-based projects:
  461. .. code-block:: shell
  462. cmake --find-package [<options>]
  463. It searches a package using :command:`find_package()` and prints the
  464. resulting flags to stdout. This can be used instead of pkg-config
  465. to find installed libraries in plain Makefile-based projects or in
  466. autoconf-based projects (via ``share/aclocal/cmake.m4``).
  467. .. note::
  468. This mode is not well-supported due to some technical limitations.
  469. It is kept for compatibility but should not be used in new projects.
  470. View Help
  471. =========
  472. To print selected pages from the CMake documentation, use
  473. .. code-block:: shell
  474. cmake --help[-<topic>]
  475. with one of the following options:
  476. .. include:: OPTIONS_HELP.txt
  477. See Also
  478. ========
  479. .. include:: LINKS.txt