cmake.1.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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. ``--warn-uninitialized``
  175. Warn about uninitialized values.
  176. Print a warning when an uninitialized variable is used.
  177. ``--warn-unused-vars``
  178. Warn about unused variables.
  179. Find variables that are declared or set, but not used.
  180. ``--no-warn-unused-cli``
  181. Don't warn about command line options.
  182. Don't find variables that are declared on the command line, but not
  183. used.
  184. ``--check-system-vars``
  185. Find problems with variable usage in system files.
  186. Normally, unused and uninitialized variables are searched for only
  187. in :variable:`CMAKE_SOURCE_DIR` and :variable:`CMAKE_BINARY_DIR`.
  188. This flag tells CMake to warn about other files as well.
  189. .. _`Build Tool Mode`:
  190. Build a Project
  191. ===============
  192. CMake provides a command-line signature to build an already-generated
  193. project binary tree:
  194. .. code-block:: shell
  195. cmake --build <dir> [<options>] [-- <build-tool-options>]
  196. This abstracts a native build tool's command-line interface with the
  197. following options:
  198. ``--build <dir>``
  199. Project binary directory to be built. This is required and must be first.
  200. ``--parallel [<jobs>], -j [<jobs>]``
  201. The maximum number of concurrent processes to use when building.
  202. If ``<jobs>`` is omitted the native build tool's default number is used.
  203. The :envvar:`CMAKE_BUILD_PARALLEL_LEVEL` environment variable, if set,
  204. specifies a default parallel level when this option is not given.
  205. Some native build tools always build in parallel. The use of ``<jobs>``
  206. value of ``1`` can be used to limit to a single job.
  207. ``--target <tgt>..., -t <tgt>...``
  208. Build ``<tgt>`` instead of default targets. May be specified multiple times.
  209. ``--config <cfg>``
  210. For multi-configuration tools, choose configuration ``<cfg>``.
  211. ``--clean-first``
  212. Build target ``clean`` first, then build.
  213. (To clean only, use ``--target clean``.)
  214. ``--use-stderr``
  215. Ignored. Behavior is default in CMake >= 3.0.
  216. ``--verbose, -v``
  217. Enable verbose output - if supported - including the build commands to be
  218. executed.
  219. This option can be omitted if :envvar:`VERBOSE` environment variable or
  220. :variable:`CMAKE_VERBOSE_MAKEFILE` cached variable is set.
  221. ``--``
  222. Pass remaining options to the native tool.
  223. Run ``cmake --build`` with no options for quick help.
  224. Install a Project
  225. =================
  226. CMake provides a command-line signature to install an already-generated
  227. project binary tree:
  228. .. code-block:: shell
  229. cmake --install <dir> [<options>]
  230. This may be used after building a project to run installation without
  231. using the generated build system or the native build tool.
  232. The options are:
  233. ``--install <dir>``
  234. Project binary directory to install. This is required and must be first.
  235. ``--config <cfg>``
  236. For multi-configuration tools, choose configuration ``<cfg>``.
  237. ``--component <comp>``
  238. Component-based install. Only install component ``<comp>``.
  239. ``--prefix <prefix>``
  240. The installation prefix :variable:`CMAKE_INSTALL_PREFIX`.
  241. ``--strip``
  242. Strip before installing by setting ``CMAKE_INSTALL_DO_STRIP``.
  243. ``-v, --verbose``
  244. Enable verbose output.
  245. This option can be omitted if :envvar:`VERBOSE` environment variable is set.
  246. Run ``cmake --install`` with no options for quick help.
  247. Open a Project
  248. ==============
  249. .. code-block:: shell
  250. cmake --open <dir>
  251. Open the generated project in the associated application. This is only
  252. supported by some generators.
  253. .. _`Script Processing Mode`:
  254. Run a Script
  255. ============
  256. .. code-block:: shell
  257. cmake [{-D <var>=<value>}...] -P <cmake-script-file>
  258. Process the given cmake file as a script written in the CMake
  259. language. No configure or generate step is performed and the cache
  260. is not modified. If variables are defined using ``-D``, this must be
  261. done before the ``-P`` argument.
  262. Run a Command-Line Tool
  263. =======================
  264. CMake provides builtin command-line tools through the signature
  265. .. code-block:: shell
  266. cmake -E <command> [<options>]
  267. Run ``cmake -E`` or ``cmake -E help`` for a summary of commands.
  268. Available commands are:
  269. ``capabilities``
  270. Report cmake capabilities in JSON format. The output is a JSON object
  271. with the following keys:
  272. ``version``
  273. A JSON object with version information. Keys are:
  274. ``string``
  275. The full version string as displayed by cmake ``--version``.
  276. ``major``
  277. The major version number in integer form.
  278. ``minor``
  279. The minor version number in integer form.
  280. ``patch``
  281. The patch level in integer form.
  282. ``suffix``
  283. The cmake version suffix string.
  284. ``isDirty``
  285. A bool that is set if the cmake build is from a dirty tree.
  286. ``generators``
  287. A list available generators. Each generator is a JSON object with the
  288. following keys:
  289. ``name``
  290. A string containing the name of the generator.
  291. ``toolsetSupport``
  292. ``true`` if the generator supports toolsets and ``false`` otherwise.
  293. ``platformSupport``
  294. ``true`` if the generator supports platforms and ``false`` otherwise.
  295. ``extraGenerators``
  296. A list of strings with all the extra generators compatible with
  297. the generator.
  298. ``serverMode``
  299. ``true`` if cmake supports server-mode and ``false`` otherwise.
  300. ``chdir <dir> <cmd> [<arg>...]``
  301. Change the current working directory and run a command.
  302. ``compare_files [--ignore-eol] <file1> <file2>``
  303. Check if ``<file1>`` is same as ``<file2>``. If files are the same,
  304. then returns ``0``, if not it returns ``1``. The ``--ignore-eol`` option
  305. implies line-wise comparison and ignores LF/CRLF differences.
  306. ``copy <file>... <destination>``
  307. Copy files to ``<destination>`` (either file or directory).
  308. If multiple files are specified, the ``<destination>`` must be
  309. directory and it must exist. Wildcards are not supported.
  310. ``copy`` does follow symlinks. That means it does not copy symlinks,
  311. but the files or directories it point to.
  312. ``copy_directory <dir>... <destination>``
  313. Copy directories to ``<destination>`` directory.
  314. If ``<destination>`` directory does not exist it will be created.
  315. ``copy_directory`` does follow symlinks.
  316. ``copy_if_different <file>... <destination>``
  317. Copy files to ``<destination>`` (either file or directory) if
  318. they have changed.
  319. If multiple files are specified, the ``<destination>`` must be
  320. directory and it must exist.
  321. ``copy_if_different`` does follow symlinks.
  322. ``echo [<string>...]``
  323. Displays arguments as text.
  324. ``echo_append [<string>...]``
  325. Displays arguments as text but no new line.
  326. ``env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...``
  327. Run command in a modified environment.
  328. ``environment``
  329. Display the current environment variables.
  330. ``make_directory <dir>...``
  331. Create ``<dir>`` directories. If necessary, create parent
  332. directories too. If a directory already exists it will be
  333. silently ignored.
  334. ``md5sum <file>...``
  335. Create MD5 checksum of files in ``md5sum`` compatible format::
  336. 351abe79cd3800b38cdfb25d45015a15 file1.txt
  337. 052f86c15bbde68af55c7f7b340ab639 file2.txt
  338. ``sha1sum <file>...``
  339. Create SHA1 checksum of files in ``sha1sum`` compatible format::
  340. 4bb7932a29e6f73c97bb9272f2bdc393122f86e0 file1.txt
  341. 1df4c8f318665f9a5f2ed38f55adadb7ef9f559c file2.txt
  342. ``sha224sum <file>...``
  343. Create SHA224 checksum of files in ``sha224sum`` compatible format::
  344. b9b9346bc8437bbda630b0b7ddfc5ea9ca157546dbbf4c613192f930 file1.txt
  345. 6dfbe55f4d2edc5fe5c9197bca51ceaaf824e48eba0cc453088aee24 file2.txt
  346. ``sha256sum <file>...``
  347. Create SHA256 checksum of files in ``sha256sum`` compatible format::
  348. 76713b23615d31680afeb0e9efe94d47d3d4229191198bb46d7485f9cb191acc file1.txt
  349. 15b682ead6c12dedb1baf91231e1e89cfc7974b3787c1e2e01b986bffadae0ea file2.txt
  350. ``sha384sum <file>...``
  351. Create SHA384 checksum of files in ``sha384sum`` compatible format::
  352. acc049fedc091a22f5f2ce39a43b9057fd93c910e9afd76a6411a28a8f2b8a12c73d7129e292f94fc0329c309df49434 file1.txt
  353. 668ddeb108710d271ee21c0f3acbd6a7517e2b78f9181c6a2ff3b8943af92b0195dcb7cce48aa3e17893173c0a39e23d file2.txt
  354. ``sha512sum <file>...``
  355. Create SHA512 checksum of files in ``sha512sum`` compatible format::
  356. 2a78d7a6c5328cfb1467c63beac8ff21794213901eaadafd48e7800289afbc08e5fb3e86aa31116c945ee3d7bf2a6194489ec6101051083d1108defc8e1dba89 file1.txt
  357. 7a0b54896fe5e70cca6dd643ad6f672614b189bf26f8153061c4d219474b05dad08c4e729af9f4b009f1a1a280cb625454bf587c690f4617c27e3aebdf3b7a2d file2.txt
  358. ``remove [-f] <file>...``
  359. Remove the file(s). If any of the listed files already do not
  360. exist, the command returns a non-zero exit code, but no message
  361. is logged. The ``-f`` option changes the behavior to return a
  362. zero exit code (i.e. success) in such situations instead.
  363. ``remove`` does not follow symlinks. That means it remove only symlinks
  364. and not files it point to.
  365. ``remove_directory <dir>``
  366. Remove a directory and its contents. If a directory does
  367. not exist it will be silently ignored.
  368. ``rename <oldname> <newname>``
  369. Rename a file or directory (on one volume). If file with the ``<newname>`` name
  370. already exists, then it will be silently replaced.
  371. ``server``
  372. Launch :manual:`cmake-server(7)` mode.
  373. ``sleep <number>...``
  374. Sleep for given number of seconds.
  375. ``tar [cxt][vf][zjJ] file.tar [<options>] [--] [<pathname>...]``
  376. Create or extract a tar or zip archive. Options are:
  377. ``c``
  378. Create a new archive containing the specified files.
  379. If used, the ``<pathname>...`` argument is mandatory.
  380. ``x``
  381. Extract to disk from the archive.
  382. The ``<pathname>...`` argument could be used to extract only selected files
  383. or directories.
  384. When extracting selected files or directories, you must provide their exact
  385. names including the path, as printed by list (``-t``).
  386. ``t``
  387. List archive contents.
  388. The ``<pathname>...`` argument could be used to list only selected files
  389. or directories.
  390. ``v``
  391. Produce verbose output.
  392. ``z``
  393. Compress the resulting archive with gzip.
  394. ``j``
  395. Compress the resulting archive with bzip2.
  396. ``J``
  397. Compress the resulting archive with XZ.
  398. ``--``
  399. Stop interpreting options and treat all remaining arguments
  400. as file names even if they start in ``-``.
  401. ``--files-from=<file>``
  402. Read file names from the given file, one per line.
  403. Blank lines are ignored. Lines may not start in ``-``
  404. except for ``--add-file=<name>`` to add files whose
  405. names start in ``-``.
  406. ``--mtime=<date>``
  407. Specify modification time recorded in tarball entries.
  408. ``--format=<format>``
  409. Specify the format of the archive to be created.
  410. Supported formats are: ``7zip``, ``gnutar``, ``pax``,
  411. ``paxr`` (restricted pax, default), and ``zip``.
  412. ``time <command> [<args>...]``
  413. Run command and display elapsed time.
  414. ``touch <file>...``
  415. Creates ``<file>`` if file do not exist.
  416. If ``<file>`` exists, it is changing ``<file>`` access and modification times.
  417. ``touch_nocreate <file>...``
  418. Touch a file if it exists but do not create it. If a file does
  419. not exist it will be silently ignored.
  420. ``create_symlink <old> <new>``
  421. Create a symbolic link ``<new>`` naming ``<old>``.
  422. .. note::
  423. Path to where ``<new>`` symbolic link will be created has to exist beforehand.
  424. Windows-specific Command-Line Tools
  425. -----------------------------------
  426. The following ``cmake -E`` commands are available only on Windows:
  427. ``delete_regv <key>``
  428. Delete Windows registry value.
  429. ``env_vs8_wince <sdkname>``
  430. Displays a batch file which sets the environment for the provided
  431. Windows CE SDK installed in VS2005.
  432. ``env_vs9_wince <sdkname>``
  433. Displays a batch file which sets the environment for the provided
  434. Windows CE SDK installed in VS2008.
  435. ``write_regv <key> <value>``
  436. Write Windows registry value.
  437. Run the Find-Package Tool
  438. =========================
  439. CMake provides a pkg-config like helper for Makefile-based projects:
  440. .. code-block:: shell
  441. cmake --find-package [<options>]
  442. It searches a package using :command:`find_package()` and prints the
  443. resulting flags to stdout. This can be used instead of pkg-config
  444. to find installed libraries in plain Makefile-based projects or in
  445. autoconf-based projects (via ``share/aclocal/cmake.m4``).
  446. .. note::
  447. This mode is not well-supported due to some technical limitations.
  448. It is kept for compatibility but should not be used in new projects.
  449. View Help
  450. =========
  451. To print selected pages from the CMake documentation, use
  452. .. code-block:: shell
  453. cmake --help[-<topic>]
  454. with one of the following options:
  455. .. include:: OPTIONS_HELP.txt
  456. See Also
  457. ========
  458. .. include:: LINKS.txt