cmake-presets.7.rst 34 KB

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