cmake-presets.7.rst 40 KB

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