cmake-presets.7.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 files,
  11. ``CMakePresets.json`` and ``CMakeUserPresets.json``, that allow users to
  12. specify common configure options and share them with others.
  13. ``CMakePresets.json`` and ``CMakeUserPresets.json`` live in the project's root
  14. directory. They both have exactly the same format, and both are optional
  15. (though at least one must be present if ``--preset`` is specified.)
  16. ``CMakePresets.json`` is meant to save project-wide builds, while
  17. ``CMakeUserPresets.json`` is meant for developers to save their own local
  18. builds. ``CMakePresets.json`` may be checked into a version control system, and
  19. ``CMakeUserPresets.json`` should NOT be checked in. For example, if a project
  20. is using Git, ``CMakePresets.json`` may be tracked, and
  21. ``CMakeUserPresets.json`` should be added to the ``.gitignore``.
  22. Format
  23. ======
  24. The files are a JSON document with an object as the root:
  25. .. literalinclude:: presets/example.json
  26. :language: json
  27. The root object recognizes the following fields:
  28. ``version``
  29. A required integer representing the version of the JSON schema. Currently,
  30. the only supported version is 1.
  31. ``cmakeMinimumRequired``
  32. An optional object representing the minimum version of CMake needed to
  33. build this project. This object consists of the following fields:
  34. ``major``
  35. An optional integer representing the major version.
  36. ``minor``
  37. An optional integer representing the minor version.
  38. ``patch``
  39. An optional integer representing the patch version.
  40. ``vendor``
  41. An optional map containing vendor-specific information. CMake does not
  42. interpret the contents of this field except to verify that it is a map if
  43. it does exist. However, the keys should be a vendor-specific domain name
  44. followed by a ``/``-separated path. For example, the Example IDE 1.0 could
  45. use ``example.com/ExampleIDE/1.0``. The value of each field can be anything
  46. desired by the vendor, though will typically be a map.
  47. ``configurePresets``
  48. An optional array of configure preset objects. Each preset may contain the
  49. following fields:
  50. ``name``
  51. A required string representing the machine-friendly name of the preset.
  52. This identifier is used in the ``--preset`` argument. There must not be
  53. two presets in the union of ``CMakePresets.json`` and
  54. ``CMakeUserPresets.json`` in the same directory with the same name.
  55. ``hidden``
  56. An optional boolean specifying whether or not a preset should be hidden.
  57. If a preset is hidden, it cannot be used in the ``--preset=`` argument,
  58. will not show up in the :manual:`CMake GUI <cmake-gui(1)>`, and does not
  59. have to have a valid ``generator`` or ``binaryDir``, even from
  60. inheritance. ``hidden`` presets are intended to be used as a base for
  61. other presets to inherit via the ``inherits`` field.
  62. ``inherits``
  63. An optional array of strings representing the names of presets to inherit
  64. from. The preset will inherit all of the fields from the ``inherits``
  65. presets by default (except ``name``, ``hidden``, ``inherits``,
  66. ``description``, and ``longDescription``), but can override them as
  67. desired. If multiple ``inherits`` presets provide conflicting values for
  68. the same field, the earlier preset in the ``inherits`` list will be
  69. preferred. Presets in ``CMakePresets.json`` may not inherit from presets
  70. in ``CMakeUserPresets.json``.
  71. This field can also be a string, which is equivalent to an array
  72. containing one string.
  73. ``vendor``
  74. An optional map containing vendor-specific information. CMake does not
  75. interpret the contents of this field except to verify that it is a map
  76. if it does exist. However, it should follow the same conventions as the
  77. root-level ``vendor`` field. If vendors use their own per-preset
  78. ``vendor`` field, they should implement inheritance in a sensible manner
  79. when appropriate.
  80. ``displayName``
  81. An optional string with a human-friendly name of the preset.
  82. ``description``
  83. An optional string with a human-friendly description of the preset.
  84. ``generator``
  85. An optional string representing the generator to use for the preset. If
  86. ``generator`` is not specified, it must be inherited from the
  87. ``inherits`` preset (unless this preset is ``hidden``).
  88. Note that for Visual Studio generators, unlike in the command line ``-G``
  89. argument, you cannot include the platform name in the generator name. Use
  90. the ``architecture`` field instead.
  91. ``architecture``
  92. ``toolset``
  93. Optional fields representing the platform and toolset, respectively, for
  94. generators that support them. Each may be either a string or an object
  95. with the following fields:
  96. ``value``
  97. An optional string representing the value.
  98. ``strategy``
  99. An optional string telling CMake how to handle the ``architecture`` or
  100. ``toolset`` field. Valid values are:
  101. ``"set"``
  102. Set the respective value. This will result in an error for generators
  103. that do not support the respective field.
  104. ``"external"``
  105. Do not set the value, even if the generator supports it. This is
  106. useful if, for example, a preset uses the Ninja generator, and an IDE
  107. knows how to set up the Visual C++ environment from the
  108. ``architecture`` and ``toolset`` fields. In that case, CMake will
  109. ignore the field, but the IDE can use them to set up the environment
  110. before invoking CMake.
  111. ``binaryDir``
  112. An optional string representing the path to the output binary directory.
  113. This field supports macro expansion. If a relative path is specified, it
  114. is calculated relative to the source directory. If ``binaryDir`` is not
  115. specified, it must be inherited from the ``inherits`` preset (unless this
  116. preset is ``hidden``).
  117. ``cmakeExecutable``
  118. An optional string representing the path to the CMake executable to use
  119. for this preset. This is reserved for use by IDEs, and is not used by
  120. CMake itself. IDEs that use this field should expand any macros in it.
  121. ``cacheVariables``
  122. An optional map of cache variables. The key is the variable name (which
  123. may not be an empty string), and the value is either ``null``, a boolean
  124. (which is equivalent to a value of ``"TRUE"`` or ``"FALSE"`` and a type
  125. of ``BOOL``), a string representing the value of the variable (which
  126. supports macro expansion), or an object with the following fields:
  127. ``type``
  128. An optional string representing the type of the variable.
  129. ``value``
  130. A required string or boolean representing the value of the variable.
  131. A boolean is equivalent to ``"TRUE"`` or ``"FALSE"``. This field
  132. supports macro expansion.
  133. Cache variables are inherited through the ``inherits`` field, and the
  134. preset's variables will be the union of its own ``cacheVariables`` and
  135. the ``cacheVariables`` from all its parents. If multiple presets in this
  136. union define the same variable, the standard rules of ``inherits`` are
  137. applied. Setting a variable to ``null`` causes it to not be set, even if
  138. a value was inherited from another preset.
  139. ``environment``
  140. An optional map of environment variables. The key is the variable name
  141. (which may not be an empty string), and the value is either ``null`` or
  142. a string representing the value of the variable. Each variable is set
  143. regardless of whether or not a value was given to it by the process's
  144. environment. This field supports macro expansion, and environment
  145. variables in this map may reference each other, and may be listed in any
  146. order, as long as such references do not cause a cycle (for example,
  147. if ``ENV_1`` is ``$env{ENV_2}``, ``ENV_2`` may not be ``$env{ENV_1}``.)
  148. Environment variables are inherited through the ``inherits`` field, and
  149. the preset's environment will be the union of its own ``environment`` and
  150. the ``environment`` from all its parents. If multiple presets in this
  151. union define the same variable, the standard rules of ``inherits`` are
  152. applied. Setting a variable to ``null`` causes it to not be set, even if
  153. a value was inherited from another preset.
  154. ``warnings``
  155. An optional object specifying the warnings to enable. The object may
  156. contain the following fields:
  157. ``dev``
  158. An optional boolean. Equivalent to passing ``-Wdev`` or ``-Wno-dev``
  159. on the command line. This may not be set to ``false`` if ``errors.dev``
  160. is set to ``true``.
  161. ``deprecated``
  162. An optional boolean. Equivalent to passing ``-Wdeprecated`` or
  163. ``-Wno-deprecated`` on the command line. This may not be set to
  164. ``false`` if ``errors.deprecated`` is set to ``true``.
  165. ``uninitialized``
  166. An optional boolean. Setting this to ``true`` is equivalent to passing
  167. ``--warn-uninitialized`` on the command line.
  168. ``unusedCli``
  169. An optional boolean. Setting this to ``false`` is equivalent to passing
  170. ``--no-warn-unused-cli`` on the command line.
  171. ``systemVars``
  172. An optional boolean. Setting this to ``true`` is equivalent to passing
  173. ``--check-system-vars`` on the command line.
  174. ``errors``
  175. An optional object specifying the errors to enable. The object may
  176. contain the following fields:
  177. ``dev``
  178. An optional boolean. Equivalent to passing ``-Werror=dev`` or
  179. ``-Wno-error=dev`` on the command line. This may not be set to ``true``
  180. if ``warnings.dev`` is set to ``false``.
  181. ``deprecated``
  182. An optional boolean. Equivalent to passing ``-Werror=deprecated`` or
  183. ``-Wno-error=deprecated`` on the command line. This may not be set to
  184. ``true`` if ``warnings.deprecated`` is set to ``false``.
  185. ``debug``
  186. An optional object specifying debug options. The object may contain the
  187. following fields:
  188. ``output``
  189. An optional boolean. Setting this to ``true`` is equivalent to passing
  190. ``--debug-output`` on the command line.
  191. ``tryCompile``
  192. An optional boolean. Setting this to ``true`` is equivalent to passing
  193. ``--debug-trycompile`` on the command line.
  194. ``find``
  195. An optional boolean. Setting this to ``true`` is equivalent to passing
  196. ``--debug-find`` on the command line.
  197. As mentioned above, some fields support macro expansion. Macros are
  198. recognized in the form ``$<macro-namespace>{<macro-name>}``. All macros are
  199. evaluated in the context of the preset being used, even if the macro is in a
  200. field that was inherited from another preset. For example, if the ``Base``
  201. preset sets variable ``PRESET_NAME`` to ``${presetName}``, and the
  202. ``Derived`` preset inherits from ``Base``, ``PRESET_NAME`` will be set to
  203. ``Derived``.
  204. It is an error to not put a closing brace at the end of a macro name. For
  205. example, ``${sourceDir`` is invalid. A dollar sign (``$``) followed by
  206. anything other than a left curly brace (``{``) with a possible namespace is
  207. interpreted as a literal dollar sign.
  208. Recognized macros include:
  209. ``${sourceDir}``
  210. Path to the project source directory.
  211. ``${sourceParentDir}``
  212. Path to the project source directory's parent directory.
  213. ``${sourceDirName}``
  214. The last filename component of ``${sourceDir}``. For example, if
  215. ``${sourceDir}`` is ``/path/to/source``, this would be ``source``.
  216. ``${presetName}``
  217. Name specified in the preset's ``name`` field.
  218. ``${generator}``
  219. Generator specified in the preset's ``generator`` field.
  220. ``${dollar}``
  221. A literal dollar sign (``$``).
  222. ``$env{<variable-name>}``
  223. Environment variable with name ``<variable-name>``. The variable name may
  224. not be an empty string. If the variable is defined in the ``environment``
  225. field, that value is used instead of the value from the parent environment.
  226. If the environment variable is not defined, this evaluates as an empty
  227. string.
  228. Note that while Windows environment variable names are case-insensitive,
  229. variable names within a preset are still case-sensitive. This may lead to
  230. unexpected results when using inconsistent casing. For best results, keep
  231. the casing of environment variable names consistent.
  232. ``$penv{<variable-name>}``
  233. Similar to ``$env{<variable-name>}``, except that the value only comes from
  234. the parent environment, and never from the ``environment`` field. This
  235. allows you to prepend or append values to existing environment variables.
  236. For example, setting ``PATH`` to ``/path/to/ninja/bin:$penv{PATH}`` will
  237. prepend ``/path/to/ninja/bin`` to the ``PATH`` environment variable. This
  238. is needed because ``$env{<variable-name>}`` does not allow circular
  239. references.
  240. ``$vendor{<macro-name>}``
  241. An extension point for vendors to insert their own macros. CMake will not
  242. be able to use presets which have a ``$vendor{<macro-name>}`` macro, and
  243. effectively ignores such presets. However, it will still be able to use
  244. other presets from the same file.
  245. CMake does not make any attempt to interpret ``$vendor{<macro-name>}``
  246. macros. However, to avoid name collisions, IDE vendors should prefix
  247. ``<macro-name>`` with a very short (preferably <= 4 characters) vendor
  248. identifier prefix, followed by a ``.``, followed by the macro name. For
  249. example, the Example IDE could have ``$vendor{xide.ideInstallDir}``.
  250. Schema
  251. ======
  252. :download:`This file </manual/presets/schema.json>` provides a machine-readable
  253. JSON schema for the ``CMakePresets.json`` format.