cmake-presets.7.rst 40 KB

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