cmake-presets.7.rst 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  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 ``--preset`` is specified).
  17. ``CMakePresets.json`` is meant to specify project-wide build details, while
  18. ``CMakeUserPresets.json`` is meant for developers to specify their own local
  19. 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 ``-Wdev`` or ``-Wno-dev``
  223. on the command line. This may not be set to ``false`` if ``errors.dev``
  224. is set to ``true``.
  225. ``deprecated``
  226. An optional boolean. Equivalent to passing ``-Wdeprecated`` or
  227. ``-Wno-deprecated`` on the command line. This may not be set to
  228. ``false`` if ``errors.deprecated`` is set to ``true``.
  229. ``uninitialized``
  230. An optional boolean. Setting this to ``true`` is equivalent to passing
  231. ``--warn-uninitialized`` on the command line.
  232. ``unusedCli``
  233. An optional boolean. Setting this to ``false`` is equivalent to passing
  234. ``--no-warn-unused-cli`` on the command line.
  235. ``systemVars``
  236. An optional boolean. Setting this to ``true`` is equivalent to passing
  237. ``--check-system-vars`` on the command line.
  238. ``errors``
  239. An optional object specifying the errors to enable. The object may
  240. contain the following fields:
  241. ``dev``
  242. An optional boolean. Equivalent to passing ``-Werror=dev`` or
  243. ``-Wno-error=dev`` on the command line. This may not be set to ``true``
  244. if ``warnings.dev`` is set to ``false``.
  245. ``deprecated``
  246. An optional boolean. Equivalent to passing ``-Werror=deprecated`` or
  247. ``-Wno-error=deprecated`` on the command line. This may not be set to
  248. ``true`` if ``warnings.deprecated`` is set to ``false``.
  249. ``debug``
  250. An optional object specifying debug options. The object may contain the
  251. following fields:
  252. ``output``
  253. An optional boolean. Setting this to ``true`` is equivalent to passing
  254. ``--debug-output`` on the command line.
  255. ``tryCompile``
  256. An optional boolean. Setting this to ``true`` is equivalent to passing
  257. ``--debug-trycompile`` on the command line.
  258. ``find``
  259. An optional boolean. Setting this to ``true`` is equivalent to passing
  260. ``--debug-find`` on the command line.
  261. Build Preset
  262. ^^^^^^^^^^^^
  263. Each entry of the ``buildPresets`` array is a JSON object
  264. that may contain the following fields:
  265. ``name``
  266. A required string representing the machine-friendly name of the preset.
  267. This identifier is used in the
  268. :ref:`cmake --build --preset <Build Tool Mode>` option.
  269. There must not be two build presets in the union of ``CMakePresets.json``
  270. and ``CMakeUserPresets.json`` in the same directory with the same name.
  271. However, a build preset may have the same name as a configure or test preset.
  272. ``hidden``
  273. An optional boolean specifying whether or not a preset should be hidden.
  274. If a preset is hidden, it cannot be used in the ``--preset`` argument
  275. and does not have to have a valid ``configurePreset``, even from
  276. inheritance. ``hidden`` presets are intended to be used as a base for
  277. other presets to inherit via the ``inherits`` field.
  278. ``inherits``
  279. An optional array of strings representing the names of presets to inherit
  280. from. This field can also be a string, which is equivalent to an array
  281. containing one string.
  282. The preset will inherit all of the fields from the
  283. ``inherits`` presets by default (except ``name``, ``hidden``,
  284. ``inherits``, ``description``, and ``displayName``), but can override
  285. them as desired. If multiple ``inherits`` presets provide conflicting
  286. values for the same field, the earlier preset in the ``inherits`` list
  287. will be preferred.
  288. A preset can only inherit from another preset that is defined in the
  289. same file or in one of the files it includes (directly or indirectly).
  290. Presets in ``CMakePresets.json`` may not inherit from presets in
  291. ``CMakeUserPresets.json``.
  292. ``condition``
  293. An optional `Condition`_ object. This is allowed in preset files specifying
  294. version ``3`` or above.
  295. ``vendor``
  296. An optional map containing vendor-specific information. CMake does not
  297. interpret the contents of this field except to verify that it is a map
  298. if it does exist. However, it should follow the same conventions as the
  299. root-level ``vendor`` field. If vendors use their own per-preset
  300. ``vendor`` field, they should implement inheritance in a sensible manner
  301. when appropriate.
  302. ``displayName``
  303. An optional string with a human-friendly name of the preset.
  304. ``description``
  305. An optional string with a human-friendly description of the preset.
  306. ``environment``
  307. An optional map of environment variables. The key is the variable name
  308. (which may not be an empty string), and the value is either ``null`` or
  309. a string representing the value of the variable. Each variable is set
  310. regardless of whether or not a value was given to it by the process's
  311. environment. This field supports macro expansion, and environment
  312. variables in this map may reference each other, and may be listed in any
  313. order, as long as such references do not cause a cycle (for example, if
  314. ``ENV_1`` is ``$env{ENV_2}``, ``ENV_2`` may not be ``$env{ENV_1}``.)
  315. Environment variables are inherited through the ``inherits`` field, and
  316. the preset's environment will be the union of its own ``environment``
  317. and the ``environment`` from all its parents. If multiple presets in
  318. this union define the same variable, the standard rules of ``inherits``
  319. are applied. Setting a variable to ``null`` causes it to not be set,
  320. even if a value was inherited from another preset.
  321. .. note::
  322. For a CMake project using ExternalProject with a configuration preset
  323. having environment variables needed in the ExternalProject, use a build
  324. preset that inherits that configuration preset or the ExternalProject
  325. will not have the environment variables set in the configuration preset.
  326. Example: suppose the host defaults to one compiler (say Clang)
  327. and the user wishes to use another compiler (say GCC). Set configuration
  328. preset environment variables ``CC`` and ``CXX`` and use a build preset
  329. that inherits that configuration preset. Otherwise the ExternalProject
  330. may use a different (system default) compiler than the top-level CMake
  331. project.
  332. ``configurePreset``
  333. An optional string specifying the name of a configure preset to
  334. associate with this build preset. If ``configurePreset`` is not
  335. specified, it must be inherited from the inherits preset (unless this
  336. preset is hidden). The build directory is inferred from the configure
  337. preset, so the build will take place in the same ``binaryDir`` that the
  338. configuration did.
  339. ``inheritConfigureEnvironment``
  340. An optional boolean that defaults to true. If true, the environment
  341. variables from the associated configure preset are inherited after all
  342. inherited build preset environments, but before environment variables
  343. explicitly specified in this build preset.
  344. ``jobs``
  345. An optional integer. Equivalent to passing ``--parallel`` or ``-j`` on
  346. the command line.
  347. ``targets``
  348. An optional string or array of strings. Equivalent to passing
  349. ``--target`` or ``-t`` on the command line. Vendors may ignore the
  350. targets property or hide build presets that explicitly specify targets.
  351. This field supports macro expansion.
  352. ``configuration``
  353. An optional string. Equivalent to passing ``--config`` on the command
  354. line.
  355. ``cleanFirst``
  356. An optional bool. If true, equivalent to passing ``--clean-first`` on
  357. the command line.
  358. ``resolvePackageReferences``
  359. An optional string that specifies the package resolve mode. This is
  360. allowed in preset files specifying version ``4`` or above.
  361. Package references are used to define dependencies to packages from
  362. external package managers. Currently only NuGet in combination with the
  363. Visual Studio generator is supported. If there are no targets that define
  364. package references, this option does nothing. Valid values are:
  365. ``on``
  366. Causes package references to be resolved before attempting a build.
  367. ``off``
  368. Package references will not be resolved. Note that this may cause
  369. errors in some build environments, such as .NET SDK style projects.
  370. ``only``
  371. Only resolve package references, but do not perform a build.
  372. .. note::
  373. The command line parameter ``--resolve-package-references`` will take
  374. priority over this setting. If the command line parameter is not provided
  375. and this setting is not specified, an environment-specific cache variable
  376. will be evaluated to decide, if package restoration should be performed.
  377. When using the Visual Studio generator, package references are defined
  378. using the :prop_tgt:`VS_PACKAGE_REFERENCES` property. Package references
  379. are restored using NuGet. It can be disabled by setting the
  380. ``CMAKE_VS_NUGET_PACKAGE_RESTORE`` variable to ``OFF``. This can also be
  381. done from within a configure preset.
  382. ``verbose``
  383. An optional bool. If true, equivalent to passing ``--verbose`` on the
  384. command line.
  385. ``nativeToolOptions``
  386. An optional array of strings. Equivalent to passing options after ``--``
  387. on the command line. The array values support macro expansion.
  388. Test Preset
  389. ^^^^^^^^^^^
  390. Each entry of the ``testPresets`` array is a JSON object
  391. that may contain the following fields:
  392. ``name``
  393. A required string representing the machine-friendly name of the preset.
  394. This identifier is used in the :ref:`ctest --preset <CTest Options>` option.
  395. There must not be two test presets in the union of ``CMakePresets.json``
  396. and ``CMakeUserPresets.json`` in the same directory with the same name.
  397. However, a test preset may have the same name as a configure or build preset.
  398. ``hidden``
  399. An optional boolean specifying whether or not a preset should be hidden.
  400. If a preset is hidden, it cannot be used in the ``--preset`` argument
  401. and does not have to have a valid ``configurePreset``, even from
  402. inheritance. ``hidden`` presets are intended to be used as a base for
  403. other presets to inherit via the ``inherits`` field.
  404. ``inherits``
  405. An optional array of strings representing the names of presets to inherit
  406. from. This field can also be a string, which is equivalent to an array
  407. containing one string.
  408. The preset will inherit all of the fields from the
  409. ``inherits`` presets by default (except ``name``, ``hidden``,
  410. ``inherits``, ``description``, and ``displayName``), but can override
  411. them as desired. If multiple ``inherits`` presets provide conflicting
  412. values for the same field, the earlier preset in the ``inherits`` list
  413. will be preferred.
  414. A preset can only inherit from another preset that is defined in the
  415. same file or in one of the files it includes (directly or indirectly).
  416. Presets in ``CMakePresets.json`` may not inherit from presets in
  417. ``CMakeUserPresets.json``.
  418. ``condition``
  419. An optional `Condition`_ object. This is allowed in preset files specifying
  420. version ``3`` or above.
  421. ``vendor``
  422. An optional map containing vendor-specific information. CMake does not
  423. interpret the contents of this field except to verify that it is a map
  424. if it does exist. However, it should follow the same conventions as the
  425. root-level ``vendor`` field. If vendors use their own per-preset
  426. ``vendor`` field, they should implement inheritance in a sensible manner
  427. when appropriate.
  428. ``displayName``
  429. An optional string with a human-friendly name of the preset.
  430. ``description``
  431. An optional string with a human-friendly description of the preset.
  432. ``environment``
  433. An optional map of environment variables. The key is the variable name
  434. (which may not be an empty string), and the value is either ``null`` or
  435. a string representing the value of the variable. Each variable is set
  436. regardless of whether or not a value was given to it by the process's
  437. environment. This field supports macro expansion, and environment
  438. variables in this map may reference each other, and may be listed in any
  439. order, as long as such references do not cause a cycle (for example, if
  440. ``ENV_1`` is ``$env{ENV_2}``, ``ENV_2`` may not be ``$env{ENV_1}``.)
  441. Environment variables are inherited through the ``inherits`` field, and
  442. the preset's environment will be the union of its own ``environment``
  443. and the ``environment`` from all its parents. If multiple presets in
  444. this union define the same variable, the standard rules of ``inherits``
  445. are applied. Setting a variable to ``null`` causes it to not be set,
  446. even if a value was inherited from another preset.
  447. ``configurePreset``
  448. An optional string specifying the name of a configure preset to
  449. associate with this test preset. If ``configurePreset`` is not
  450. specified, it must be inherited from the inherits preset (unless this
  451. preset is hidden). The build directory is inferred from the configure
  452. preset, so tests will run in the same ``binaryDir`` that the
  453. configuration did and build did.
  454. ``inheritConfigureEnvironment``
  455. An optional boolean that defaults to true. If true, the environment
  456. variables from the associated configure preset are inherited after all
  457. inherited test preset environments, but before environment variables
  458. explicitly specified in this test preset.
  459. ``configuration``
  460. An optional string. Equivalent to passing ``--build-config`` on the
  461. command line.
  462. ``overwriteConfigurationFile``
  463. An optional array of configuration options to overwrite options
  464. specified in the CTest configuration file. Equivalent to passing
  465. ``--overwrite`` for each value in the array. The array values
  466. support macro expansion.
  467. ``output``
  468. An optional object specifying output options. The object may contain the
  469. following fields.
  470. ``shortProgress``
  471. An optional bool. If true, equivalent to passing ``--progress`` on the
  472. command line.
  473. ``verbosity``
  474. An optional string specifying verbosity level. Must be one of the
  475. following:
  476. ``default``
  477. Equivalent to passing no verbosity flags on the command line.
  478. ``verbose``
  479. Equivalent to passing ``--verbose`` on the command line.
  480. ``extra``
  481. Equivalent to passing ``--extra-verbose`` on the command line.
  482. ``debug``
  483. An optional bool. If true, equivalent to passing ``--debug`` on the
  484. command line.
  485. ``outputOnFailure``
  486. An optional bool. If true, equivalent to passing
  487. ``--output-on-failure`` on the command line.
  488. ``quiet``
  489. An optional bool. If true, equivalent to passing ``--quiet`` on the
  490. command line.
  491. ``outputLogFile``
  492. An optional string specifying a path to a log file. Equivalent to
  493. passing ``--output-log`` on the command line. This field supports
  494. macro expansion.
  495. ``labelSummary``
  496. An optional bool. If false, equivalent to passing
  497. ``--no-label-summary`` on the command line.
  498. ``subprojectSummary``
  499. An optional bool. If false, equivalent to passing
  500. ``--no-subproject-summary`` on the command line.
  501. ``maxPassedTestOutputSize``
  502. An optional integer specifying the maximum output for passed tests in
  503. bytes. Equivalent to passing ``--test-output-size-passed`` on the
  504. command line.
  505. ``maxFailedTestOutputSize``
  506. An optional integer specifying the maximum output for failed tests in
  507. bytes. Equivalent to passing ``--test-output-size-failed`` on the
  508. command line.
  509. ``testOutputTruncation``
  510. An optional string specifying the test output truncation mode. Equivalent
  511. to passing ``--test-output-truncation`` on the command line."
  512. This is allowed in preset files specifying version ``5`` or above.
  513. ``maxTestNameWidth``
  514. An optional integer specifying the maximum width of a test name to
  515. output. Equivalent to passing ``--max-width`` on the command line.
  516. ``filter``
  517. An optional object specifying how to filter the tests to run. The object
  518. may contain the following fields.
  519. ``include``
  520. An optional object specifying which tests to include. The object may
  521. contain the following fields.
  522. ``name``
  523. An optional string specifying a regex for test names. Equivalent to
  524. passing ``--tests-regex`` on the command line. This field supports
  525. macro expansion. CMake regex syntax is described under
  526. :ref:`string(REGEX) <Regex Specification>`.
  527. ``label``
  528. An optional string specifying a regex for test labels. Equivalent to
  529. passing ``--label-regex`` on the command line. This field supports
  530. macro expansion.
  531. ``useUnion``
  532. An optional bool. Equivalent to passing ``--union`` on the command
  533. line.
  534. ``index``
  535. An optional object specifying tests to include by test index. The
  536. object may contain the following fields. Can also be an optional
  537. string specifying a file with the command line syntax for
  538. ``--tests-information``. If specified as a string, this field
  539. supports macro expansion.
  540. ``start``
  541. An optional integer specifying a test index to start testing at.
  542. ``end``
  543. An optional integer specifying a test index to stop testing at.
  544. ``stride``
  545. An optional integer specifying the increment.
  546. ``specificTests``
  547. An optional array of integers specifying specific test indices to
  548. run.
  549. ``exclude``
  550. An optional object specifying which tests to exclude. The object may
  551. contain the following fields.
  552. ``name``
  553. An optional string specifying a regex for test names. Equivalent to
  554. passing ``--exclude-regex`` on the command line. This field supports
  555. macro expansion.
  556. ``label``
  557. An optional string specifying a regex for test labels. Equivalent to
  558. passing ``--label-exclude`` on the command line. This field supports
  559. macro expansion.
  560. ``fixtures``
  561. An optional object specifying which fixtures to exclude from adding
  562. tests. The object may contain the following fields.
  563. ``any``
  564. An optional string specifying a regex for text fixtures to exclude
  565. from adding any tests. Equivalent to ``--fixture-exclude-any`` on
  566. the command line. This field supports macro expansion.
  567. ``setup``
  568. An optional string specifying a regex for text fixtures to exclude
  569. from adding setup tests. Equivalent to ``--fixture-exclude-setup``
  570. on the command line. This field supports macro expansion.
  571. ``cleanup``
  572. An optional string specifying a regex for text fixtures to exclude
  573. from adding cleanup tests. Equivalent to
  574. ``--fixture-exclude-cleanup`` on the command line. This field
  575. supports macro expansion.
  576. ``execution``
  577. An optional object specifying options for test execution. The object may
  578. contain the following fields.
  579. ``stopOnFailure``
  580. An optional bool. If true, equivalent to passing ``--stop-on-failure``
  581. on the command line.
  582. ``enableFailover``
  583. An optional bool. If true, equivalent to passing ``-F`` on the command
  584. line.
  585. ``jobs``
  586. An optional integer. Equivalent to passing ``--parallel`` on the
  587. command line.
  588. ``resourceSpecFile``
  589. An optional string. Equivalent to passing ``--resource-spec-file`` on
  590. the command line. This field supports macro expansion.
  591. ``testLoad``
  592. An optional integer. Equivalent to passing ``--test-load`` on the
  593. command line.
  594. ``showOnly``
  595. An optional string. Equivalent to passing ``--show-only`` on the
  596. command line. The string must be one of the following values:
  597. ``human``
  598. ``json-v1``
  599. ``repeat``
  600. An optional object specifying how to repeat tests. Equivalent to
  601. passing ``--repeat`` on the command line. The object must have the
  602. following fields.
  603. ``mode``
  604. A required string. Must be one of the following values:
  605. ``until-fail``
  606. ``until-pass``
  607. ``after-timeout``
  608. ``count``
  609. A required integer.
  610. ``interactiveDebugging``
  611. An optional bool. If true, equivalent to passing
  612. ``--interactive-debug-mode 1`` on the command line. If false,
  613. equivalent to passing ``--interactive-debug-mode 0`` on the command
  614. line.
  615. ``scheduleRandom``
  616. An optional bool. If true, equivalent to passing ``--schedule-random``
  617. on the command line.
  618. ``timeout``
  619. An optional integer. Equivalent to passing ``--timeout`` on the
  620. command line.
  621. ``noTestsAction``
  622. An optional string specifying the behavior if no tests are found. Must
  623. be one of the following values:
  624. ``default``
  625. Equivalent to not passing any value on the command line.
  626. ``error``
  627. Equivalent to passing ``--no-tests=error`` on the command line.
  628. ``ignore``
  629. Equivalent to passing ``--no-tests=ignore`` on the command line.
  630. Condition
  631. ^^^^^^^^^
  632. The ``condition`` field of a preset, allowed in preset files specifying version
  633. ``3`` or above, is used to determine whether or not the preset is enabled. For
  634. example, this can be used to disable a preset on platforms other than Windows.
  635. ``condition`` may be either a boolean, ``null``, or an object. If it is a
  636. boolean, the boolean indicates whether the preset is enabled or disabled. If it
  637. is ``null``, the preset is enabled, but the ``null`` condition is not inherited
  638. by any presets that may inherit from the preset. Sub-conditions (for example in
  639. a ``not``, ``anyOf``, or ``allOf`` condition) may not be ``null``. If it is an
  640. object, it has the following fields:
  641. ``type``
  642. A required string with one of the following values:
  643. ``"const"``
  644. Indicates that the condition is constant. This is equivalent to using a
  645. boolean in place of the object. The condition object will have the
  646. following additional fields:
  647. ``value``
  648. A required boolean which provides a constant value for the condition's
  649. evaluation.
  650. ``"equals"``
  651. ``"notEquals"``
  652. Indicates that the condition compares two strings to see if they are equal
  653. (or not equal). The condition object will have the following additional
  654. fields:
  655. ``lhs``
  656. First string to compare. This field supports macro expansion.
  657. ``rhs``
  658. Second string to compare. This field supports macro expansion.
  659. ``"inList"``
  660. ``"notInList"``
  661. Indicates that the condition searches for a string in a list of strings.
  662. The condition object will have the following additional fields:
  663. ``string``
  664. A required string to search for. This field supports macro expansion.
  665. ``list``
  666. A required list of strings to search. This field supports macro
  667. expansion, and uses short-circuit evaluation.
  668. ``"matches"``
  669. ``"notMatches"``
  670. Indicates that the condition searches for a regular expression in a string.
  671. The condition object will have the following additional fields:
  672. ``string``
  673. A required string to search. This field supports macro expansion.
  674. ``regex``
  675. A required regular expression to search for. This field supports macro
  676. expansion.
  677. ``"anyOf"``
  678. ``"allOf"``
  679. Indicates that the condition is an aggregation of zero or more nested
  680. conditions. The condition object will have the following additional fields:
  681. ``conditions``
  682. A required array of condition objects. These conditions use short-circuit
  683. evaluation.
  684. ``"not"``
  685. Indicates that the condition is an inversion of another condition. The
  686. condition object will have the following additional fields:
  687. ``condition``
  688. A required condition object.
  689. Macro Expansion
  690. ^^^^^^^^^^^^^^^
  691. As mentioned above, some fields support macro expansion. Macros are
  692. recognized in the form ``$<macro-namespace>{<macro-name>}``. All macros are
  693. evaluated in the context of the preset being used, even if the macro is in a
  694. field that was inherited from another preset. For example, if the ``Base``
  695. preset sets variable ``PRESET_NAME`` to ``${presetName}``, and the
  696. ``Derived`` preset inherits from ``Base``, ``PRESET_NAME`` will be set to
  697. ``Derived``.
  698. It is an error to not put a closing brace at the end of a macro name. For
  699. example, ``${sourceDir`` is invalid. A dollar sign (``$``) followed by
  700. anything other than a left curly brace (``{``) with a possible namespace is
  701. interpreted as a literal dollar sign.
  702. Recognized macros include:
  703. ``${sourceDir}``
  704. Path to the project source directory (i.e. the same as
  705. :variable:`CMAKE_SOURCE_DIR`).
  706. ``${sourceParentDir}``
  707. Path to the project source directory's parent directory.
  708. ``${sourceDirName}``
  709. The last filename component of ``${sourceDir}``. For example, if
  710. ``${sourceDir}`` is ``/path/to/source``, this would be ``source``.
  711. ``${presetName}``
  712. Name specified in the preset's ``name`` field.
  713. ``${generator}``
  714. Generator specified in the preset's ``generator`` field. For build and
  715. test presets, this will evaluate to the generator specified by
  716. ``configurePreset``.
  717. ``${hostSystemName}``
  718. The name of the host operating system. Contains the same value as
  719. :variable:`CMAKE_HOST_SYSTEM_NAME`. This is allowed in preset files
  720. specifying version ``3`` or above.
  721. ``${fileDir}``
  722. Path to the directory containing the preset file which contains the macro.
  723. This is allowed in preset files specifying version ``4`` or above.
  724. ``${dollar}``
  725. A literal dollar sign (``$``).
  726. ``${pathListSep}``
  727. Native character for separating lists of paths, such as ``:`` or ``;``.
  728. For example, by setting ``PATH`` to
  729. ``/path/to/ninja/bin${pathListSep}$env{PATH}``, ``${pathListSep}`` will
  730. expand to the underlying operating system's character used for
  731. concatenation in ``PATH``.
  732. This is allowed in preset files specifying version ``5`` or above.
  733. ``$env{<variable-name>}``
  734. Environment variable with name ``<variable-name>``. The variable name may
  735. not be an empty string. If the variable is defined in the ``environment``
  736. field, that value is used instead of the value from the parent environment.
  737. If the environment variable is not defined, this evaluates as an empty
  738. string.
  739. Note that while Windows environment variable names are case-insensitive,
  740. variable names within a preset are still case-sensitive. This may lead to
  741. unexpected results when using inconsistent casing. For best results, keep
  742. the casing of environment variable names consistent.
  743. ``$penv{<variable-name>}``
  744. Similar to ``$env{<variable-name>}``, except that the value only comes from
  745. the parent environment, and never from the ``environment`` field. This
  746. allows you to prepend or append values to existing environment variables.
  747. For example, setting ``PATH`` to ``/path/to/ninja/bin:$penv{PATH}`` will
  748. prepend ``/path/to/ninja/bin`` to the ``PATH`` environment variable. This
  749. is needed because ``$env{<variable-name>}`` does not allow circular
  750. references.
  751. ``$vendor{<macro-name>}``
  752. An extension point for vendors to insert their own macros. CMake will not
  753. be able to use presets which have a ``$vendor{<macro-name>}`` macro, and
  754. effectively ignores such presets. However, it will still be able to use
  755. other presets from the same file.
  756. CMake does not make any attempt to interpret ``$vendor{<macro-name>}``
  757. macros. However, to avoid name collisions, IDE vendors should prefix
  758. ``<macro-name>`` with a very short (preferably <= 4 characters) vendor
  759. identifier prefix, followed by a ``.``, followed by the macro name. For
  760. example, the Example IDE could have ``$vendor{xide.ideInstallDir}``.
  761. Schema
  762. ======
  763. :download:`This file </manual/presets/schema.json>` provides a machine-readable
  764. JSON schema for the ``CMakePresets.json`` format.