cmake.1.rst 12 KB

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