cmake-presets.7.rst 38 KB

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