cmake-presets.7.rst 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  1. .. cmake-manual-description: CMakePresets.json
  2. cmake-presets(7)
  3. ****************
  4. .. only:: html
  5. .. contents::
  6. Introduction
  7. ============
  8. One problem that CMake users often face is sharing settings with other people
  9. for common ways to configure a project. This may be done to support CI builds,
  10. or for users who frequently use the same build. CMake supports two files,
  11. ``CMakePresets.json`` and ``CMakeUserPresets.json``, that allow users to
  12. specify common configure options and share them with others.
  13. ``CMakePresets.json`` and ``CMakeUserPresets.json`` live in the project's root
  14. directory. They both have exactly the same format, and both are optional
  15. (though at least one must be present if ``--preset`` is specified.)
  16. ``CMakePresets.json`` is meant to save project-wide builds, while
  17. ``CMakeUserPresets.json`` is meant for developers to save their own local
  18. builds. ``CMakePresets.json`` may be checked into a version control system, and
  19. ``CMakeUserPresets.json`` should NOT be checked in. For example, if a project
  20. is using Git, ``CMakePresets.json`` may be tracked, and
  21. ``CMakeUserPresets.json`` should be added to the ``.gitignore``.
  22. Format
  23. ======
  24. The files are a JSON document with an object as the root:
  25. .. literalinclude:: presets/example.json
  26. :language: json
  27. The root object recognizes the following fields:
  28. ``version``
  29. A required integer representing the version of the JSON schema.
  30. The supported versions are ``1``, ``2``, and ``3``.
  31. ``cmakeMinimumRequired``
  32. An optional object representing the minimum version of CMake needed to
  33. build this project. This object consists of the following fields:
  34. ``major``
  35. An optional integer representing the major version.
  36. ``minor``
  37. An optional integer representing the minor version.
  38. ``patch``
  39. An optional integer representing the patch version.
  40. ``vendor``
  41. An optional map containing vendor-specific information. CMake does not
  42. interpret the contents of this field except to verify that it is a map if
  43. it does exist. However, the keys should be a vendor-specific domain name
  44. followed by a ``/``-separated path. For example, the Example IDE 1.0 could
  45. use ``example.com/ExampleIDE/1.0``. The value of each field can be anything
  46. desired by the vendor, though will typically be a map.
  47. ``configurePresets``
  48. An optional array of `Configure Preset`_ objects.
  49. This is allowed in preset files specifying version ``1`` or above.
  50. ``buildPresets``
  51. An optional array of `Build Preset`_ objects.
  52. This is allowed in preset files specifying version ``2`` or above.
  53. ``testPresets``
  54. An optional array of `Test Preset`_ objects.
  55. This is allowed in preset files specifying version ``2`` or above.
  56. Configure Preset
  57. ^^^^^^^^^^^^^^^^
  58. Each entry of the ``configurePresets`` array is a JSON object
  59. that may contain the following fields:
  60. ``name``
  61. A required string representing the machine-friendly name of the preset.
  62. This identifier is used in the :ref:`cmake --preset <CMake Options>` option.
  63. There must not be two configure presets in the union of ``CMakePresets.json``
  64. and ``CMakeUserPresets.json`` in the same directory with the same name.
  65. However, a configure preset may have the same name as a build or test preset.
  66. ``hidden``
  67. An optional boolean specifying whether or not a preset should be hidden.
  68. If a preset is hidden, it cannot be used in the ``--preset=`` argument,
  69. will not show up in the :manual:`CMake GUI <cmake-gui(1)>`, and does not
  70. have to have a valid ``generator`` or ``binaryDir``, even from
  71. inheritance. ``hidden`` presets are intended to be used as a base for
  72. other presets to inherit via the ``inherits`` field.
  73. ``inherits``
  74. An optional array of strings representing the names of presets to inherit
  75. from. The preset will inherit all of the fields from the ``inherits``
  76. presets by default (except ``name``, ``hidden``, ``inherits``,
  77. ``description``, and ``displayName``), but can override them as
  78. desired. If multiple ``inherits`` presets provide conflicting values for
  79. the same field, the earlier preset in the ``inherits`` list will be
  80. preferred. Presets in ``CMakePresets.json`` may not inherit from presets
  81. in ``CMakeUserPresets.json``.
  82. This field can also be a string, which is equivalent to an array
  83. containing one string.
  84. ``condition``
  85. An optional `Condition`_ object. This is allowed in preset files specifying
  86. version ``3`` or above.
  87. ``vendor``
  88. An optional map containing vendor-specific information. CMake does not
  89. interpret the contents of this field except to verify that it is a map
  90. if it does exist. However, it should follow the same conventions as the
  91. root-level ``vendor`` field. If vendors use their own per-preset
  92. ``vendor`` field, they should implement inheritance in a sensible manner
  93. when appropriate.
  94. ``displayName``
  95. An optional string with a human-friendly name of the preset.
  96. ``description``
  97. An optional string with a human-friendly description of the preset.
  98. ``generator``
  99. An optional string representing the generator to use for the preset. If
  100. ``generator`` is not specified, it must be inherited from the
  101. ``inherits`` preset (unless this preset is ``hidden``). In version ``3``
  102. or above, this field may be omitted to fall back to regular generator
  103. discovery procedure.
  104. Note that for Visual Studio generators, unlike in the command line ``-G``
  105. argument, you cannot include the platform name in the generator name. Use
  106. the ``architecture`` field instead.
  107. ``architecture``, ``toolset``
  108. Optional fields representing the platform and toolset, respectively, for
  109. generators that support them. Each may be either a string or an object
  110. with the following fields:
  111. ``value``
  112. An optional string representing the value.
  113. ``strategy``
  114. An optional string telling CMake how to handle the ``architecture`` or
  115. ``toolset`` field. Valid values are:
  116. ``"set"``
  117. Set the respective value. This will result in an error for generators
  118. that do not support the respective field.
  119. ``"external"``
  120. Do not set the value, even if the generator supports it. This is
  121. useful if, for example, a preset uses the Ninja generator, and an IDE
  122. knows how to set up the Visual C++ environment from the
  123. ``architecture`` and ``toolset`` fields. In that case, CMake will
  124. ignore the field, but the IDE can use them to set up the environment
  125. before invoking CMake.
  126. ``toolchainFile``
  127. An optional string representing the path to the toolchain file.
  128. This field supports `macro expansion`_. If a relative path is specified,
  129. it is calculated relative to the build directory, and if not found,
  130. relative to the source directory. This field takes precedence over any
  131. :variable:`CMAKE_TOOLCHAIN_FILE` value. It is allowed in preset files
  132. specifying version ``3`` or above.
  133. ``binaryDir``
  134. An optional string representing the path to the output binary directory.
  135. This field supports `macro expansion`_. If a relative path is specified,
  136. it is calculated relative to the source directory. If ``binaryDir`` is not
  137. specified, it must be inherited from the ``inherits`` preset (unless this
  138. preset is ``hidden``). In version ``3`` or above, this field may be
  139. omitted.
  140. ``installDir``
  141. An optional string representing the path to the installation directory.
  142. This field supports `macro expansion`_. If a relative path is specified,
  143. it is calculated relative to the source directory. This is allowed in
  144. preset files specifying version ``3`` or above.
  145. ``cmakeExecutable``
  146. An optional string representing the path to the CMake executable to use
  147. for this preset. This is reserved for use by IDEs, and is not used by
  148. CMake itself. IDEs that use this field should expand any macros in it.
  149. ``cacheVariables``
  150. An optional map of cache variables. The key is the variable name (which
  151. may not be an empty string), and the value is either ``null``, a boolean
  152. (which is equivalent to a value of ``"TRUE"`` or ``"FALSE"`` and a type
  153. of ``BOOL``), a string representing the value of the variable (which
  154. supports `macro expansion`_), or an object with the following fields:
  155. ``type``
  156. An optional string representing the type of the variable.
  157. ``value``
  158. A required string or boolean representing the value of the variable.
  159. A boolean is equivalent to ``"TRUE"`` or ``"FALSE"``. This field
  160. supports `macro expansion`_.
  161. Cache variables are inherited through the ``inherits`` field, and the
  162. preset's variables will be the union of its own ``cacheVariables`` and
  163. the ``cacheVariables`` from all its parents. If multiple presets in this
  164. union define the same variable, the standard rules of ``inherits`` are
  165. applied. Setting a variable to ``null`` causes it to not be set, even if
  166. a value was inherited from another preset.
  167. ``environment``
  168. An optional map of environment variables. The key is the variable name
  169. (which may not be an empty string), and the value is either ``null`` or
  170. a string representing the value of the variable. Each variable is set
  171. regardless of whether or not a value was given to it by the process's
  172. environment. This field supports `macro expansion`_, and environment
  173. variables in this map may reference each other, and may be listed in any
  174. order, as long as such references do not cause a cycle (for example,
  175. if ``ENV_1`` is ``$env{ENV_2}``, ``ENV_2`` may not be ``$env{ENV_1}``.)
  176. Environment variables are inherited through the ``inherits`` field, and
  177. the preset's environment will be the union of its own ``environment`` and
  178. the ``environment`` from all its parents. If multiple presets in this
  179. union define the same variable, the standard rules of ``inherits`` are
  180. applied. Setting a variable to ``null`` causes it to not be set, even if
  181. a value was inherited from another preset.
  182. ``warnings``
  183. An optional object specifying the warnings to enable. The object may
  184. contain the following fields:
  185. ``dev``
  186. An optional boolean. Equivalent to passing ``-Wdev`` or ``-Wno-dev``
  187. on the command line. This may not be set to ``false`` if ``errors.dev``
  188. is set to ``true``.
  189. ``deprecated``
  190. An optional boolean. Equivalent to passing ``-Wdeprecated`` or
  191. ``-Wno-deprecated`` on the command line. This may not be set to
  192. ``false`` if ``errors.deprecated`` is set to ``true``.
  193. ``uninitialized``
  194. An optional boolean. Setting this to ``true`` is equivalent to passing
  195. ``--warn-uninitialized`` on the command line.
  196. ``unusedCli``
  197. An optional boolean. Setting this to ``false`` is equivalent to passing
  198. ``--no-warn-unused-cli`` on the command line.
  199. ``systemVars``
  200. An optional boolean. Setting this to ``true`` is equivalent to passing
  201. ``--check-system-vars`` on the command line.
  202. ``errors``
  203. An optional object specifying the errors to enable. The object may
  204. contain the following fields:
  205. ``dev``
  206. An optional boolean. Equivalent to passing ``-Werror=dev`` or
  207. ``-Wno-error=dev`` on the command line. This may not be set to ``true``
  208. if ``warnings.dev`` is set to ``false``.
  209. ``deprecated``
  210. An optional boolean. Equivalent to passing ``-Werror=deprecated`` or
  211. ``-Wno-error=deprecated`` on the command line. This may not be set to
  212. ``true`` if ``warnings.deprecated`` is set to ``false``.
  213. ``debug``
  214. An optional object specifying debug options. The object may contain the
  215. following fields:
  216. ``output``
  217. An optional boolean. Setting this to ``true`` is equivalent to passing
  218. ``--debug-output`` on the command line.
  219. ``tryCompile``
  220. An optional boolean. Setting this to ``true`` is equivalent to passing
  221. ``--debug-trycompile`` on the command line.
  222. ``find``
  223. An optional boolean. Setting this to ``true`` is equivalent to passing
  224. ``--debug-find`` on the command line.
  225. Build Preset
  226. ^^^^^^^^^^^^
  227. Each entry of the ``buildPresets`` array is a JSON object
  228. that may contain the following fields:
  229. ``name``
  230. A required string representing the machine-friendly name of the preset.
  231. This identifier is used in the
  232. :ref:`cmake --build --preset <Build Tool Mode>` option.
  233. There must not be two build presets in the union of ``CMakePresets.json``
  234. and ``CMakeUserPresets.json`` in the same directory with the same name.
  235. However, a build preset may have the same name as a configure or test preset.
  236. ``hidden``
  237. An optional boolean specifying whether or not a preset should be hidden.
  238. If a preset is hidden, it cannot be used in the ``--preset`` argument
  239. and does not have to have a valid ``configurePreset``, even from
  240. inheritance. ``hidden`` presets are intended to be used as a base for
  241. other presets to inherit via the ``inherits`` field.
  242. ``inherits``
  243. An optional array of strings representing the names of presets to
  244. inherit from. The preset will inherit all of the fields from the
  245. ``inherits`` presets by default (except ``name``, ``hidden``,
  246. ``inherits``, ``description``, and ``displayName``), but can override
  247. them as desired. If multiple ``inherits`` presets provide conflicting
  248. values for the same field, the earlier preset in the ``inherits`` list
  249. will be preferred. Presets in ``CMakePresets.json`` may not inherit from
  250. presets in ``CMakeUserPresets.json``.
  251. This field can also be a string, which is equivalent to an array
  252. containing one string.
  253. ``condition``
  254. An optional `Condition`_ object. This is allowed in preset files specifying
  255. version ``3`` or above.
  256. ``vendor``
  257. An optional map containing vendor-specific information. CMake does not
  258. interpret the contents of this field except to verify that it is a map
  259. if it does exist. However, it should follow the same conventions as the
  260. root-level ``vendor`` field. If vendors use their own per-preset
  261. ``vendor`` field, they should implement inheritance in a sensible manner
  262. when appropriate.
  263. ``displayName``
  264. An optional string with a human-friendly name of the preset.
  265. ``description``
  266. An optional string with a human-friendly description of the preset.
  267. ``environment``
  268. An optional map of environment variables. The key is the variable name
  269. (which may not be an empty string), and the value is either ``null`` or
  270. a string representing the value of the variable. Each variable is set
  271. regardless of whether or not a value was given to it by the process's
  272. environment. This field supports macro expansion, and environment
  273. variables in this map may reference each other, and may be listed in any
  274. order, as long as such references do not cause a cycle (for example, if
  275. ``ENV_1`` is ``$env{ENV_2}``, ``ENV_2`` may not be ``$env{ENV_1}``.)
  276. Environment variables are inherited through the ``inherits`` field, and
  277. the preset's environment will be the union of its own ``environment``
  278. and the ``environment`` from all its parents. If multiple presets in
  279. this union define the same variable, the standard rules of ``inherits``
  280. are applied. Setting a variable to ``null`` causes it to not be set,
  281. even if a value was inherited from another preset.
  282. .. note::
  283. For a CMake project using ExternalProject with a configuration preset
  284. having environment variables needed in the ExternalProject, use a build
  285. preset that inherits that configuration preset or the ExternalProject
  286. will not have the environment variables set in the configuration preset.
  287. Example: suppose the host defaults to one compiler (say Clang)
  288. and the user wishes to use another compiler (say GCC). Set configuration
  289. preset environment variables ``CC`` and ``CXX`` and use a build preset
  290. that inherits that configuration preset. Otherwise the ExternalProject
  291. may use a different (system default) compiler than the top-level CMake
  292. project.
  293. ``configurePreset``
  294. An optional string specifying the name of a configure preset to
  295. associate with this build preset. If ``configurePreset`` is not
  296. specified, it must be inherited from the inherits preset (unless this
  297. preset is hidden). The build directory is inferred from the configure
  298. preset, so the build will take place in the same ``binaryDir`` that the
  299. configuration did.
  300. ``inheritConfigureEnvironment``
  301. An optional boolean that defaults to true. If true, the environment
  302. variables from the associated configure preset are inherited after all
  303. inherited build preset environments, but before environment variables
  304. explicitly specified in this build preset.
  305. ``jobs``
  306. An optional integer. Equivalent to passing ``--parallel`` or ``-j`` on
  307. the command line.
  308. ``targets``
  309. An optional string or array of strings. Equivalent to passing
  310. ``--target`` or ``-t`` on the command line. Vendors may ignore the
  311. targets property or hide build presets that explicitly specify targets.
  312. This field supports macro expansion.
  313. ``configuration``
  314. An optional string. Equivalent to passing ``--config`` on the command
  315. line.
  316. ``cleanFirst``
  317. An optional bool. If true, equivalent to passing ``--clean-first`` on
  318. the command line.
  319. ``verbose``
  320. An optional bool. If true, equivalent to passing ``--verbose`` on the
  321. command line.
  322. ``nativeToolOptions``
  323. An optional array of strings. Equivalent to passing options after ``--``
  324. on the command line. The array values support macro expansion.
  325. Test Preset
  326. ^^^^^^^^^^^
  327. Each entry of the ``testPresets`` array is a JSON object
  328. that may contain the following fields:
  329. ``name``
  330. A required string representing the machine-friendly name of the preset.
  331. This identifier is used in the :ref:`ctest --preset <CTest Options>` option.
  332. There must not be two test presets in the union of ``CMakePresets.json``
  333. and ``CMakeUserPresets.json`` in the same directory with the same name.
  334. However, a test preset may have the same name as a configure or build preset.
  335. ``hidden``
  336. An optional boolean specifying whether or not a preset should be hidden.
  337. If a preset is hidden, it cannot be used in the ``--preset`` argument
  338. and does not have to have a valid ``configurePreset``, even from
  339. inheritance. ``hidden`` presets are intended to be used as a base for
  340. other presets to inherit via the ``inherits`` field.
  341. ``inherits``
  342. An optional array of strings representing the names of presets to
  343. inherit from. The preset will inherit all of the fields from the
  344. ``inherits`` presets by default (except ``name``, ``hidden``,
  345. ``inherits``, ``description``, and ``displayName``), but can override
  346. them as desired. If multiple ``inherits`` presets provide conflicting
  347. values for the same field, the earlier preset in the ``inherits`` list
  348. will be preferred. Presets in ``CMakePresets.json`` may not inherit from
  349. presets in ``CMakeUserPresets.json``.
  350. This field can also be a string, which is equivalent to an array
  351. containing one string.
  352. ``condition``
  353. An optional `Condition`_ object. This is allowed in preset files specifying
  354. version ``3`` or above.
  355. ``vendor``
  356. An optional map containing vendor-specific information. CMake does not
  357. interpret the contents of this field except to verify that it is a map
  358. if it does exist. However, it should follow the same conventions as the
  359. root-level ``vendor`` field. If vendors use their own per-preset
  360. ``vendor`` field, they should implement inheritance in a sensible manner
  361. when appropriate.
  362. ``displayName``
  363. An optional string with a human-friendly name of the preset.
  364. ``description``
  365. An optional string with a human-friendly description of the preset.
  366. ``environment``
  367. An optional map of environment variables. The key is the variable name
  368. (which may not be an empty string), and the value is either ``null`` or
  369. a string representing the value of the variable. Each variable is set
  370. regardless of whether or not a value was given to it by the process's
  371. environment. This field supports macro expansion, and environment
  372. variables in this map may reference each other, and may be listed in any
  373. order, as long as such references do not cause a cycle (for example, if
  374. ``ENV_1`` is ``$env{ENV_2}``, ``ENV_2`` may not be ``$env{ENV_1}``.)
  375. Environment variables are inherited through the ``inherits`` field, and
  376. the preset's environment will be the union of its own ``environment``
  377. and the ``environment`` from all its parents. If multiple presets in
  378. this union define the same variable, the standard rules of ``inherits``
  379. are applied. Setting a variable to ``null`` causes it to not be set,
  380. even if a value was inherited from another preset.
  381. ``configurePreset``
  382. An optional string specifying the name of a configure preset to
  383. associate with this test preset. If ``configurePreset`` is not
  384. specified, it must be inherited from the inherits preset (unless this
  385. preset is hidden). The build directory is inferred from the configure
  386. preset, so tests will run in the same ``binaryDir`` that the
  387. configuration did and build did.
  388. ``inheritConfigureEnvironment``
  389. An optional boolean that defaults to true. If true, the environment
  390. variables from the associated configure preset are inherited after all
  391. inherited test preset environments, but before environment variables
  392. explicitly specified in this test preset.
  393. ``configuration``
  394. An optional string. Equivalent to passing ``--build-config`` on the
  395. command line.
  396. ``overwriteConfigurationFile``
  397. An optional array of configuration options to overwrite options
  398. specified in the CTest configuration file. Equivalent to passing
  399. ``--overwrite`` for each value in the array. The array values
  400. support macro expansion.
  401. ``output``
  402. An optional object specifying output options. The object may contain the
  403. following fields.
  404. ``shortProgress``
  405. An optional bool. If true, equivalent to passing ``--progress`` on the
  406. command line.
  407. ``verbosity``
  408. An optional string specifying verbosity level. Must be one of the
  409. following:
  410. ``default``
  411. Equivalent to passing no verbosity flags on the command line.
  412. ``verbose``
  413. Equivalent to passing ``--verbose`` on the command line.
  414. ``extra``
  415. Equivalent to passing ``--extra-verbose`` on the command line.
  416. ``debug``
  417. An optional bool. If true, equivalent to passing ``--debug`` on the
  418. command line.
  419. ``outputOnFailure``
  420. An optional bool. If true, equivalent to passing
  421. ``--output-on-failure`` on the command line.
  422. ``quiet``
  423. An optional bool. If true, equivalent to passing ``--quiet`` on the
  424. command line.
  425. ``outputLogFile``
  426. An optional string specifying a path to a log file. Equivalent to
  427. passing ``--output-log`` on the command line. This field supports
  428. macro expansion.
  429. ``labelSummary``
  430. An optional bool. If false, equivalent to passing
  431. ``--no-label-summary`` on the command line.
  432. ``subprojectSummary``
  433. An optional bool. If false, equivalent to passing
  434. ``--no-subproject-summary`` on the command line.
  435. ``maxPassedTestOutputSize``
  436. An optional integer specifying the maximum output for passed tests in
  437. bytes. Equivalent to passing ``--test-output-size-passed`` on the
  438. command line.
  439. ``maxFailedTestOutputSize``
  440. An optional integer specifying the maximum output for failed tests in
  441. bytes. Equivalent to passing ``--test-output-size-failed`` on the
  442. command line.
  443. ``maxTestNameWidth``
  444. An optional integer specifying the maximum width of a test name to
  445. output. Equivalent to passing ``--max-width`` on the command line.
  446. ``filter``
  447. An optional object specifying how to filter the tests to run. The object
  448. may contain the following fields.
  449. ``include``
  450. An optional object specifying which tests to include. The object may
  451. contain the following fields.
  452. ``name``
  453. An optional string specifying a regex for test names. Equivalent to
  454. passing ``--tests-regex`` on the command line. This field supports
  455. macro expansion. CMake regex syntax is described under
  456. :ref:`string(REGEX) <Regex Specification>`.
  457. ``label``
  458. An optional string specifying a regex for test labels. Equivalent to
  459. passing ``--label-regex`` on the command line. This field supports
  460. macro expansion.
  461. ``useUnion``
  462. An optional bool. Equivalent to passing ``--union`` on the command
  463. line.
  464. ``index``
  465. An optional object specifying tests to include by test index. The
  466. object may contain the following fields. Can also be an optional
  467. string specifying a file with the command line syntax for
  468. ``--tests-information``. If specified as a string, this field
  469. supports macro expansion.
  470. ``start``
  471. An optional integer specifying a test index to start testing at.
  472. ``end``
  473. An optional integer specifying a test index to stop testing at.
  474. ``stride``
  475. An optional integer specifying the increment.
  476. ``specificTests``
  477. An optional array of integers specifying specific test indices to
  478. run.
  479. ``exclude``
  480. An optional object specifying which tests to exclude. The object may
  481. contain the following fields.
  482. ``name``
  483. An optional string specifying a regex for test names. Equivalent to
  484. passing ``--exclude-regex`` on the command line. This field supports
  485. macro expansion.
  486. ``label``
  487. An optional string specifying a regex for test labels. Equivalent to
  488. passing ``--label-exclude`` on the command line. This field supports
  489. macro expansion.
  490. ``fixtures``
  491. An optional object specifying which fixtures to exclude from adding
  492. tests. The object may contain the following fields.
  493. ``any``
  494. An optional string specifying a regex for text fixtures to exclude
  495. from adding any tests. Equivalent to ``--fixture-exclude-any`` on
  496. the command line. This field supports macro expansion.
  497. ``setup``
  498. An optional string specifying a regex for text fixtures to exclude
  499. from adding setup tests. Equivalent to ``--fixture-exclude-setup``
  500. on the command line. This field supports macro expansion.
  501. ``cleanup``
  502. An optional string specifying a regex for text fixtures to exclude
  503. from adding cleanup tests. Equivalent to
  504. ``--fixture-exclude-cleanup`` on the command line. This field
  505. supports macro expansion.
  506. ``execution``
  507. An optional object specifying options for test execution. The object may
  508. contain the following fields.
  509. ``stopOnFailure``
  510. An optional bool. If true, equivalent to passing ``--stop-on-failure``
  511. on the command line.
  512. ``enableFailover``
  513. An optional bool. If true, equivalent to passing ``-F`` on the command
  514. line.
  515. ``jobs``
  516. An optional integer. Equivalent to passing ``--parallel`` on the
  517. command line.
  518. ``resourceSpecFile``
  519. An optional string. Equivalent to passing ``--resource-spec-file`` on
  520. the command line. This field supports macro expansion.
  521. ``testLoad``
  522. An optional integer. Equivalent to passing ``--test-load`` on the
  523. command line.
  524. ``showOnly``
  525. An optional string. Equivalent to passing ``--show-only`` on the
  526. command line. The string must be one of the following values:
  527. ``human``
  528. ``json-v1``
  529. ``repeat``
  530. An optional object specifying how to repeat tests. Equivalent to
  531. passing ``--repeat`` on the command line. The object must have the
  532. following fields.
  533. ``mode``
  534. A required string. Must be one of the following values:
  535. ``until-fail``
  536. ``until-pass``
  537. ``after-timeout``
  538. ``count``
  539. A required integer.
  540. ``interactiveDebugging``
  541. An optional bool. If true, equivalent to passing
  542. ``--interactive-debug-mode 1`` on the command line. If false,
  543. equivalent to passing ``--interactive-debug-mode 0`` on the command
  544. line.
  545. ``scheduleRandom``
  546. An optional bool. If true, equivalent to passing ``--schedule-random``
  547. on the command line.
  548. ``timeout``
  549. An optional integer. Equivalent to passing ``--timeout`` on the
  550. command line.
  551. ``noTestsAction``
  552. An optional string specifying the behavior if no tests are found. Must
  553. be one of the following values:
  554. ``default``
  555. Equivalent to not passing any value on the command line.
  556. ``error``
  557. Equivalent to passing ``--no-tests=error`` on the command line.
  558. ``ignore``
  559. Equivalent to passing ``--no-tests=ignore`` on the command line.
  560. Condition
  561. ^^^^^^^^^
  562. The ``condition`` field of a preset, allowed in preset files specifying version
  563. ``3`` or above, is used to determine whether or not the preset is enabled. For
  564. example, this can be used to disable a preset on platforms other than Windows.
  565. ``condition`` may be either a boolean, ``null``, or an object. If it is a
  566. boolean, the boolean indicates whether the preset is enabled or disabled. If it
  567. is ``null``, the preset is enabled, but the ``null`` condition is not inherited
  568. by any presets that may inherit from the preset. Sub-conditions (for example in
  569. a ``not``, ``anyOf``, or ``allOf`` condition) may not be ``null``. If it is an
  570. object, it has the following fields:
  571. ``type``
  572. A required string with one of the following values:
  573. ``"const"``
  574. Indicates that the condition is constant. This is equivalent to using a
  575. boolean in place of the object. The condition object will have the
  576. following additional fields:
  577. ``value``
  578. A required boolean which provides a constant value for the condition's
  579. evaluation.
  580. ``"equals"``
  581. ``"notEquals"``
  582. Indicates that the condition compares two strings to see if they are equal
  583. (or not equal). The condition object will have the following additional
  584. fields:
  585. ``lhs``
  586. First string to compare. This field supports macro expansion.
  587. ``rhs``
  588. Second string to compare. This field supports macro expansion.
  589. ``"inList"``
  590. ``"notInList"``
  591. Indicates that the condition searches for a string in a list of strings.
  592. The condition object will have the following additional fields:
  593. ``string``
  594. A required string to search for. This field supports macro expansion.
  595. ``list``
  596. A required list of strings to search. This field supports macro
  597. expansion, and uses short-circuit evaluation.
  598. ``"matches"``
  599. ``"notMatches"``
  600. Indicates that the condition searches for a regular expression in a string.
  601. The condition object will have the following additional fields:
  602. ``string``
  603. A required string to search. This field supports macro expansion.
  604. ``regex``
  605. A required regular expression to search for. This field supports macro
  606. expansion.
  607. ``"anyOf"``
  608. ``"allOf"``
  609. Indicates that the condition is an aggregation of zero or more nested
  610. conditions. The condition object will have the following additional fields:
  611. ``conditions``
  612. A required array of condition objects. These conditions use short-circuit
  613. evaluation.
  614. ``"not"``
  615. Indicates that the condition is an inversion of another condition. The
  616. condition object will have the following additional fields:
  617. ``condition``
  618. A required condition object.
  619. Macro Expansion
  620. ^^^^^^^^^^^^^^^
  621. As mentioned above, some fields support macro expansion. Macros are
  622. recognized in the form ``$<macro-namespace>{<macro-name>}``. All macros are
  623. evaluated in the context of the preset being used, even if the macro is in a
  624. field that was inherited from another preset. For example, if the ``Base``
  625. preset sets variable ``PRESET_NAME`` to ``${presetName}``, and the
  626. ``Derived`` preset inherits from ``Base``, ``PRESET_NAME`` will be set to
  627. ``Derived``.
  628. It is an error to not put a closing brace at the end of a macro name. For
  629. example, ``${sourceDir`` is invalid. A dollar sign (``$``) followed by
  630. anything other than a left curly brace (``{``) with a possible namespace is
  631. interpreted as a literal dollar sign.
  632. Recognized macros include:
  633. ``${sourceDir}``
  634. Path to the project source directory.
  635. ``${sourceParentDir}``
  636. Path to the project source directory's parent directory.
  637. ``${sourceDirName}``
  638. The last filename component of ``${sourceDir}``. For example, if
  639. ``${sourceDir}`` is ``/path/to/source``, this would be ``source``.
  640. ``${presetName}``
  641. Name specified in the preset's ``name`` field.
  642. ``${generator}``
  643. Generator specified in the preset's ``generator`` field. For build and
  644. test presets, this will evaluate to the generator specified by
  645. ``configurePreset``.
  646. ``${hostSystemName}``
  647. The name of the host operating system. Contains the same value as
  648. :variable:`CMAKE_HOST_SYSTEM_NAME`. This is allowed in preset files
  649. specifying version ``3`` or above.
  650. ``${dollar}``
  651. A literal dollar sign (``$``).
  652. ``$env{<variable-name>}``
  653. Environment variable with name ``<variable-name>``. The variable name may
  654. not be an empty string. If the variable is defined in the ``environment``
  655. field, that value is used instead of the value from the parent environment.
  656. If the environment variable is not defined, this evaluates as an empty
  657. string.
  658. Note that while Windows environment variable names are case-insensitive,
  659. variable names within a preset are still case-sensitive. This may lead to
  660. unexpected results when using inconsistent casing. For best results, keep
  661. the casing of environment variable names consistent.
  662. ``$penv{<variable-name>}``
  663. Similar to ``$env{<variable-name>}``, except that the value only comes from
  664. the parent environment, and never from the ``environment`` field. This
  665. allows you to prepend or append values to existing environment variables.
  666. For example, setting ``PATH`` to ``/path/to/ninja/bin:$penv{PATH}`` will
  667. prepend ``/path/to/ninja/bin`` to the ``PATH`` environment variable. This
  668. is needed because ``$env{<variable-name>}`` does not allow circular
  669. references.
  670. ``$vendor{<macro-name>}``
  671. An extension point for vendors to insert their own macros. CMake will not
  672. be able to use presets which have a ``$vendor{<macro-name>}`` macro, and
  673. effectively ignores such presets. However, it will still be able to use
  674. other presets from the same file.
  675. CMake does not make any attempt to interpret ``$vendor{<macro-name>}``
  676. macros. However, to avoid name collisions, IDE vendors should prefix
  677. ``<macro-name>`` with a very short (preferably <= 4 characters) vendor
  678. identifier prefix, followed by a ``.``, followed by the macro name. For
  679. example, the Example IDE could have ``$vendor{xide.ideInstallDir}``.
  680. Schema
  681. ======
  682. :download:`This file </manual/presets/schema.json>` provides a machine-readable
  683. JSON schema for the ``CMakePresets.json`` format.