cmake-presets.7.rst 47 KB

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