cmake-presets.7.rst 47 KB

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