cmake.1.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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. `Open a Project`_
  14. cmake --open <dir>
  15. `Run a Script`_
  16. cmake [{-D <var>=<value>}...] -P <cmake-script-file>
  17. `Run a Command-Line Tool`_
  18. cmake -E <command> [<options>]
  19. `Run the Find-Package Tool`_
  20. cmake --find-package [<options>]
  21. `View Help`_
  22. cmake --help[-<topic>]
  23. Description
  24. ===========
  25. The **cmake** executable is the command-line interface of the cross-platform
  26. buildsystem generator CMake. The above `Synopsis`_ lists various actions
  27. the tool can perform as described in sections below.
  28. To build a software project with CMake, `Generate a Project Buildsystem`_.
  29. Optionally use **cmake** to `Build a Project`_ or just run the
  30. corresponding build tool (e.g. ``make``) directly. **cmake** can also
  31. be used to `View Help`_.
  32. The other actions are meant for use by software developers writing
  33. scripts in the :manual:`CMake language <cmake-language(7)>` to support
  34. their builds.
  35. For graphical user interfaces that may be used in place of **cmake**,
  36. see :manual:`ccmake <ccmake(1)>` and :manual:`cmake-gui <cmake-gui(1)>`.
  37. For command-line interfaces to the CMake testing and packaging facilities,
  38. see :manual:`ctest <ctest(1)>` and :manual:`cpack <cpack(1)>`.
  39. For more information on CMake at large, `see also`_ the links at the end
  40. of this manual.
  41. Introduction to CMake Buildsystems
  42. ==================================
  43. A *buildsystem* describes how to build a project's executables and libraries
  44. from its source code using a *build tool* to automate the process. For
  45. example, a buildsystem may be a ``Makefile`` for use with a command-line
  46. ``make`` tool or a project file for an Integrated Development Environment
  47. (IDE). In order to avoid maintaining multiple such buildsystems, a project
  48. may specify its buildsystem abstractly using files written in the
  49. :manual:`CMake language <cmake-language(7)>`. From these files CMake
  50. generates a preferred buildsystem locally for each user through a backend
  51. called a *generator*.
  52. To generate a buildsystem with CMake, the following must be selected:
  53. Source Tree
  54. The top-level directory containing source files provided by the project.
  55. The project specifies its buildsystem using files as described in the
  56. :manual:`cmake-language(7)` manual, starting with a top-level file named
  57. ``CMakeLists.txt``. These files specify build targets and their
  58. dependencies as described in the :manual:`cmake-buildsystem(7)` manual.
  59. Build Tree
  60. The top-level directory in which buildsystem files and build output
  61. artifacts (e.g. executables and libraries) are to be stored.
  62. CMake will write a ``CMakeCache.txt`` file to identify the directory
  63. as a build tree and store persistent information such as buildsystem
  64. configuration options.
  65. To maintain a pristine source tree, perform an *out-of-source* build
  66. by using a separate dedicated build tree. An *in-source* build in
  67. which the build tree is placed in the same directory as the source
  68. tree is also supported, but discouraged.
  69. Generator
  70. This chooses the kind of buildsystem to generate. See the
  71. :manual:`cmake-generators(7)` manual for documentation of all generators.
  72. Run ``cmake --help`` to see a list of generators available locally.
  73. Optionally use the ``-G`` option below to specify a generator, or simply
  74. accept the default CMake chooses for the current platform.
  75. When using one of the :ref:`Command-Line Build Tool Generators`
  76. CMake expects that the environment needed by the compiler toolchain
  77. is already configured in the shell. When using one of the
  78. :ref:`IDE Build Tool Generators`, no particular environment is needed.
  79. Generate a Project Buildsystem
  80. ==============================
  81. Run CMake with one of the following command signatures to specify the
  82. source and build trees and generate a buildsystem:
  83. ``cmake [<options>] <path-to-source>``
  84. Uses the current working directory as the build tree, and
  85. ``<path-to-source>`` as the source tree. The specified path may
  86. be absolute or relative to the current working directory.
  87. The source tree must contain a ``CMakeLists.txt`` file and must
  88. *not* contain a ``CMakeCache.txt`` file because the latter
  89. identifies an existing build tree. For example:
  90. .. code-block:: console
  91. $ mkdir build ; cd build
  92. $ cmake ../src
  93. ``cmake [<options>] <path-to-existing-build>``
  94. Uses ``<path-to-existing-build>`` as the build tree, and loads the
  95. path to the source tree from its ``CMakeCache.txt`` file, which must
  96. have already been generated by a previous run of CMake. The specified
  97. path may be absolute or relative to the current working directory.
  98. For example:
  99. .. code-block:: console
  100. $ cd build
  101. $ cmake .
  102. ``cmake [<options>] -S <path-to-source> -B <path-to-build>``
  103. Uses ``<path-to-build>`` as the build tree and ``<path-to-source>``
  104. as the source tree. The specified paths may be absolute or relative
  105. to the current working directory. The source tree must contain a
  106. ``CMakeLists.txt`` file. The build tree will be created automatically
  107. if it does not already exist. For example:
  108. .. code-block:: console
  109. $ cmake -S src -B build
  110. In all cases the ``<options>`` may be zero or more of the `Options`_ below.
  111. After generating a buildsystem one may use the corresponding native
  112. build tool to build the project. For example, after using the
  113. :generator:`Unix Makefiles` generator one may run ``make`` directly:
  114. .. code-block:: console
  115. $ make
  116. $ make install
  117. Alternatively, one may use **cmake** to `Build a Project`_ by
  118. automatically choosing and invoking the appropriate native build tool.
  119. .. _`CMake Options`:
  120. Options
  121. -------
  122. .. include:: OPTIONS_BUILD.txt
  123. ``-L[A][H]``
  124. List non-advanced cached variables.
  125. List cache variables will run CMake and list all the variables from
  126. the CMake cache that are not marked as INTERNAL or ADVANCED. This
  127. will effectively display current CMake settings, which can then be
  128. changed with -D option. Changing some of the variables may result
  129. in more variables being created. If A is specified, then it will
  130. display also advanced variables. If H is specified, it will also
  131. display help for each variable.
  132. ``-N``
  133. View mode only.
  134. Only load the cache. Do not actually run configure and generate
  135. steps.
  136. ``--graphviz=[file]``
  137. Generate graphviz of dependencies, see :module:`CMakeGraphVizOptions` for more.
  138. Generate a graphviz input file that will contain all the library and
  139. executable dependencies in the project. See the documentation for
  140. :module:`CMakeGraphVizOptions` for more details.
  141. ``--system-information [file]``
  142. Dump information about this system.
  143. Dump a wide range of information about the current system. If run
  144. from the top of a binary tree for a CMake project it will dump
  145. additional information such as the cache, log files etc.
  146. ``--debug-trycompile``
  147. Do not delete the try_compile build tree. Only useful on one try_compile at a time.
  148. Do not delete the files and directories created for try_compile
  149. calls. This is useful in debugging failed try_compiles. It may
  150. however change the results of the try-compiles as old junk from a
  151. previous try-compile may cause a different test to either pass or
  152. fail incorrectly. This option is best used for one try-compile at a
  153. time, and only when debugging.
  154. ``--debug-output``
  155. Put cmake in a debug mode.
  156. Print extra information during the cmake run like stack traces with
  157. message(send_error ) calls.
  158. ``--trace``
  159. Put cmake in trace mode.
  160. Print a trace of all calls made and from where.
  161. ``--trace-expand``
  162. Put cmake in trace mode.
  163. Like ``--trace``, but with variables expanded.
  164. ``--trace-source=<file>``
  165. Put cmake in trace mode, but output only lines of a specified file.
  166. Multiple options are allowed.
  167. ``--warn-uninitialized``
  168. Warn about uninitialized values.
  169. Print a warning when an uninitialized variable is used.
  170. ``--warn-unused-vars``
  171. Warn about unused variables.
  172. Find variables that are declared or set, but not used.
  173. ``--no-warn-unused-cli``
  174. Don't warn about command line options.
  175. Don't find variables that are declared on the command line, but not
  176. used.
  177. ``--check-system-vars``
  178. Find problems with variable usage in system files.
  179. Normally, unused and uninitialized variables are searched for only
  180. in CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR. This flag tells CMake to
  181. warn about other files as well.
  182. .. _`Build Tool Mode`:
  183. Build a Project
  184. ===============
  185. CMake provides a command-line signature to build an already-generated
  186. project binary tree:
  187. .. code-block:: shell
  188. cmake --build <dir> [<options>] [-- <build-tool-options>]
  189. This abstracts a native build tool's command-line interface with the
  190. following options:
  191. ``--build <dir>``
  192. Project binary directory to be built. This is required and must be first.
  193. ``--parallel [<jobs>], -j [<jobs>]``
  194. The maximum number of concurrent processes to use when building.
  195. If ``<jobs>`` is omitted the native build tool's default number is used.
  196. The :envvar:`CMAKE_BUILD_PARALLEL_LEVEL` environment variable, if set,
  197. specifies a default parallel level when this option is not given.
  198. ``--target <tgt>..., -t <tgt>...``
  199. Build ``<tgt>`` instead of default targets. May be specified multiple times.
  200. ``--config <cfg>``
  201. For multi-configuration tools, choose configuration ``<cfg>``.
  202. ``--clean-first``
  203. Build target ``clean`` first, then build.
  204. (To clean only, use ``--target clean``.)
  205. ``--use-stderr``
  206. Ignored. Behavior is default in CMake >= 3.0.
  207. ``--verbose, -v``
  208. Enable verbose output - if supported - including the build commands to be
  209. executed.
  210. This option can be omitted if :envvar:`VERBOSE` environment variable or
  211. :variable:`CMAKE_VERBOSE_MAKEFILE` cached variable is set.
  212. ``--``
  213. Pass remaining options to the native tool.
  214. Run ``cmake --build`` with no options for quick help.
  215. Open a Project
  216. ==============
  217. .. code-block:: shell
  218. cmake --open <dir>
  219. Open the generated project in the associated application. This is only
  220. supported by some generators.
  221. .. _`Script Processing Mode`:
  222. Run a Script
  223. ============
  224. .. code-block:: shell
  225. cmake [{-D <var>=<value>}...] -P <cmake-script-file>
  226. Process the given cmake file as a script written in the CMake
  227. language. No configure or generate step is performed and the cache
  228. is not modified. If variables are defined using -D, this must be
  229. done before the -P argument.
  230. Run a Command-Line Tool
  231. =======================
  232. CMake provides builtin command-line tools through the signature
  233. .. code-block:: shell
  234. cmake -E <command> [<options>]
  235. Run ``cmake -E`` or ``cmake -E help`` for a summary of commands.
  236. Available commands are:
  237. ``capabilities``
  238. Report cmake capabilities in JSON format. The output is a JSON object
  239. with the following keys:
  240. ``version``
  241. A JSON object with version information. Keys are:
  242. ``string``
  243. The full version string as displayed by cmake ``--version``.
  244. ``major``
  245. The major version number in integer form.
  246. ``minor``
  247. The minor version number in integer form.
  248. ``patch``
  249. The patch level in integer form.
  250. ``suffix``
  251. The cmake version suffix string.
  252. ``isDirty``
  253. A bool that is set if the cmake build is from a dirty tree.
  254. ``generators``
  255. A list available generators. Each generator is a JSON object with the
  256. following keys:
  257. ``name``
  258. A string containing the name of the generator.
  259. ``toolsetSupport``
  260. ``true`` if the generator supports toolsets and ``false`` otherwise.
  261. ``platformSupport``
  262. ``true`` if the generator supports platforms and ``false`` otherwise.
  263. ``extraGenerators``
  264. A list of strings with all the extra generators compatible with
  265. the generator.
  266. ``serverMode``
  267. ``true`` if cmake supports server-mode and ``false`` otherwise.
  268. ``chdir <dir> <cmd> [<arg>...]``
  269. Change the current working directory and run a command.
  270. ``compare_files [--ignore-eol] <file1> <file2>``
  271. Check if ``<file1>`` is same as ``<file2>``. If files are the same,
  272. then returns 0, if not it returns 1. The ``--ignore-eol`` option
  273. implies line-wise comparison and ignores LF/CRLF differences.
  274. ``copy <file>... <destination>``
  275. Copy files to ``<destination>`` (either file or directory).
  276. If multiple files are specified, the ``<destination>`` must be
  277. directory and it must exist. Wildcards are not supported.
  278. ``copy`` does follow symlinks. That means it does not copy symlinks,
  279. but the files or directories it point to.
  280. ``copy_directory <dir>... <destination>``
  281. Copy directories to ``<destination>`` directory.
  282. If ``<destination>`` directory does not exist it will be created.
  283. ``copy_directory`` does follow symlinks.
  284. ``copy_if_different <file>... <destination>``
  285. Copy files to ``<destination>`` (either file or directory) if
  286. they have changed.
  287. If multiple files are specified, the ``<destination>`` must be
  288. directory and it must exist.
  289. ``copy_if_different`` does follow symlinks.
  290. ``echo [<string>...]``
  291. Displays arguments as text.
  292. ``echo_append [<string>...]``
  293. Displays arguments as text but no new line.
  294. ``env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...``
  295. Run command in a modified environment.
  296. ``environment``
  297. Display the current environment variables.
  298. ``make_directory <dir>...``
  299. Create ``<dir>`` directories. If necessary, create parent
  300. directories too. If a directory already exists it will be
  301. silently ignored.
  302. ``md5sum <file>...``
  303. Create MD5 checksum of files in ``md5sum`` compatible format::
  304. 351abe79cd3800b38cdfb25d45015a15 file1.txt
  305. 052f86c15bbde68af55c7f7b340ab639 file2.txt
  306. ``sha1sum <file>...``
  307. Create SHA1 checksum of files in ``sha1sum`` compatible format::
  308. 4bb7932a29e6f73c97bb9272f2bdc393122f86e0 file1.txt
  309. 1df4c8f318665f9a5f2ed38f55adadb7ef9f559c file2.txt
  310. ``sha224sum <file>...``
  311. Create SHA224 checksum of files in ``sha224sum`` compatible format::
  312. b9b9346bc8437bbda630b0b7ddfc5ea9ca157546dbbf4c613192f930 file1.txt
  313. 6dfbe55f4d2edc5fe5c9197bca51ceaaf824e48eba0cc453088aee24 file2.txt
  314. ``sha256sum <file>...``
  315. Create SHA256 checksum of files in ``sha256sum`` compatible format::
  316. 76713b23615d31680afeb0e9efe94d47d3d4229191198bb46d7485f9cb191acc file1.txt
  317. 15b682ead6c12dedb1baf91231e1e89cfc7974b3787c1e2e01b986bffadae0ea file2.txt
  318. ``sha384sum <file>...``
  319. Create SHA384 checksum of files in ``sha384sum`` compatible format::
  320. acc049fedc091a22f5f2ce39a43b9057fd93c910e9afd76a6411a28a8f2b8a12c73d7129e292f94fc0329c309df49434 file1.txt
  321. 668ddeb108710d271ee21c0f3acbd6a7517e2b78f9181c6a2ff3b8943af92b0195dcb7cce48aa3e17893173c0a39e23d file2.txt
  322. ``sha512sum <file>...``
  323. Create SHA512 checksum of files in ``sha512sum`` compatible format::
  324. 2a78d7a6c5328cfb1467c63beac8ff21794213901eaadafd48e7800289afbc08e5fb3e86aa31116c945ee3d7bf2a6194489ec6101051083d1108defc8e1dba89 file1.txt
  325. 7a0b54896fe5e70cca6dd643ad6f672614b189bf26f8153061c4d219474b05dad08c4e729af9f4b009f1a1a280cb625454bf587c690f4617c27e3aebdf3b7a2d file2.txt
  326. ``remove [-f] <file>...``
  327. Remove the file(s). If any of the listed files already do not
  328. exist, the command returns a non-zero exit code, but no message
  329. is logged. The ``-f`` option changes the behavior to return a
  330. zero exit code (i.e. success) in such situations instead.
  331. ``remove`` does not follow symlinks. That means it remove only symlinks
  332. and not files it point to.
  333. ``remove_directory <dir>``
  334. Remove a directory and its contents. If a directory does
  335. not exist it will be silently ignored.
  336. ``rename <oldname> <newname>``
  337. Rename a file or directory (on one volume). If file with the ``<newname>`` name
  338. already exists, then it will be silently replaced.
  339. ``server``
  340. Launch :manual:`cmake-server(7)` mode.
  341. ``sleep <number>...``
  342. Sleep for given number of seconds.
  343. ``tar [cxt][vf][zjJ] file.tar [<options>] [--] [<file>...]``
  344. Create or extract a tar or zip archive. Options are:
  345. ``c``
  346. Create a new archive containing the specified files.
  347. If used, the <file> argument is mandatory.
  348. ``x``
  349. Extract to disk from the archive.
  350. ``t``
  351. List archive contents to stdout.
  352. ``v``
  353. Produce verbose output.
  354. ``z``
  355. Compress the resulting archive with gzip.
  356. ``j``
  357. Compress the resulting archive with bzip2.
  358. ``J``
  359. Compress the resulting archive with XZ.
  360. ``--``
  361. Stop interpreting options and treat all remaining arguments
  362. as file names even if they start in ``-``.
  363. ``--files-from=<file>``
  364. Read file names from the given file, one per line.
  365. Blank lines are ignored. Lines may not start in ``-``
  366. except for ``--add-file=<name>`` to add files whose
  367. names start in ``-``.
  368. ``--mtime=<date>``
  369. Specify modification time recorded in tarball entries.
  370. ``--format=<format>``
  371. Specify the format of the archive to be created.
  372. Supported formats are: ``7zip``, ``gnutar``, ``pax``,
  373. ``paxr`` (restricted pax, default), and ``zip``.
  374. ``time <command> [<args>...]``
  375. Run command and display elapsed time.
  376. ``touch <file>...``
  377. Creates ``<file>`` if file do not exist.
  378. If ``<file>`` exists, it is changing ``<file>`` access and modification times.
  379. ``touch_nocreate <file>...``
  380. Touch a file if it exists but do not create it. If a file does
  381. not exist it will be silently ignored.
  382. ``create_symlink <old> <new>``
  383. Create a symbolic link ``<new>`` naming ``<old>``.
  384. .. note::
  385. Path to where ``<new>`` symbolic link will be created has to exist beforehand.
  386. Windows-specific Command-Line Tools
  387. -----------------------------------
  388. The following ``cmake -E`` commands are available only on Windows:
  389. ``delete_regv <key>``
  390. Delete Windows registry value.
  391. ``env_vs8_wince <sdkname>``
  392. Displays a batch file which sets the environment for the provided
  393. Windows CE SDK installed in VS2005.
  394. ``env_vs9_wince <sdkname>``
  395. Displays a batch file which sets the environment for the provided
  396. Windows CE SDK installed in VS2008.
  397. ``write_regv <key> <value>``
  398. Write Windows registry value.
  399. Run the Find-Package Tool
  400. =========================
  401. CMake provides a pkg-config like helper for Makefile-based projects:
  402. .. code-block:: shell
  403. cmake --find-package [<options>]
  404. It searches a package using :command:`find_package()` and prints the
  405. resulting flags to stdout. This can be used instead of pkg-config
  406. to find installed libraries in plain Makefile-based projects or in
  407. autoconf-based projects (via ``share/aclocal/cmake.m4``).
  408. .. note::
  409. This mode is not well-supported due to some technical limitations.
  410. It is kept for compatibility but should not be used in new projects.
  411. View Help
  412. =========
  413. To print selected pages from the CMake documentation, use
  414. .. code-block:: shell
  415. cmake --help[-<topic>]
  416. with one of the following options:
  417. .. include:: OPTIONS_HELP.txt
  418. See Also
  419. ========
  420. .. include:: LINKS.txt