cmake-presets.7.rst 33 KB

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