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.

403 lines
12 KiB

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