index.rst 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. User Interaction Guide
  2. **********************
  3. .. only:: html
  4. .. contents::
  5. Introduction
  6. ============
  7. Where a software package supplies a CMake-based buildsystem
  8. with the source of their software, the consumer of the
  9. software is required to run a CMake user interaction tool
  10. in order to build it.
  11. Well-behaved CMake-based buildsystems do not create any
  12. output in the source directory, so typically, the user
  13. performs an out-of-source build and performs the build
  14. there. First, CMake must be instructed to generate a
  15. suitable buildsystem, then the user invokes a build tool
  16. to process that generated buildsystem. The generated
  17. buildsystem is specific to the machine used to generate
  18. it and is not redistributable. Each consumer of a provided
  19. source software package is required to use CMake to
  20. generate a buildsystem specific to their system.
  21. Generated buildsystems should generally be treated as
  22. read-only. The CMake files as a primary artifact should
  23. completely specify the buildsystem and there should be no
  24. reason to populate properties manually in an IDE for
  25. example after generating the buildsystem. CMake will
  26. periodically rewrite the generated buildsystem, so
  27. modifications by users will be overwritten.
  28. The features and user interfaces described in this manual
  29. are available for all CMake-based build systems by virtue
  30. of providing CMake files.
  31. The CMake tooling may report errors to the user when
  32. processing provided CMake files, such as reporting that
  33. the compiler is not supported, or the compiler does not
  34. support a required compile option, or a dependency can
  35. not be found. These errors must be resolved by the user
  36. by choosing a different compiler,
  37. :guide:`installing dependencies <Using Dependencies Guide>`,
  38. or instructing CMake where to find them, etc.
  39. Command Line cmake tool
  40. -----------------------
  41. A simple but typical use of :manual:`cmake(1)` with a fresh
  42. copy of software source code is to create a build directory
  43. and invoke cmake there:
  44. .. code-block:: console
  45. $ cd some_software-1.4.2
  46. $ mkdir build
  47. $ cd build
  48. $ cmake .. -DCMAKE_INSTALL_PREFIX=/opt/the/prefix
  49. $ cmake --build .
  50. $ cmake --build . --target install
  51. It is recommended to build in a separate directory to the
  52. source because that keeps the source directory pristine,
  53. allows for building a single source with multiple
  54. toolchains, and allows easy clearing of build artifacts by
  55. simply deleting the build directory.
  56. The CMake tooling may report warnings which are intended
  57. for the provider of the software, not intended for the
  58. consumer of the software. Such warnings end with "This
  59. warning is for project developers". Users may disable
  60. such warnings by passing the :option:`-Wno-dev <cmake -Wno-dev>`
  61. flag to :manual:`cmake(1)`.
  62. cmake-gui tool
  63. --------------
  64. Users more accustomed to GUI interfaces may use the
  65. :manual:`cmake-gui(1)` tool to invoke CMake and generate
  66. a buildsystem.
  67. The source and binary directories must first be
  68. populated. It is always advised to use different
  69. directories for the source and the build.
  70. .. image:: GUI-Source-Binary.png
  71. :alt: Choosing source and binary directories
  72. Generating a Buildsystem
  73. ========================
  74. There are several user interface tools which may be used
  75. to generate a buildsystem from CMake files. The
  76. :manual:`ccmake(1)` and :manual:`cmake-gui(1)` tools guide
  77. the user through setting the various necessary options.
  78. The :manual:`cmake(1)` tool can be invoked to specify
  79. options on the command line. This manual describes options
  80. which may be set using any of the user interface tools,
  81. though the mode of setting an option is different for each
  82. tool.
  83. Command line environment
  84. ------------------------
  85. When invoking :manual:`cmake(1)` with a command line
  86. buildsystem such as ``Makefiles`` or ``Ninja``, it is
  87. necessary to use the correct build environment to
  88. ensure that build tools are available. CMake must be
  89. able to find the appropriate
  90. :variable:`build tool <CMAKE_MAKE_PROGRAM>`,
  91. compiler, linker and other tools as needed.
  92. On Linux systems, the appropriate tools are often
  93. provided in system-wide locations and may be readily
  94. installed through the system package manager. Other
  95. toolchains provided by the user or installed in
  96. non-default locations can also be used.
  97. When cross-compiling, some platforms may require
  98. environment variables to be set or may provide
  99. scripts to set the environment.
  100. Visual Studio ships multiple command prompts and
  101. ``vcvarsall.bat`` scripts for setting up the
  102. correct environments for command line buildsystems. While
  103. not strictly necessary to use a corresponding
  104. command line environment when using a Visual Studio
  105. generator, doing so has no disadvantages.
  106. When using :generator:`Xcode`, there can be more than one Xcode
  107. version installed. Which one to use can be selected
  108. in a number of different ways, but the most common
  109. methods are:
  110. * Setting the default version in the preferences
  111. of the Xcode IDE.
  112. * Setting the default version via the ``xcode-select``
  113. command line tool.
  114. * Overriding the default version by setting the
  115. ``DEVELOPER_DIR`` environment variable when running
  116. CMake and the build tool.
  117. For convenience, :manual:`cmake-gui(1)` provides an
  118. environment variable editor.
  119. Command line ``-G`` option
  120. --------------------------
  121. CMake chooses a generator by default based on the
  122. platform. Usually, the default generator is sufficient
  123. to allow the user to proceed to build the software.
  124. The user may override the default generator with
  125. the :option:`-G <cmake -G>` option:
  126. .. code-block:: console
  127. $ cmake .. -G Ninja
  128. The output of :option:`cmake --help` includes a list of
  129. :manual:`generators <cmake-generators(7)>` available
  130. for the user to choose from. Note that generator
  131. names are case sensitive.
  132. On Unix-like systems (including Mac OS X), the
  133. :generator:`Unix Makefiles` generator is used by
  134. default. A variant of that generator can also be used
  135. on Windows in various environments, such as the
  136. :generator:`NMake Makefiles` and
  137. :generator:`MinGW Makefiles` generator. These generators
  138. generate a ``Makefile`` variant which can be executed
  139. with ``make``, ``gmake``, ``nmake`` or similar tools.
  140. See the individual generator documentation for more
  141. information on targeted environments and tools.
  142. The :generator:`Ninja` generator is available on all
  143. major platforms. ``ninja`` is a build tool similar
  144. in use-cases to ``make``, but with a focus on
  145. performance and efficiency.
  146. On Windows, :manual:`cmake(1)` can be used to generate
  147. solutions for the Visual Studio IDE. Visual Studio
  148. versions may be specified by the product name of the
  149. IDE, which includes a four-digit year. Aliases are
  150. provided for other means by which Visual Studio
  151. versions are sometimes referred to, such as two
  152. digits which correspond to the product version of the
  153. VisualC++ compiler, or a combination of the two:
  154. .. code-block:: console
  155. $ cmake .. -G "Visual Studio 2019"
  156. $ cmake .. -G "Visual Studio 16"
  157. $ cmake .. -G "Visual Studio 16 2019"
  158. :ref:`Visual Studio Generators` can target different architectures.
  159. One can specify the target architecture using the
  160. :option:`-A <cmake -A>` option:
  161. .. code-block:: console
  162. cmake .. -G "Visual Studio 2019" -A x64
  163. cmake .. -G "Visual Studio 16" -A ARM
  164. cmake .. -G "Visual Studio 16 2019" -A ARM64
  165. On Apple, the :generator:`Xcode` generator may be used to
  166. generate project files for the Xcode IDE.
  167. Some IDEs such as KDevelop4, QtCreator and CLion have
  168. native support for CMake-based buildsystems. Those IDEs
  169. provide user interface for selecting an underlying
  170. generator to use, typically a choice between a ``Makefile``
  171. or a ``Ninja`` based generator.
  172. Note that it is not possible to change the generator
  173. with :option:`-G <cmake -G>` after the first invocation of CMake.
  174. To change the generator, the build directory must be
  175. deleted and the build must be started from scratch.
  176. When generating Visual Studio project and solutions
  177. files several other options are available to use when
  178. initially running :manual:`cmake(1)`.
  179. The Visual Studio toolset can be specified with the
  180. :option:`cmake -T` option:
  181. .. code-block:: console
  182. $ # Build with the clang-cl toolset
  183. $ cmake.exe .. -G "Visual Studio 16 2019" -A x64 -T ClangCL
  184. $ # Build targeting Windows XP
  185. $ cmake.exe .. -G "Visual Studio 16 2019" -A x64 -T v120_xp
  186. Whereas the :option:`-A <cmake -A>` option specifies the _target_
  187. architecture, the :option:`-T <cmake -T>` option can be used to specify
  188. details of the toolchain used. For example, ``-Thost=x64``
  189. can be given to select the 64-bit version of the host
  190. tools. The following demonstrates how to use 64-bit
  191. tools and also build for a 64-bit target architecture:
  192. .. code-block:: console
  193. $ cmake .. -G "Visual Studio 16 2019" -A x64 -Thost=x64
  194. Choosing a generator in cmake-gui
  195. ---------------------------------
  196. The "Configure" button triggers a new dialog to
  197. select the CMake generator to use.
  198. .. image:: GUI-Configure-Dialog.png
  199. :alt: Configuring a generator
  200. All generators available on the command line are also
  201. available in :manual:`cmake-gui(1)`.
  202. .. image:: GUI-Choose-Generator.png
  203. :alt: Choosing a generator
  204. When choosing a Visual Studio generator, further options
  205. are available to set an architecture to generate for.
  206. .. image:: VS-Choose-Arch.png
  207. :alt: Choosing an architecture for Visual Studio generators
  208. .. _`Setting Build Variables`:
  209. Setting Build Variables
  210. =======================
  211. Software projects often require variables to be
  212. set on the command line when invoking CMake. Some of
  213. the most commonly used CMake variables are listed in
  214. the table below:
  215. ========================================== ============================================================
  216. Variable Meaning
  217. ========================================== ============================================================
  218. :variable:`CMAKE_PREFIX_PATH` Path to search for
  219. :guide:`dependent packages <Using Dependencies Guide>`
  220. :variable:`CMAKE_MODULE_PATH` Path to search for additional CMake modules
  221. :variable:`CMAKE_BUILD_TYPE` Build configuration, such as
  222. ``Debug`` or ``Release``, determining
  223. debug/optimization flags. This is only
  224. relevant for single-configuration buildsystems such
  225. as :ref:`Makefile Generators` and
  226. :ref:`Ninja Generators`.
  227. Multi-configuration buildsystems such as those for
  228. :ref:`Visual Studio Generators` and :generator:`Xcode`
  229. ignore this setting.
  230. :variable:`CMAKE_INSTALL_PREFIX` Location to install the
  231. software to with the
  232. ``install`` build target
  233. :variable:`CMAKE_TOOLCHAIN_FILE` File containing cross-compiling
  234. data such as
  235. :manual:`toolchains and sysroots <cmake-toolchains(7)>`.
  236. :variable:`BUILD_SHARED_LIBS` Whether to build shared
  237. instead of static libraries
  238. for :command:`add_library`
  239. commands used without a type
  240. :variable:`CMAKE_EXPORT_COMPILE_COMMANDS` Generate a ``compile_commands.json``
  241. file for use with clang-based tools
  242. :variable:`CMAKE_EXPORT_BUILD_DATABASE` Generate a ``build_database.json``
  243. file for use with clang-based tools
  244. ========================================== ============================================================
  245. Other project-specific variables may be available
  246. to control builds, such as enabling or disabling
  247. components of the project.
  248. There is no convention provided by CMake for how
  249. such variables are named between different
  250. provided buildsystems, except that variables with
  251. the prefix ``CMAKE_`` usually refer to options
  252. provided by CMake itself and should not be used
  253. in third-party options, which should use
  254. their own prefix instead. The
  255. :manual:`cmake-gui(1)` tool can display options
  256. in groups defined by their prefix, so it makes
  257. sense for third parties to ensure that they use a
  258. self-consistent prefix.
  259. Setting variables on the command line
  260. -------------------------------------
  261. CMake variables can be set on the command line either
  262. when creating the initial build:
  263. .. code-block:: console
  264. $ mkdir build
  265. $ cd build
  266. $ cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Debug
  267. or later on a subsequent invocation of
  268. :manual:`cmake(1)`:
  269. .. code-block:: console
  270. $ cd build
  271. $ cmake . -DCMAKE_BUILD_TYPE=Debug
  272. The :option:`-U <cmake -U>` flag may be used to unset variables
  273. on the :manual:`cmake(1)` command line:
  274. .. code-block:: console
  275. $ cd build
  276. $ cmake . -UMyPackage_DIR
  277. A CMake buildsystem which was initially created
  278. on the command line can be modified using the
  279. :manual:`cmake-gui(1)` and vice-versa.
  280. The :manual:`cmake(1)` tool allows specifying a
  281. file to use to populate the initial cache using
  282. the :option:`-C <cmake -C>` option. This can be useful to simplify
  283. commands and scripts which repeatedly require the
  284. same cache entries.
  285. Setting variables with cmake-gui
  286. --------------------------------
  287. Variables may be set in the cmake-gui using the "Add Entry"
  288. button. This triggers a new dialog to set the value of
  289. the variable.
  290. .. image:: GUI-Add-Entry.png
  291. :alt: Editing a cache entry
  292. The main view of the :manual:`cmake-gui(1)` user interface
  293. can be used to edit existing variables.
  294. The CMake Cache
  295. ---------------
  296. When CMake is executed, it needs to find the locations of
  297. compilers, tools and dependencies. It also needs to be
  298. able to consistently re-generate a buildsystem to use the
  299. same compile/link flags and paths to dependencies. Such
  300. parameters are also required to be configurable by the
  301. user because they are paths and options specific to the
  302. users system.
  303. When it is first executed, CMake generates a
  304. ``CMakeCache.txt`` file in the build directory containing
  305. key-value pairs for such artifacts. The cache file can be
  306. viewed or edited by the user by running the
  307. :manual:`cmake-gui(1)` or :manual:`ccmake(1)` tool. The
  308. tools provide an interactive interface for re-configuring
  309. the provided software and re-generating the buildsystem,
  310. as is needed after editing cached values. Each cache
  311. entry may have an associated short help text which is
  312. displayed in the user interface tools.
  313. The cache entries may also have a type to signify how it
  314. should be presented in the user interface. For example,
  315. a cache entry of type ``BOOL`` can be edited by a
  316. checkbox in a user interface, a ``STRING`` can be edited
  317. in a text field, and a ``FILEPATH`` while similar to a
  318. ``STRING`` should also provide a way to locate filesystem
  319. paths using a file dialog. An entry of type ``STRING``
  320. may provide a restricted list of allowed values which are
  321. then provided in a drop-down menu in the
  322. :manual:`cmake-gui(1)` user interface (see the
  323. :prop_cache:`STRINGS` cache property).
  324. The CMake files shipped with a software package may also
  325. define boolean toggle options using the :command:`option`
  326. command. The command creates a cache entry which has a
  327. help text and a default value. Such cache entries are
  328. typically specific to the provided software and affect
  329. the configuration of the build, such as whether tests
  330. and examples are built, whether to build with exceptions
  331. enabled etc.
  332. Presets
  333. =======
  334. CMake understands a file, ``CMakePresets.json``, and its
  335. user-specific counterpart, ``CMakeUserPresets.json``, for
  336. saving presets for commonly-used configure settings. These
  337. presets can set the build directory, generator, cache
  338. variables, environment variables, and other command-line
  339. options. All of these options can be overridden by the
  340. user. The full details of the ``CMakePresets.json`` format
  341. are listed in the :manual:`cmake-presets(7)` manual.
  342. Using presets on the command-line
  343. ---------------------------------
  344. When using the :manual:`cmake(1)` command line tool, a
  345. preset can be invoked by using the :option:`--preset <cmake --preset>`
  346. option. If :option:`--preset <cmake --preset>` is specified,
  347. the generator and build directory are not required, but can be
  348. specified to override them. For example, if you have the following
  349. ``CMakePresets.json`` file:
  350. .. code-block:: json
  351. {
  352. "version": 1,
  353. "configurePresets": [
  354. {
  355. "name": "ninja-release",
  356. "binaryDir": "${sourceDir}/build/${presetName}",
  357. "generator": "Ninja",
  358. "cacheVariables": {
  359. "CMAKE_BUILD_TYPE": "Release"
  360. }
  361. }
  362. ]
  363. }
  364. and you run the following:
  365. .. code-block:: console
  366. cmake -S /path/to/source --preset=ninja-release
  367. This will generate a build directory in
  368. ``/path/to/source/build/ninja-release`` with the
  369. :generator:`Ninja` generator, and with
  370. :variable:`CMAKE_BUILD_TYPE` set to ``Release``.
  371. If you want to see the list of available presets, you can
  372. run:
  373. .. code-block:: console
  374. cmake -S /path/to/source --list-presets
  375. This will list the presets available in
  376. ``/path/to/source/CMakePresets.json`` and
  377. ``/path/to/source/CMakeUsersPresets.json`` without
  378. generating a build tree.
  379. Using presets in cmake-gui
  380. --------------------------
  381. If a project has presets available, either through
  382. ``CMakePresets.json`` or ``CMakeUserPresets.json``, the
  383. list of presets will appear in a drop-down menu in
  384. :manual:`cmake-gui(1)` between the source directory and
  385. the binary directory. Choosing a preset sets the binary
  386. directory, generator, environment variables, and cache
  387. variables, but all of these options can be overridden after
  388. a preset is selected.
  389. Invoking the Buildsystem
  390. ========================
  391. After generating the buildsystem, the software can be
  392. built by invoking the particular build tool. In the
  393. case of the IDE generators, this can involve loading
  394. the generated project file into the IDE to invoke the
  395. build.
  396. CMake is aware of the specific build tool needed to invoke
  397. a build so in general, to build a buildsystem or project
  398. from the command line after generating, the following
  399. command may be invoked in the build directory:
  400. .. code-block:: console
  401. $ cmake --build .
  402. The :option:`--build <cmake --build>` flag enables a
  403. particular mode of operation for the :manual:`cmake(1)`
  404. tool. It invokes the :variable:`CMAKE_MAKE_PROGRAM`
  405. command associated with the
  406. :manual:`generator <cmake-generators(7)>`, or
  407. the build tool configured by the user.
  408. The :option:`--build <cmake --build>` mode also accepts
  409. the parameter :option:`--target <cmake--build --target>` to
  410. specify a particular target to build, for example a
  411. particular library, executable or custom target, or a
  412. particular special target like ``install``:
  413. .. code-block:: console
  414. $ cmake --build . --target myexe
  415. The :option:`--build <cmake --build>` mode also accepts a
  416. :option:`--config <cmake--build --config>` parameter
  417. in the case of multi-config generators to specify which
  418. particular configuration to build:
  419. .. code-block:: console
  420. $ cmake --build . --target myexe --config Release
  421. The :option:`--config <cmake--build --config>` option has no
  422. effect if the generator generates a buildsystem specific
  423. to a configuration which is chosen when invoking cmake
  424. with the :variable:`CMAKE_BUILD_TYPE` variable.
  425. Some buildsystems omit details of command lines invoked
  426. during the build. The :option:`--verbose <cmake--build --verbose>`
  427. flag can be used to cause those command lines to be shown:
  428. .. code-block:: console
  429. $ cmake --build . --target myexe --verbose
  430. The :option:`--build <cmake --build>` mode can also pass
  431. particular command line options to the underlying build
  432. tool by listing them after ``--``. This can be useful
  433. to specify options to the build tool, such as to continue the
  434. build after a failed job, where CMake does not
  435. provide a high-level user interface.
  436. For all generators, it is possible to run the underlying
  437. build tool after invoking CMake. For example, ``make``
  438. may be executed after generating with the
  439. :generator:`Unix Makefiles` generator to invoke the build,
  440. or ``ninja`` after generating with the :generator:`Ninja`
  441. generator etc. The IDE buildsystems usually provide
  442. command line tooling for building a project which can
  443. also be invoked.
  444. Selecting a Target
  445. ------------------
  446. Each executable and library described in the CMake files
  447. is a build target, and the buildsystem may describe
  448. custom targets, either for internal use, or for user
  449. consumption, for example to create documentation.
  450. CMake provides some built-in targets for all buildsystems
  451. providing CMake files.
  452. ``all``
  453. The default target used by :ref:`Makefile Generators`
  454. and :ref:`Ninja Generators`. Builds all targets in
  455. the buildsystem, except those which are excluded by
  456. their :prop_tgt:`EXCLUDE_FROM_ALL` target property or
  457. :prop_dir:`EXCLUDE_FROM_ALL` directory property. The
  458. name ``ALL_BUILD`` is used for this purpose for the
  459. :generator:`Xcode` and :ref:`Visual Studio Generators`.
  460. ``help``
  461. Lists the targets available for build. This target is
  462. available when using the :ref:`Makefile Generators` or
  463. :ref:`Ninja Generators`, and the exact output is
  464. tool-specific.
  465. ``clean``
  466. Delete built object files and other output files. The
  467. :ref:`Makefile Generators` create a ``clean`` target
  468. per directory, so that an individual directory can be
  469. cleaned. The ``Ninja`` tool provides its own granular
  470. ``-t clean`` system.
  471. ``test``
  472. Runs tests. This target is only automatically available
  473. if the CMake files provide CTest-based tests. See also
  474. `Running Tests`_.
  475. ``install``
  476. Installs the software. This target is only automatically
  477. available if the software defines install rules with the
  478. :command:`install` command. See also
  479. `Software Installation`_.
  480. ``package``
  481. Creates a binary package. This target is only
  482. automatically available if the CMake files provide
  483. CPack-based packages.
  484. ``package_source``
  485. Creates a source package. This target is only
  486. automatically available if the CMake files provide
  487. CPack-based packages.
  488. For :ref:`Makefile Generators`, ``/fast`` variants of binary
  489. build targets are provided. The ``/fast`` variants are used
  490. to build the specified target without regard for its
  491. dependencies. The dependencies are not checked and
  492. are not rebuilt if out of date. The :ref:`Ninja Generators`
  493. are sufficiently fast at dependency checking that
  494. such targets are not provided for that generator.
  495. :ref:`Makefile Generators` also provide build-targets to
  496. preprocess, assemble and compile individual files in a
  497. particular directory.
  498. .. code-block:: console
  499. $ make foo.cpp.i
  500. $ make foo.cpp.s
  501. $ make foo.cpp.o
  502. The file extension is built into the name of the target
  503. because another file with the same name but a different
  504. extension may exist. However, build-targets without the
  505. file extension are also provided.
  506. .. code-block:: console
  507. $ make foo.i
  508. $ make foo.s
  509. $ make foo.o
  510. In buildsystems which contain ``foo.c`` and ``foo.cpp``,
  511. building the ``foo.i`` target will preprocess both files.
  512. Specifying a Build Program
  513. --------------------------
  514. The program invoked by the :option:`--build <cmake --build>`
  515. mode is determined by the :variable:`CMAKE_MAKE_PROGRAM` variable.
  516. For most generators, the particular program does not need to be
  517. configured.
  518. ===================== =========================== ===========================
  519. Generator Default make program Alternatives
  520. ===================== =========================== ===========================
  521. XCode ``xcodebuild``
  522. Unix Makefiles ``make``
  523. NMake Makefiles ``nmake`` ``jom``
  524. NMake Makefiles JOM ``jom`` ``nmake``
  525. MinGW Makefiles ``mingw32-make``
  526. MSYS Makefiles ``make``
  527. Ninja ``ninja``
  528. Visual Studio ``msbuild``
  529. Watcom WMake ``wmake``
  530. ===================== =========================== ===========================
  531. The ``jom`` tool is capable of reading makefiles of the
  532. ``NMake`` flavor and building in parallel, while the
  533. ``nmake`` tool always builds serially. After generating
  534. with the :generator:`NMake Makefiles` generator a user
  535. can run ``jom`` instead of ``nmake``. The
  536. :option:`--build <cmake --build>`
  537. mode would also use ``jom`` if the
  538. :variable:`CMAKE_MAKE_PROGRAM` was set to ``jom`` while
  539. using the :generator:`NMake Makefiles` generator, and
  540. as a convenience, the :generator:`NMake Makefiles JOM`
  541. generator is provided to find ``jom`` in the normal way
  542. and use it as the :variable:`CMAKE_MAKE_PROGRAM`. For
  543. completeness, ``nmake`` is an alternative tool which
  544. can process the output of the
  545. :generator:`NMake Makefiles JOM` generator, but doing
  546. so would be a pessimization.
  547. Software Installation
  548. =====================
  549. The :variable:`CMAKE_INSTALL_PREFIX` variable can be
  550. set in the CMake cache to specify where to install the
  551. provided software. If the provided software has install
  552. rules, specified using the :command:`install` command,
  553. they will install artifacts into that prefix. On Windows,
  554. the default installation location corresponds to the
  555. ``ProgramFiles`` system directory which may be
  556. architecture specific. On Unix hosts, ``/usr/local`` is
  557. the default installation location.
  558. The :variable:`CMAKE_INSTALL_PREFIX` variable always
  559. refers to the installation prefix on the target
  560. filesystem.
  561. In cross-compiling or packaging scenarios where the
  562. sysroot is read-only or where the sysroot should otherwise
  563. remain pristine, the :variable:`CMAKE_STAGING_PREFIX`
  564. variable can be set to a location to actually install
  565. the files.
  566. The commands:
  567. .. code-block:: console
  568. $ cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local \
  569. -DCMAKE_SYSROOT=$HOME/root \
  570. -DCMAKE_STAGING_PREFIX=/tmp/package
  571. $ cmake --build .
  572. $ cmake --build . --target install
  573. result in files being installed to paths such
  574. as ``/tmp/package/lib/libfoo.so`` on the host machine.
  575. The ``/usr/local`` location on the host machine is
  576. not affected.
  577. Some provided software may specify ``uninstall`` rules,
  578. but CMake does not generate such rules by default itself.
  579. Running Tests
  580. =============
  581. The :manual:`ctest(1)` tool is shipped with the CMake
  582. distribution to execute provided tests and report
  583. results. The ``test`` build-target is provided to run
  584. all available tests, but the :manual:`ctest(1)` tool
  585. allows granular control over which tests to run, how to
  586. run them, and how to report results. Executing
  587. :manual:`ctest(1)` in the build directory is equivalent
  588. to running the ``test`` target:
  589. .. code-block:: console
  590. $ ctest
  591. A regular expression can be passed to run only tests
  592. which match the expression. To run only tests with
  593. ``Qt`` in their name:
  594. .. code-block:: console
  595. $ ctest -R Qt
  596. Tests can be excluded by regular expression too. To
  597. run only tests without ``Qt`` in their name:
  598. .. code-block:: console
  599. $ ctest -E Qt
  600. Tests can be run in parallel by passing :option:`-j <ctest -j>`
  601. arguments to :manual:`ctest(1)`:
  602. .. code-block:: console
  603. $ ctest -R Qt -j8
  604. The environment variable :envvar:`CTEST_PARALLEL_LEVEL`
  605. can alternatively be set to avoid the need to pass
  606. :option:`-j <ctest -j>`.
  607. By default :manual:`ctest(1)` does not print the output
  608. from the tests. The command line argument :option:`-V <ctest -V>`
  609. (or ``--verbose``) enables verbose mode to print the
  610. output from all tests.
  611. The :option:`--output-on-failure <ctest --output-on-failure>`
  612. option prints the test output for failing tests only.
  613. The environment variable :envvar:`CTEST_OUTPUT_ON_FAILURE`
  614. can be set to ``1`` as an alternative to passing the
  615. :option:`--output-on-failure <ctest --output-on-failure>`
  616. option to :manual:`ctest(1)`.