index.rst 24 KB

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