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.

462 lines
14 KiB

  1. .. cmake-manual-description: CMake Command-Line Reference
  2. cmake(1)
  3. ********
  4. Synopsis
  5. ========
  6. .. parsed-literal::
  7. `Generate a Project Buildsystem`_
  8. cmake [<options>] {<path-to-source> | <path-to-existing-build>}
  9. cmake [<options>] -S <path-to-source> -B <path-to-build>
  10. `Build a Project`_
  11. cmake --build <dir> [<options>] [-- <build-tool-options>]
  12. `Open a Project`_
  13. cmake --open <dir>
  14. `Run a Script`_
  15. cmake [{-D <var>=<value>}...] -P <cmake-script-file>
  16. `Run a Command-Line Tool`_
  17. cmake -E <command> [<options>]
  18. `Run the Find-Package Tool`_
  19. cmake --find-package [<options>]
  20. `View Help`_
  21. cmake --help[-<topic>]
  22. Description
  23. ===========
  24. The **cmake** executable is the CMake command-line interface. It may be
  25. used to configure projects in scripts. Project configuration settings
  26. may be specified on the command line with the -D option.
  27. CMake is a cross-platform build system generator. Projects specify
  28. their build process with platform-independent CMake listfiles included
  29. in each directory of a source tree with the name CMakeLists.txt.
  30. Users build a project by using CMake to generate a build system for a
  31. native tool on their platform.
  32. Generate a Project Buildsystem
  33. ==============================
  34. .. code-block:: shell
  35. cmake [<options>] {<path-to-source> | <path-to-existing-build>}
  36. cmake [<options>] -S <path-to-source> -B <path-to-build>
  37. The parameter ``<path-to-source>`` must be the relative or absolute path
  38. of the source directory that contains the top-level ``CMakeLists.txt`` file.
  39. Alternatively, if the named directory contains ``CMakeCache.txt`` it will
  40. be treated as ``<path-to-existing-build>`` and the path to the source will
  41. be loaded from the cache.
  42. By default, **cmake** writes the generated Makefiles and all other output
  43. to the directory from where it was invoked. This behavior can be changed
  44. by the variant with the parameter ``<path-to-build>``.
  45. In all cases the ``<options>`` may be zero or more of the `Options`_ below.
  46. .. _`CMake Options`:
  47. Options
  48. -------
  49. .. include:: OPTIONS_BUILD.txt
  50. ``-L[A][H]``
  51. List non-advanced cached variables.
  52. List cache variables will run CMake and list all the variables from
  53. the CMake cache that are not marked as INTERNAL or ADVANCED. This
  54. will effectively display current CMake settings, which can then be
  55. changed with -D option. Changing some of the variables may result
  56. in more variables being created. If A is specified, then it will
  57. display also advanced variables. If H is specified, it will also
  58. display help for each variable.
  59. ``-N``
  60. View mode only.
  61. Only load the cache. Do not actually run configure and generate
  62. steps.
  63. ``--graphviz=[file]``
  64. Generate graphviz of dependencies, see :module:`CMakeGraphVizOptions` for more.
  65. Generate a graphviz input file that will contain all the library and
  66. executable dependencies in the project. See the documentation for
  67. :module:`CMakeGraphVizOptions` for more details.
  68. ``--system-information [file]``
  69. Dump information about this system.
  70. Dump a wide range of information about the current system. If run
  71. from the top of a binary tree for a CMake project it will dump
  72. additional information such as the cache, log files etc.
  73. ``--debug-trycompile``
  74. Do not delete the try_compile build tree. Only useful on one try_compile at a time.
  75. Do not delete the files and directories created for try_compile
  76. calls. This is useful in debugging failed try_compiles. It may
  77. however change the results of the try-compiles as old junk from a
  78. previous try-compile may cause a different test to either pass or
  79. fail incorrectly. This option is best used for one try-compile at a
  80. time, and only when debugging.
  81. ``--debug-output``
  82. Put cmake in a debug mode.
  83. Print extra information during the cmake run like stack traces with
  84. message(send_error ) calls.
  85. ``--trace``
  86. Put cmake in trace mode.
  87. Print a trace of all calls made and from where.
  88. ``--trace-expand``
  89. Put cmake in trace mode.
  90. Like ``--trace``, but with variables expanded.
  91. ``--trace-source=<file>``
  92. Put cmake in trace mode, but output only lines of a specified file.
  93. Multiple options are allowed.
  94. ``--warn-uninitialized``
  95. Warn about uninitialized values.
  96. Print a warning when an uninitialized variable is used.
  97. ``--warn-unused-vars``
  98. Warn about unused variables.
  99. Find variables that are declared or set, but not used.
  100. ``--no-warn-unused-cli``
  101. Don't warn about command line options.
  102. Don't find variables that are declared on the command line, but not
  103. used.
  104. ``--check-system-vars``
  105. Find problems with variable usage in system files.
  106. Normally, unused and uninitialized variables are searched for only
  107. in CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR. This flag tells CMake to
  108. warn about other files as well.
  109. .. _`Build Tool Mode`:
  110. Build a Project
  111. ===============
  112. CMake provides a command-line signature to build an already-generated
  113. project binary tree:
  114. .. code-block:: shell
  115. cmake --build <dir> [<options>] [-- <build-tool-options>]
  116. This abstracts a native build tool's command-line interface with the
  117. following options:
  118. ``--build <dir>``
  119. Project binary directory to be built. This is required and must be first.
  120. ``-j [<jobs>], --parallel [<jobs>]``
  121. The maximum number of concurrent processes to use when building.
  122. If ``<jobs>`` is omitted the native build tool's default number is used.
  123. The :envvar:`CMAKE_BUILD_PARALLEL_LEVEL` environment variable, if set,
  124. specifies a default parallel level when this option is not given.
  125. ``--target <tgt>``
  126. Build ``<tgt>`` instead of default targets. May only be specified once.
  127. ``--config <cfg>``
  128. For multi-configuration tools, choose configuration ``<cfg>``.
  129. ``--clean-first``
  130. Build target ``clean`` first, then build.
  131. (To clean only, use ``--target clean``.)
  132. ``--use-stderr``
  133. Ignored. Behavior is default in CMake >= 3.0.
  134. ``--``
  135. Pass remaining options to the native tool.
  136. Run ``cmake --build`` with no options for quick help.
  137. Open a Project
  138. ==============
  139. .. code-block:: shell
  140. cmake --open <dir>
  141. Open the generated project in the associated application. This is only
  142. supported by some generators.
  143. .. _`Script Processing Mode`:
  144. Run a Script
  145. ============
  146. .. code-block:: shell
  147. cmake [{-D <var>=<value>}...] -P <cmake-script-file>
  148. Process the given cmake file as a script written in the CMake
  149. language. No configure or generate step is performed and the cache
  150. is not modified. If variables are defined using -D, this must be
  151. done before the -P argument.
  152. Run a Command-Line Tool
  153. =======================
  154. CMake provides builtin command-line tools through the signature
  155. .. code-block:: shell
  156. cmake -E <command> [<options>]
  157. Run ``cmake -E`` or ``cmake -E help`` for a summary of commands.
  158. Available commands are:
  159. ``capabilities``
  160. Report cmake capabilities in JSON format. The output is a JSON object
  161. with the following keys:
  162. ``version``
  163. A JSON object with version information. Keys are:
  164. ``string``
  165. The full version string as displayed by cmake ``--version``.
  166. ``major``
  167. The major version number in integer form.
  168. ``minor``
  169. The minor version number in integer form.
  170. ``patch``
  171. The patch level in integer form.
  172. ``suffix``
  173. The cmake version suffix string.
  174. ``isDirty``
  175. A bool that is set if the cmake build is from a dirty tree.
  176. ``generators``
  177. A list available generators. Each generator is a JSON object with the
  178. following keys:
  179. ``name``
  180. A string containing the name of the generator.
  181. ``toolsetSupport``
  182. ``true`` if the generator supports toolsets and ``false`` otherwise.
  183. ``platformSupport``
  184. ``true`` if the generator supports platforms and ``false`` otherwise.
  185. ``extraGenerators``
  186. A list of strings with all the extra generators compatible with
  187. the generator.
  188. ``serverMode``
  189. ``true`` if cmake supports server-mode and ``false`` otherwise.
  190. ``chdir <dir> <cmd> [<arg>...]``
  191. Change the current working directory and run a command.
  192. ``compare_files <file1> <file2>``
  193. Check if ``<file1>`` is same as ``<file2>``. If files are the same,
  194. then returns 0, if not it returns 1.
  195. ``copy <file>... <destination>``
  196. Copy files to ``<destination>`` (either file or directory).
  197. If multiple files are specified, the ``<destination>`` must be
  198. directory and it must exist. Wildcards are not supported.
  199. ``copy_directory <dir>... <destination>``
  200. Copy directories to ``<destination>`` directory.
  201. If ``<destination>`` directory does not exist it will be created.
  202. ``copy_if_different <file>... <destination>``
  203. Copy files to ``<destination>`` (either file or directory) if
  204. they have changed.
  205. If multiple files are specified, the ``<destination>`` must be
  206. directory and it must exist.
  207. ``echo [<string>...]``
  208. Displays arguments as text.
  209. ``echo_append [<string>...]``
  210. Displays arguments as text but no new line.
  211. ``env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...``
  212. Run command in a modified environment.
  213. ``environment``
  214. Display the current environment variables.
  215. ``make_directory <dir>...``
  216. Create ``<dir>`` directories. If necessary, create parent
  217. directories too. If a directory already exists it will be
  218. silently ignored.
  219. ``md5sum <file>...``
  220. Create MD5 checksum of files in ``md5sum`` compatible format::
  221. 351abe79cd3800b38cdfb25d45015a15 file1.txt
  222. 052f86c15bbde68af55c7f7b340ab639 file2.txt
  223. ``sha1sum <file>...``
  224. Create SHA1 checksum of files in ``sha1sum`` compatible format::
  225. 4bb7932a29e6f73c97bb9272f2bdc393122f86e0 file1.txt
  226. 1df4c8f318665f9a5f2ed38f55adadb7ef9f559c file2.txt
  227. ``sha224sum <file>...``
  228. Create SHA224 checksum of files in ``sha224sum`` compatible format::
  229. b9b9346bc8437bbda630b0b7ddfc5ea9ca157546dbbf4c613192f930 file1.txt
  230. 6dfbe55f4d2edc5fe5c9197bca51ceaaf824e48eba0cc453088aee24 file2.txt
  231. ``sha256sum <file>...``
  232. Create SHA256 checksum of files in ``sha256sum`` compatible format::
  233. 76713b23615d31680afeb0e9efe94d47d3d4229191198bb46d7485f9cb191acc file1.txt
  234. 15b682ead6c12dedb1baf91231e1e89cfc7974b3787c1e2e01b986bffadae0ea file2.txt
  235. ``sha384sum <file>...``
  236. Create SHA384 checksum of files in ``sha384sum`` compatible format::
  237. acc049fedc091a22f5f2ce39a43b9057fd93c910e9afd76a6411a28a8f2b8a12c73d7129e292f94fc0329c309df49434 file1.txt
  238. 668ddeb108710d271ee21c0f3acbd6a7517e2b78f9181c6a2ff3b8943af92b0195dcb7cce48aa3e17893173c0a39e23d file2.txt
  239. ``sha512sum <file>...``
  240. Create SHA512 checksum of files in ``sha512sum`` compatible format::
  241. 2a78d7a6c5328cfb1467c63beac8ff21794213901eaadafd48e7800289afbc08e5fb3e86aa31116c945ee3d7bf2a6194489ec6101051083d1108defc8e1dba89 file1.txt
  242. 7a0b54896fe5e70cca6dd643ad6f672614b189bf26f8153061c4d219474b05dad08c4e729af9f4b009f1a1a280cb625454bf587c690f4617c27e3aebdf3b7a2d file2.txt
  243. ``remove [-f] <file>...``
  244. Remove the file(s). If any of the listed files already do not
  245. exist, the command returns a non-zero exit code, but no message
  246. is logged. The ``-f`` option changes the behavior to return a
  247. zero exit code (i.e. success) in such situations instead.
  248. ``remove_directory <dir>``
  249. Remove a directory and its contents. If a directory does
  250. not exist it will be silently ignored.
  251. ``rename <oldname> <newname>``
  252. Rename a file or directory (on one volume).
  253. ``server``
  254. Launch :manual:`cmake-server(7)` mode.
  255. ``sleep <number>...``
  256. Sleep for given number of seconds.
  257. ``tar [cxt][vf][zjJ] file.tar [<options>] [--] [<file>...]``
  258. Create or extract a tar or zip archive. Options are:
  259. ``--``
  260. Stop interpreting options and treat all remaining arguments
  261. as file names even if they start in ``-``.
  262. ``--files-from=<file>``
  263. Read file names from the given file, one per line.
  264. Blank lines are ignored. Lines may not start in ``-``
  265. except for ``--add-file=<name>`` to add files whose
  266. names start in ``-``.
  267. ``--mtime=<date>``
  268. Specify modification time recorded in tarball entries.
  269. ``--format=<format>``
  270. Specify the format of the archive to be created.
  271. Supported formats are: ``7zip``, ``gnutar``, ``pax``,
  272. ``paxr`` (restricted pax, default), and ``zip``.
  273. ``time <command> [<args>...]``
  274. Run command and display elapsed time.
  275. ``touch <file>``
  276. Touch a file.
  277. ``touch_nocreate <file>``
  278. Touch a file if it exists but do not create it. If a file does
  279. not exist it will be silently ignored.
  280. ``create_symlink <old> <new>``
  281. Create a symbolic link ``<new>`` naming ``<old>``.
  282. .. note::
  283. Path to where ``<new>`` symbolic link will be created has to exist beforehand.
  284. Windows-specific Command-Line Tools
  285. -----------------------------------
  286. The following ``cmake -E`` commands are available only on Windows:
  287. ``delete_regv <key>``
  288. Delete Windows registry value.
  289. ``env_vs8_wince <sdkname>``
  290. Displays a batch file which sets the environment for the provided
  291. Windows CE SDK installed in VS2005.
  292. ``env_vs9_wince <sdkname>``
  293. Displays a batch file which sets the environment for the provided
  294. Windows CE SDK installed in VS2008.
  295. ``write_regv <key> <value>``
  296. Write Windows registry value.
  297. Run the Find-Package Tool
  298. =========================
  299. CMake provides a pkg-config like helper for Makefile-based projects:
  300. .. code-block:: shell
  301. cmake --find-package [<options>]
  302. It searches a package using :command:`find_package()` and prints the
  303. resulting flags to stdout. This can be used instead of pkg-config
  304. to find installed libraries in plain Makefile-based projects or in
  305. autoconf-based projects (via ``share/aclocal/cmake.m4``).
  306. .. note::
  307. This mode is not well-supported due to some technical limitations.
  308. It is kept for compatibility but should not be used in new projects.
  309. View Help
  310. =========
  311. To print selected pages from the CMake documentation, use
  312. .. code-block:: shell
  313. cmake --help[-<topic>]
  314. with one of the following options:
  315. .. include:: OPTIONS_HELP.txt
  316. See Also
  317. ========
  318. .. include:: LINKS.txt