CMAKE-PRESETS(7)
โจ NAME โจ
CMAKE-PRESETS(7) โ cmake-presets โ CMake Presets Reference ๐
Okay bestie, welcome to the CMAKE-PRESETS(7) glow-up. This is literally the whole CMake Presets Reference, and we are keeping every single detail. Buckle up ๐
๐ธ INTRODUCTION ๐ธ
Added in version 3.19.
So hereโs the vibe: one problem that CMake users often face is sharing settings with other people for common ways to configure a project. Maybe itโs to support CI builds, maybe itโs for users who frequently use the same build โ either way, CMake supports two main files, CMakePresets.json and CMakeUserPresets.json, that allow users to specify common configure options and share them with others. ๐ซถ
Added in presets version 4: CMake also supports files included with the include field. See Includes for more details.
CMakePresets.json and CMakeUserPresets.json live in the projectโs root directory. They both have exactly the same format, and both are optional (though at least one must be present if --preset <#cmdoption-cmake-preset> is specified). CMakePresets.json is meant to specify project-wide build details, while CMakeUserPresets.json is meant for developers to specify their own local build details.
CMakePresets.json may be checked into a version control system, and CMakeUserPresets.json should NOT be checked in. For example, if a project is using Git, CMakePresets.json may be tracked, and CMakeUserPresets.json should be added to the .gitignore.
Added in version 4.4: CMake also supports specifying a file from which to read presets via the --presets-file <#cmdoption-cmake-presets-file> option. If this option is specified, neither of CMakePresets.json nor CMakeUserPresets.json are required to be present, and any presets defined in those files will be ignored/unavailable.
๐ FORMAT ๐
The files are a JSON document with an object as the root:
{
"version": 10,
"cmakeMinimumRequired": {
"major": 3,
"minor": 23,
"patch": 0
},
"$comment": "An example CMakePresets.json file",
"include": [
"otherThings.json",
"moreThings.json"
],
"configurePresets": [
{
"$comment": [
"This is a comment row.",
"This is another comment,",
"just because we can do it"
],
"name": "default",
"displayName": "Default Config",
"description": "Default build using Ninja generator",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/default",
"cacheVariables": {
"FIRST_CACHE_VARIABLE": {
"type": "BOOL",
"value": "OFF"
},
"SECOND_CACHE_VARIABLE": "ON"
},
"environment": {
"MY_ENVIRONMENT_VARIABLE": "Test",
"PATH": "$env{HOME}/ninja/bin:$penv{PATH}"
},
"vendor": {
"example.com/ExampleIDE/1.0": {
"autoFormat": true
}
}
},
{
"name": "ninja-multi",
"inherits": "default",
"displayName": "Ninja Multi-Config",
"description": "Default build using Ninja Multi-Config generator",
"generator": "Ninja Multi-Config"
},
{
"name": "windows-only",
"inherits": "default",
"displayName": "Windows-only configuration",
"description": "This build is only available on Windows",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
}
],
"testPresets": [
{
"name": "default",
"configurePreset": "default",
"output": {"outputOnFailure": true},
"execution": {"noTestsAction": "error", "stopOnFailure": true}
}
],
"packagePresets": [
{
"name": "default",
"configurePreset": "default",
"generators": [
"TGZ"
]
}
],
"workflowPresets": [
{
"name": "default",
"steps": [
{
"type": "configure",
"name": "default"
},
{
"type": "build",
"name": "default"
},
{
"type": "test",
"name": "default"
},
{
"type": "package",
"name": "default"
}
]
}
],
"vendor": {
"example.com/ExampleIDE/1.0": {
"autoFormat": false
}
}
}
Added in presets version 10: Presets files may include comments using the key $comment at any level within the JSON object to provide documentation.
The root object recognizes the following fields:
$schemaโ Added in presets version 8. An optional string that provides a URI to the JSON schema that describes the structure of this JSON document. This field is used for validation and autocompletion in editors that support JSON schema. It doesnโt affect the behavior of the document itself. If this field is not specified, the JSON document will still be valid, but tools that use JSON schema for validation and autocompletion may not function correctly.versionโ A required integer representing the version of the JSON schema. See Versions for discussion of the supported versions and the corresponding version of CMake in which they were added.cmakeMinimumRequiredโ An optional object representing the minimum version of CMake needed to build this project. This object consists of the following fields:majorโ An optional integer representing the major version.minorโ An optional integer representing the minor version.patchโ An optional integer representing the patch version.
includeโ Added in presets version 4. An optional array of strings representing files to include. If the filenames are not absolute, they are considered relative to the current file. See Includes for discussion of the constraints on included files.vendorโ An optional map containing vendor-specific information. CMake does not interpret the contents of this field except to verify that it is a map if it does exist. However, the keys should be a vendor-specific domain name followed by a /-separated path. For example, the Example IDE 1.0 could useexample.com/ExampleIDE/1.0. The value of each field can be anything desired by the vendor, though will typically be a map.configurePresetsโ An optional array of Configure Preset objects.buildPresetsโ Added in presets version 2. An optional array of Build Preset objects.testPresetsโ Added in presets version 2. An optional array of Test Preset objects.packagePresetsโ Added in presets version 6. An optional array of Package Preset objects.workflowPresetsโ Added in presets version 6. An optional array of Workflow Preset objects.
๐ง Includes ๐ง
Added in presets version 4.
CMake presets files can include other files with the include field. Files included in this manner can also include other files. If CMakePresets.json and CMakeUserPresets.json are both present, CMakeUserPresets.json implicitly includes CMakePresets.json, even with no include field, in all versions of the format.
If a presets file contains presets that inherit from presets in another file, the file must include the other file either directly or indirectly. Include cycles are not allowed among files. If a.json includes b.json, b.json cannot include a.json. However, a file may be included multiple times from the same file or from different files.
Files directly or indirectly included from CMakePresets.json should be guaranteed to be provided by the project. CMakeUserPresets.json may include files from anywhere.
Changed in presets version 7: The include field supports macro expansion, but only $penv{} macro expansion.
Changed in presets version 9: The include field supports macro expansion, except for $env{} and preset-specific macros (i.e., those derived from the fields inside a presetโs definition like presetName).
๐ Configure Preset ๐
Each entry of the configurePresets array is a JSON object that may contain the following fields:
nameโ A required string representing the machine-friendly name of the preset. This identifier is used in thecmake --preset <#cmdoption-cmake-preset>option. There must not be two configure presets in the union ofCMakePresets.jsonandCMakeUserPresets.jsonin the same directory with the same name. However, a configure preset may have the same name as a build, test, package, or workflow preset.hiddenโ An optional boolean specifying whether or not a preset should be hidden. If a preset is hidden, it cannot be used in the--preset <#cmdoption-cmake-preset>argument, will not show up in theCMake GUI <#manual:cmake-gui(1)>, and does not have to have a validgeneratororbinaryDir, even from inheritance.hiddenpresets are intended to be used as a base for other presets to inherit via theinheritsfield.inheritsโ An optional array of strings representing the names of presets from which to inherit. This field can also be a string, which is equivalent to an array containing one string.
The preset will inherit all of the fields from the inherits presets by default (except name, hidden, inherits, description, and displayName), but can override them as desired. If multiple inherits presets provide conflicting values for the same field, the earlier preset in the inherits array will be preferred.
A preset can only inherit from another preset that is defined in the same file or in one of the files it includes (directly or indirectly). Presets in CMakePresets.json may not inherit from presets in CMakeUserPresets.json.
conditionโ Added in presets version 3. An optional Condition object.vendorโ an optional map stuffed with vendor-specific lore ๐ผ CMake does not interpret what's inside this field at all, except to verify that it's a map if it does exist. That said, it should follow the same conventions as the root-levelvendorfield. And if vendors use their own per-presetvendorfield, they should implement inheritance in a sensible manner when appropriate โ be normal about it, bestie ๐ซถdisplayNameโ an optional string with a human-friendly name for the preset โจ like the preset's little nickname.descriptionโ an optional string with a human-friendly description of the preset ๐ exactly what it says on the tin.generatorโ an optional string representing the generator to use for the preset (peepcmake-generators(7)for the full menu) ๐ง
Changed in presets version 3: if you omit this, CMake falls back to the regular generator discovery procedure. In previous versions, if it wasn't specified, this field must be inherited from the inherits preset (unless this preset is hidden). No skipping, babes.
Little heads-up, and it matters: for Visual Studio Generators, unlike the command line -G argument, you cannot include the platform name in the generator name ๐ค Use the architecture field instead. That's the whole vibe.
architectureโ optional field representing the platform, for generators that support it (again,cmake-generators(7)). For possible values, go look atcmake -A.architecturemay be either a string or an object with the following fields:valueโ an optional string representing the value.strategyโ an optional string telling CMake how to handle the field. Valid values are:"set"โ set the respective value. This will result in an error for generators that do not support the respective field. ๐"external"โ do not set the value, even if the generator supports it. This is useful if, for example, a preset uses the Ninja generator, and an IDE knows how to set up the Visual C++ environment from thearchitectureandtoolsetfields. In that case, CMake will ignore the field, but the IDE can use them to set up the environment before invoking CMake. Teamwork, lowkey ๐ค
- If no
strategyfield is given, or if the field uses the string form rather than the object form, the behavior is the same as"set".
toolsetโ optional field representing the toolset, for generators that support it (yes,cmake-generators(7)). Possible values? That's acmake -Tquestion, bestie.toolsetmay be either a string or an object with the following fields:valueโ an optional string representing the value.strategyโ an optional string telling CMake how to handle the field. Valid values are:"set"โ set the respective value. This will result in an error for generators that do not support the respective field. โ ๏ธ"external"โ do not set the value, even if the generator supports it. This is useful if, for example, a preset uses the Ninja generator, and an IDE knows how to set up the Visual C++ environment from thearchitectureandtoolsetfields. In that case, CMake will ignore the field, but the IDE can use them to set up the environment before invoking CMake.
- If no
strategyfield is given, or if the field uses the string form rather than the object form, the behavior is the same as"set".
toolchainFileโ Added in presets version 3. An optional string representing the path to the toolchain file ๐งฐ This field supports macro expansion. If a relative path is specified, it is calculated relative to the build directory, and if not found, relative to the source directory. Also it takes precedence over anyCMAKE_TOOLCHAIN_FILEvalue โ it wins, periodt ๐graphvizโ Added in presets version 10. An optional string representing the path to the graphviz input file, which will contain all the library and executable dependencies in the project ๐ธ๏ธ See the documentation forcmake --graphvizfor more details. This field supports macro expansion, and if a relative path is specified, it is calculated relative to the current working directory.binaryDirโ an optional string representing the path to the output binary directory ๐ This field supports macro expansion. If a relative path is specified, it is calculated relative to the source directory.
Changed in presets version 3: if omitted, CMake will calculate the path using regular methods. In previous versions, if not specified, this field must be inherited from the inherits preset (unless this preset is hidden).
installDirโ Added in presets version 3. An optional string representing the path to the installation directory, which will be used as theCMAKE_INSTALL_PREFIXvariable ๐ This field supports macro expansion. If a relative path is specified, it is calculated relative to the source directory.cmakeExecutableโ an optional string representing the path to the CMake executable to use for this preset. This one is reserved for use by IDEs and is not used by CMake itself ๐ซ IDEs that use this field should expand any macros in it.cacheVariablesโ an optional map of cache variables ๐๏ธ The key is the variable name (which may not be an empty string), and the value is eithernull, a boolean (which is equivalent to a value of"TRUE"or"FALSE"and a type ofBOOL), a string representing the value of the variable (which supports macro expansion), or an object with the following fields:typeโ an optional string representing the type of the variable.valueโ a required string or boolean representing the value of the variable. A boolean is equivalent to"TRUE"or"FALSE". This field supports macro expansion.
Cache variables are inherited through the inherits field, and the preset's variables will be the union of its own cacheVariables and the cacheVariables from all its parents. If multiple presets in this union define the same variable, the standard rules of inherits are applied. And setting a variable to null causes it to not be set, even if a value was inherited from another preset โ the audacity, honestly ๐ญ
environmentโ an optional map of environment variables ๐ The key is the variable name (which may not be an empty string), and the value is eithernullor a string representing the value of the variable. Each variable is set regardless of whether or not a value was given to it by the process's environment.
This field supports macro expansion, and environment variables in this map may reference each other, and may be listed in any order, as long as such references do not cause a cycle (for example, if ENV_1 is $env{ENV_2}, ENV_2 may not be $env{ENV_1}). No circular drama, please ๐
โโ๏ธ $penv{NAME} allows you to prepend or append values to existing environment variables by accessing only values from the parent environment.
Environment variables are inherited through the inherits field, and the preset's environment will be the union of its own environment and the environment from all its parents. If multiple presets in this union define the same variable, the standard rules of inherits are applied. Setting a variable to null causes it to not be set, even if a value was inherited from another preset.
warningsโ an optional object specifying the warnings to enable ๐ This object may contain the following fields:authorโ Added in presets version 12. An optional boolean. Equivalent to passing-Wauthoror-Wno-authoron the command line. This may not be set tofalseiferrors.authoris set totrue.deprecatedโ an optional boolean. Equivalent to passing-Wdeprecatedor-Wno-deprecatedon the command line. This may not be set tofalseiferrors.deprecatedis set totrue.devโ Removed in presets version 12. An optional boolean. Equivalent to passing-Wdevor-Wno-devon the command line. This may not be set tofalseiferrors.devis set totrue.experimentalโ Added in presets version 12. An optional boolean. Equivalent to passing-Wexperimentalor-Wno-experimentalon the command line. This may not be set tofalseiferrors.experimentalis set totrue.installAbsoluteDestinationโ Added in presets version 12. An optional boolean. Equivalent to passing-Winstall-absolute-destinationor-Wno-install-absolute-destinationon the command line. This may not be set tofalseiferrors.installAbsoluteDestinationis set totrue.policyโ Added in presets version 12. An optional boolean. Equivalent to passing-Wpolicyor-Wno-policyon the command line. This may not be set tofalseiferrors.policyis set totrue.uninitializedโ an optional boolean. Equivalent to passing-Wuninitializedor-Wno-uninitializedon the command line. This may not be set tofalseiferrors.uninitializedis set totrue.
unusedCliโ optional boolean, bestie. It's literally just-Wunused-clior-Wno-unused-clibut โจin JSONโจ. One catch: you can't set this tofalseiferrors.unusedCliistrue, okay? That combo is a no-go.systemVarsโ optional boolean. Flip it totrueand it's the same energy as passing--check-system-varson the command line. Slay.
๐ฅ errors ๐ฅ
An optional object where you pick which errors get enabled. It may contain these fields, and yes, there are a lot of them โ hydrate first:
authorโ added in presets version 12. Optional boolean. Equivalent to-Werror=authoror-Wno-error=authoron the command line. You may not set this totrueifwarnings.authoris set tofalse. The math has to math.deprecatedโ optional boolean. Equivalent to-Werror=deprecatedor-Wno-error=deprecated. Same rule: no setting this totrueifwarnings.deprecatedisfalse.devโ removed in presets version 12, so she's gone, respectfully. When she existed: optional boolean, equivalent to-Werror=devor-Wno-error=dev, and not allowed to betrueifwarnings.devwasfalse.experimentalโ added in presets version 12. Optional boolean. Equivalent to-Werror=experimentalor-Wno-error=experimental. May not betrueifwarnings.experimentalisfalse.installAbsoluteDestinationโ added in presets version 12. Optional boolean. Equivalent to-Werror=install-absolute-destinationor-Wno-error=install-absolute-destination. May not betrueifwarnings.installAbsoluteDestinationisfalse.policyโ added in presets version 12. Optional boolean. Equivalent to-Werror=policyor-Wno-error=policy. May not betrueifwarnings.policyisfalse.uninitializedโ added in presets version 12. Optional boolean. Equivalent to-Werror=uninitializedor-Wno-error=uninitialized. May not betrueifwarnings.uninitializedisfalse.unusedCliโ added in presets version 12. Optional boolean. Equivalent to-Werror=unused-clior-Wno-error=unused-cli. May not betrueifwarnings.unusedCliisfalse.
๐ debug ๐
An optional object for debug options. Fields go like this:
outputโ optional boolean. Set it totrueand it's giving--debug-outputon the command line.tryCompileโ optional boolean. Set it totrueand it's literally--debug-trycompile.findโ optional boolean.true=--debug-find. Easy.
๐ trace ๐
added in presets version 7. An optional object for trace options โ the object may contain these fields:
modeโ optional string, picks the trace mode. Valid values are:onโ prints a trace of all calls made and from where. Equivalent to--trace.offโ no trace of all calls gets printed. Chill.expandโ prints a trace with variables expanded of all calls made and from where. Equivalent to--trace-expand.
formatโ optional string for the trace output format. Valid values are:humanโ prints each trace line in a human-readable format. This is the default format, and it's equivalent to--trace-format=human.json-v1โ prints each line as a separate JSON document. Equivalent to--trace-format=json-v1.
sourceโ optional array of strings holding the paths of source files to be traced. This field can also be a string, which is equivalent to an array containing one string. Equivalent to--trace-source.redirectโ optional string specifying a path to a trace output file. Equivalent to--trace-redirect.
๐ BUILD PRESET ๐
added in presets version 2. Every entry of the buildPresets array is a JSON object that may contain these fields โ and yes, name is the main character:
nameโ a required string with the machine-friendly name of the preset. This identifier is what you use in thecmake --build --presetoption. Important: there must not be two build presets in the union ofCMakePresets.jsonandCMakeUserPresets.jsonin the same directory with the same name. However, a build preset may have the same name as a configure, test, package, or workflow preset. Different lanes, no drama.hiddenโ optional boolean saying whether a preset should be hidden. If a preset is hidden, it cannot be used in the--presetargument and does not have to have a validconfigurePreset, even from inheritance. Hidden presets are intended as a base for other presets to inherit via theinheritsfield. Secret little template energy. ๐inheritsโ optional array of strings naming the presets you're inheriting from. This field can also be a string, which is equivalent to an array containing one string. The preset will inherit all of the fields from the inherits presets by default, exceptname,hidden,inherits,description, anddisplayNameโ but it can override them as desired. If multiple inherits presets provide conflicting values for the same field, the earlier preset in theinheritsarray is preferred. A preset can only inherit from another preset defined in the same file or in one of the files it includes (directly or indirectly). No cap: presets inCMakePresets.jsonmay not inherit from presets inCMakeUserPresets.json.conditionโ added in presets version 3. An optionalConditionobject. Very conditional of it.vendorโ optional map holding vendor-specific information. CMake does not interpret the contents of this field except to verify that it is a map if it does exist. It should follow the same conventions as the root-levelvendorfield, though. And if vendors use their own per-presetvendorfield, they should implement inheritance in a sensible manner when appropriate. Please and thank you. ๐ซถdisplayNameโ optional string with a human-friendly name of the preset.descriptionโ optional string with a human-friendly description of the preset.environmentโ optional map of environment variables. The key is the variable name (which may not be an empty string), and the value is eithernullor a string representing the value of the variable. Each variable is set regardless of whether or not a value was given to it by the process's environment. This field supports macro expansion, and environment variables in this map may reference each other, and may be listed in any order โ as long as those references don't cause a cycle (for example, ifENV_1is$env{ENV_2}, thenENV_2may not be$env{ENV_1}). No circular bestie drama. ๐$penv{NAME}lets you prepend or append values to existing environment variables by accessing only values from the parent environment. Environment variables are inherited through theinheritsfield, and the preset's environment will be the union of its own environment and the environment from all its parents. If multiple presets in this union define the same variable, the standard rules ofinheritsare applied. Setting a variable tonullcauses it to not be set, even if a value was inherited from another preset. Iconic override behaviour, ngl.
Note: For a CMake project usingExternalProjectwith a configuration preset that has environment variables needed in theExternalProject, use a build preset that inherits that configuration preset โ or theExternalProjectwill not have the environment variables set in the configuration preset. Fr fr, this one bites people. Example: suppose the host defaults to one compiler (say Clang) and the user wishes to use another compiler (say GCC). Set configuration preset environment variablesCCandCXXand use a build preset that inherits that configuration preset. Otherwise theExternalProjectmay use a different (system default) compiler than the top-level CMake project. ๐
configurePresetโ optional string, and it's literally just the name of the configure preset you wanna pair with this build preset ๐ซถ. If you don't write it down, it has to come from theinheritspreset (unless this preset ishidden). And because the build dir gets inferred from the configure preset, your build lands in the exact samebinaryDiryour configure step used. Same room, same vibe, no cap.inheritConfigureEnvironmentโ optional boolean, defaults totrueโจ. When it'strue, the environment variables from the associated configure preset get inherited after all the inherited build preset environments, but before any environment variables you explicitly set in this build preset. Order matters, bestie, it's giving priority list ๐ .jobsโ optional integer, same energy as passing--parallelor-jon the command line ๐ฅ. If the value is0, it's equivalent to passing--parallelwith the jobs value omitted; alternatively you can define the environment variableCMAKE_BUILD_PARALLEL_LEVELas an empty string using theenvironmentfield. Either way works, pick your fighter.
Changed in version 4.3: this field does not accept negative integer values, regardless of the version in the presets file. So no -1 shenanigans, that's not the move ๐.
targetsโ optional string or array of strings. Equivalent to passing--targetor-ton the command line ๐ฏ. Heads up though: vendors may ignore thetargetsproperty or hide build presets that explicitly specify targets. Also, this field supports macro expansion โจ.configurationโ optional string. Equivalent to passing--configon the command line. Simple, clean, iconic.cleanFirstโ optional bool. Iftrue, equivalent to passing--clean-firston the command line ๐งผ. Fresh start energy.resolvePackageReferencesโ added in presets version 4 โจ.
An optional string that specifies the package resolve mode.
So like, package references are what you use to define dependencies to packages from external package managers. Currently only NuGet in combination with the Visual Studio Generators is supported. If there are no targets that define package references, this option literally does nothing โ it's just sitting there. The valid values are:
onโ causes package references to be resolved before attempting a build.offโ package references will not be resolved. Note that this may cause errors in some build environments, such as .NET SDK style projects ๐ฌ.onlyโ only resolve package references, but do not perform a build.
Note: the command line parameter --resolve-package-references will take priority over this setting. If the command line parameter is not provided and this setting is not specified, an environment-specific cache variable will be evaluated to decide if package restoration should be performed.
When using the Visual Studio Generators, package references are defined using theVS_PACKAGE_REFERENCESproperty. Package references are restored using NuGet. It can be disabled by setting theCMAKE_VS_NUGET_PACKAGE_RESTOREvariable toOFF. This can also be done from within a configure preset ๐ซถ.
verboseโ optional boolean. Iftrue, equivalent to passing--verboseon the command line. Loud and proud ๐ฃ.nativeToolOptionsโ optional array of strings. Equivalent to passing options after--on the command line. The array values support macro expansion โจ. Basically the "and also whatever the native tool wants" bucket, iykyk.
๐งช Test Preset ๐งช
Added in presets version 2 ๐.
Each entry of the testPresets array is a JSON object that may contain the following fields:
nameโ a required string, the machine-friendly name of the preset. This identifier is what you use in thectest --presetoption. And here's the rule: there must not be two test presets in the union ofCMakePresets.jsonandCMakeUserPresets.jsonin the same directory with the same name ๐ซ. However โ plot twist โ a test preset may have the same name as a configure, build, package, or workflow preset. Different lane, same name, totally fine.hiddenโ optional boolean, specifies whether or not a preset should be hidden ๐. If a preset is hidden, it can't be used in the--presetargument and it doesn't have to have a validconfigurePreset, even from inheritance. Hidden presets are intended to be used as a base for other presets to inherit via theinheritsfield. They're the backstage crew, not the main character.inheritsโ optional array of strings representing the names of presets from which to inherit ๐ซถ. This field can also be a string, which is equivalent to an array containing one string.
The preset will inherit all of the fields from the inherits presets by default (except name, hidden, inherits, description, and displayName), but can override them as desired. If multiple inherits presets provide conflicting values for the same field, the earlier preset in the inherits array will be preferred โจ.
A preset can only inherit from another preset that is defined in the same file or in one of the files it includes (directly or indirectly). Presets in CMakePresets.json may not inherit from presets in CMakeUserPresets.json. Boundaries, bestie ๐
.
conditionโ added in presets version 3. An optional Condition object.vendorโ an optional map containing vendor-specific information. CMake does not interpret the contents of this field except to verify that it is a map if it does exist. However, it should follow the same conventions as the root-levelvendorfield. If vendors use their own per-presetvendorfield, they should implement inheritance in a sensible manner when appropriate ๐ง.displayNameโ an optional string with a human-friendly name of the preset. The cute version ๐.descriptionโ an optional string with a human-friendly description of the preset.environmentโ an optional map of environment variables. The key is the variable name (which may not be an empty string), and the value is eithernullor a string representing the value of the variable. Each variable is set regardless of whether or not a value was given to it by the process's environment ๐.
This field supports macro expansion, and environment variables in this map may reference each other, and may be listed in any order, as long as such references do not cause a cycle (for example, if ENV_1 is $env{ENV_2}, ENV_2 may not be $env{ENV_1}) ๐. $penv{NAME} allows one to prepend or append values to existing environment variables by accessing only values from the parent environment.
Environment variables are inherited through the inherits field, and the preset's environment will be the union of its own environment and the environment from all its parents. If multiple presets in this union define the same variable, the standard rules of inherits are applied. Setting a variable to null causes it to not be set, even if a value was inherited from another preset ๐.
configurePresetโ an optional string specifying the name of a configure preset to associate with this test preset. IfconfigurePresetis not specified, it must be inherited from theinheritspreset (unless this preset ishidden). The build directory is inferred from the configure preset, so tests will run in the samebinaryDirthat the configuration and build used ๐ซถ. Consistency is the vibe.inheritConfigureEnvironmentโ an optional boolean that defaults totrue. Iftrue, the environment variables from the associated configure preset are inherited after all inherited test preset environments, but before environment variables explicitly specified in this test preset โจ. Yes it's the same concept as before, it's a recurring theme, we love a consistent queen.configurationโ an optional string. Equivalent to passing--build-configor-Con the command line.overwriteConfigurationFileโ an optional array of configuration options to overwrite options specified in the CTest configuration file. Equivalent to passing--overwritefor each value in the array. The array values support macro expansion ๐.outputโ an optional object specifying output options. The object may contain the following fields:shortProgressโ an optional bool. Iftrue, equivalent to passing--progresson the command line.verbosityโ an optional string specifying verbosity level. Must be one of the following:defaultโ equivalent to passing no verbosity flags on the command line.verboseโ equivalent to passing--verboseor-Von the command line.extraโ equivalent to passing--extra-verboseor-VVon the command line.
debugโ an optional bool. Iftrue, equivalent to passing--debugon the command line.outputOnFailureโ an optional bool. Iftrue, equivalent to passing--output-on-failureon the command line.quietโ an optional bool. Iftrue, equivalent to passing--quietor-Qon the command line ๐คซ.outputLogFileโ an optional string specifying a path to a log file. Equivalent to passing--output-logor-Oon the command line. This field supports macro expansion โจ.outputJUnitFileโ added in presets version 6. An optional string specifying a path to a JUnit file. Equivalent to passing--output-juniton the command line. This field supports macro expansion ๐.
labelSummary
An optional bool. Set it to false and it's literally the same as passing --no-label-summary on the command line. That's it, that's the whole vibe. โจ
subprojectSummary
An optional bool. false here = equivalent to passing --no-subproject-summary on the command line. Easy.
maxPassedTestOutputSize
An optional integer that caps how much output you get for passed tests, measured in bytes. Same thing as passing --test-output-size-passed on the command line. ๐
maxFailedTestOutputSize
An optional integer that caps how much output you get for failed tests, in bytes. Equivalent to passing --test-output-size-failed on the command line. No cap on the drama tho ๐
testOutputTruncation
Added in presets version 5.
An optional string that picks your test output truncation mode. Equivalent to passing --test-output-truncation on the command line. It has to be one of these three besties, no exceptions:
tailmiddlehead
maxTestNameWidth
An optional integer for the max width of a test name in the output. Equivalent to passing --max-width on the command line. Give those names room to breathe fr fr ๐ซถ
filter
An optional object that says how to filter which tests actually run. It may contain these fields:
include โ an optional object saying which tests to include. Its fields:
nameโ an optional string holding a regex for test names. Equivalent to passing--tests-regexon the command line. This field supports macro expansion. (CMake regex syntax is described over understring(REGEX).)labelโ an optional string holding a regex for test labels. Equivalent to passing--label-regexon the command line. This field supports macro expansion.useUnionโ an optional bool. Equivalent to passing--unionon the command line.indexโ an optional object saying which tests to include by test index. Its fields arestart,end,strideandspecificTests(listed below). It can also be an optional string pointing at a file that uses the command line syntax for--tests-information. If you give it as a string, this field supports macro expansion.startโ an optional integer setting the test index where testing starts.endโ an optional integer setting the test index where testing stops.strideโ an optional integer setting the increment.specificTestsโ an optional array of integers naming the exact test indices to run. Iconic behaviour, honestly.
exclude โ an optional object saying which tests to exclude. Its fields:
nameโ an optional string holding a regex for test names. Equivalent to passing--exclude-regexon the command line. This field supports macro expansion.labelโ an optional string holding a regex for test labels. Equivalent to passing--label-excludeon the command line. This field supports macro expansion.fixturesโ an optional object saying which fixtures to exclude from adding tests. Its fields:anyโ an optional string holding a regex for text fixtures to exclude from adding any tests. Equivalent to passing--fixture-exclude-anyon the command line. This field supports macro expansion.setupโ an optional string holding a regex for text fixtures to exclude from adding setup tests. Equivalent to passing--fixture-exclude-setupon the command line. This field supports macro expansion.cleanupโ an optional string holding a regex for text fixtures to exclude from adding cleanup tests. Equivalent to passing--fixture-exclude-cleanupon the command line. This field supports macro expansion.
execution
An optional object full of options for how tests get executed. It may contain these fields:
stopOnFailureโ an optional bool. Iftrue, equivalent to passing--stop-on-failureon the command line.enableFailoverโ an optional bool. Iftrue, equivalent to passing-Fon the command line.jobsโ an optional integer. Equivalent to passing--parallelon the command line. If the value is0, that's equivalent to unbounded parallelism ๐ญ (yes, really, go off). If this field is set, it takes precedence over theCTEST_PARALLEL_LEVELenvironment variable โ including when that variable is instead set via this test preset's ownenvironmentfield.
Changed in presets version 11: this field can also be a string, and in that case it must be empty, and it's equivalent to passing--parallelwith<jobs>omitted.
Changed in version 4.3: this field does not accept negative integer values, regardless of the version in the presets file. So don't even try it ๐
resourceSpecFileโ an optional string. Equivalent to passing--resource-spec-fileon the command line. This field supports macro expansion.testLoadโ an optional integer. Equivalent to passing--test-loadon the command line.showOnlyโ an optional string. Equivalent to passing--show-onlyon the command line. It must be one of these two values:humanjson-v1
repeatโ an optional object saying how to repeat tests. Equivalent to passing--repeaton the command line. This object must have these fields:modeโ a required string. Must be one of these values:until-failuntil-passafter-timeout
countโ a required integer.
interactiveDebuggingโ an optional bool. Iftrue, equivalent to passing--interactive-debug-mode 1on the command line. Iffalse, equivalent to passing--interactive-debug-mode 0on the command line.scheduleRandomโ an optional bool. Iftrue, equivalent to passing--schedule-randomon the command line. Chaos mode: enabled ๐timeoutโ an optional integer. Equivalent to passing--timeouton the command line.noTestsActionโ an optional string that says what to do if no tests get found at all. Must be one of these:defaultโ equivalent to not passing any value on the command line.errorโ equivalent to passing--no-tests=erroron the command line.ignoreโ equivalent to passing--no-tests=ignoreon the command line.
If this field is set, it gets overridden by the CTEST_NO_TESTS_ACTION environment variable, including when that variable is instead set via this test preset's own environment field. See CTEST_NO_TESTS_ACTION for the full precedence order, iykyk.
testPassthroughArgumentsโ Added in presets version 12. An optional array of strings. Every single element gets forwarded as an argument to every test executable โ equivalent to passing arguments afterctest --on the command line. When both preset and command-line passthrough arguments are specified, the preset arguments appear first, followed by the command-line arguments. Order matters bestie ๐
๐ Package Preset
Added in presets version 6.
Each entry of the packagePresets array is a JSON object that may contain the following fields:
nameโ a required string, the machine-friendly name of your preset. This identifier is used in thecpack --preset <name>option. There must not be two package presets in the union ofCMakePresets.jsonandCMakeUserPresets.jsonin the same directory with the same name. That said ๐ a package preset may have the same name as a configure, build, test, or workflow preset โ cross-category name reuse is totally fine, periodt.hiddenโ an optional boolean saying whether a preset should be hidden. If a preset is hidden, it cannot be used in the--preset <name>argument and does not have to have a validconfigurePreset, even from inheritance. Hidden presets are literally meant to be used as a base for other presets to inherit via theinheritsfield. ๐ซถinheritsโ an optional array of strings: the names of the presets you're inheriting from. This field can also be a string, which is equivalent to an array containing one string.
By default the preset inherits all the fields from the inherits presets (except name, hidden, inherits, description, and displayName) โ but you can override them as much as you want. If multiple inherits presets give conflicting values for the same field, the earlier preset in the inherits array is preferred. ๐ฅ
A preset can only inherit from another preset that's defined in the same file or in one of the files it includes (directly or indirectly). Presets in CMakePresets.json may not inherit from presets in CMakeUserPresets.json. ๐ซ no sneaking around that one, bestie.
conditionโ an optionalConditionobject. (Full breakdown further down, keep scrolling โฌ๏ธ)vendorโ an optional map containing vendor-specific information. CMake does not interpret the contents of this field, except to verify that it is a map if it exists at all. However, it should follow the same conventions as the root-levelvendorfield. If vendors use their own per-presetvendorfield, they should implement inheritance in a sensible manner when appropriate. ๐คdisplayNameโ an optional string with a human-friendly name of the preset. โจdescriptionโ an optional string with a human-friendly description of the preset.environmentโ an optional map of environment variables. The key is the variable name (which may not be an empty string), and the value is eithernullor a string representing the value of the variable. Each variable is set regardless of whether or not a value was given to it by the process's environment.
This field supports macro expansion, and environment variables in this map may reference each other, and may be listed in any order โ as long as those references don't cause a cycle (for example, if ENV_1 is $env{ENV_2}, then ENV_2 may not be $env{ENV_1}). ๐ $penv{NAME} lets you prepend or append values to existing environment variables by accessing only values from the parent environment.
Environment variables are inherited through the inherits field, and the preset's environment will be the union of its own environment and the environment from all its parents. If multiple presets in this union define the same variable, the standard rules of inherits are applied (earlier wins, remember? ๐
). Setting a variable to null causes it to not be set, even if a value was inherited from another preset. ๐
configurePresetโ an optional string specifying the name of a configure preset to associate with this package preset. IfconfigurePresetis not specified, it must be inherited from theinheritspreset (unless this preset ishidden). The build directory is inferred from the configure preset, so packaging will run in the samebinaryDirthat the configuration did and the build did. ๐inheritConfigureEnvironmentโ an optional boolean that defaults totrue. Iftrue, the environment variables from the associated configure preset are inherited after all inherited package preset environments, but before environment variables explicitly specified in this package preset.generatorsโ an optional array of strings representing generators for CPack to use.configurationsโ an optional array of strings representing build configurations for CPack to package.variablesโ an optional map of variables to pass to CPack, equivalent to-Darguments. Each key is the name of a variable, and the value is the string to assign to that variable.configFileโ an optional string representing the config file for CPack to use.outputโ an optional object specifying output options. Valid keys are:debugโ an optional boolean specifying whether or not to print debug information. A value oftrueis equivalent to passing--debugon the command line.verboseโ an optional boolean specifying whether or not to print verbosely. A value oftrueis equivalent to passing--verboseon the command line.
packageNameโ an optional string representing the package name.
Note: Due to problems with the implementation, this field does not affect the name of the final package file produced. However, other aspects of the package may use the value, leading to inconsistencies. A future CMake release may address this problem, but until then, it is recommended that this field not be used. ๐
packageVersionโ an optional string representing the package version.
Note: Due to problems with the implementation, this field does not affect the name of the final package file produced. However, other aspects of the package may use the value, leading to inconsistencies. A future CMake release may address this problem, but until then, it is recommended that this field not be used. ๐
packageDirectoryโ an optional string representing the directory in which to place the package.vendorNameโ an optional string representing the vendor name.
๐ Workflow Preset ๐
Added in presets version 6.
Each entry of the workflowPresets array is a JSON object that may contain the following fields:
nameโ a required string, the machine-friendly name of the preset. This identifier is used in thecmake --workflow --preset <name>option. There must not be two workflow presets in the union ofCMakePresets.jsonandCMakeUserPresets.jsonin the same directory with the same name. However โ and this is the fun part ๐ โ a workflow preset may have the same name as a configure, build, test, or package preset.vendorโ an optional map containing vendor-specific information. CMake does not interpret the contents of this field except to verify that it is a map if it exists. However, it should follow the same conventions as the root-levelvendorfield. If vendors use their own per-presetvendorfield, they should implement inheritance in a sensible manner when appropriate. ๐คdisplayNameโ an optional string with a human-friendly name of the preset. โจdescriptionโ an optional string with a human-friendly description of the preset.stepsโ a required array of objects describing the steps of the workflow. The first step must be aconfigurepreset, and all subsequent steps must be non-configure presets whoseconfigurePresetfield matches the starting configure preset. Each object may contain the following fields:typeโ a required string. The first step must beconfigure. Subsequent steps must be eitherbuild,test, orpackage.nameโ a required string representing the name of the configure, build, test, or package preset to run as this workflow step.
๐ฎ Condition ๐ฎ
Added in presets version 3.
The condition field of a preset is used to determine whether or not the preset is enabled. For example, this can be used to disable a preset on platforms other than Windows. ๐ช condition may be either a boolean, null, or an object. If it's a boolean, the boolean indicates whether the preset is enabled or disabled. If it's null, the preset is enabled, but the null condition is not inherited by any presets that may inherit from that preset. Sub-conditions (for example in a not, anyOf, or allOf condition) may not be null. If it's an object, it has the following fields:
typeโ a required string with one of the following values:"const"โ indicates that the condition is constant. This is equivalent to using a boolean in place of the object. The condition object will have the following additional fields:valueโ a required boolean which provides a constant value for the condition's evaluation.
"equals","notEquals"โ indicates that the condition compares two strings to see if they are equal (or not equal). The condition object will have the following additional fields:lhsโ first string to compare. This field supports macro expansion.rhsโ second string to compare. This field supports macro expansion.
"inList","notInList"โ indicates that the condition searches for a string in a list of strings. The condition object will have the following additional fields:stringโ a required string to search for. This field supports macro expansion.listโ a required array of strings to search. This field supports macro expansion, and uses short-circuit evaluation. โก
"matches","notMatches"โ indicates that the condition searches for a regular expression in a string. The condition object will have the following additional fields:stringโ a required string to search. This field supports macro expansion.regexโ a required regular expression to search for. This field supports macro expansion.
"anyOf", "allOf" ๐ซถ
Okay so these two are the "group chat" of conditions โ they're saying "this condition is literally just an aggregation of zero or more nested conditions", no cap. The condition object gets these extra fields:
conditionsโ a required array of condition objects. And these ones use short-circuit evaluation, meaning it bails the second it knows the answer ๐
"not" ๐
The hater of the group โ it says the condition is an inversion of another condition. Condition object gets one extra field:
conditionโ a required condition object.
โจ Macro Expansion โจ ๐ง
So remember earlier when I said some fields support macro expansion? Yeah. Macros show up looking like $<macro-namespace>{<macro-name>}.
Big vibe to know: in general, macros get evaluated in the context of the preset being used โ even if that macro lives in a field that was inherited from some other preset. Example time: if the Base preset sets variable PRESET_NAME to ${presetName}, and Derived inherits from Base, then PRESET_NAME becomes Derived. The ${fileDir} macro as of preset version 12 is the exception to this whole rule (more on that in a sec ๐).
๐จ It is an error to not put a closing brace at the end of a macro name. Like ${sourceDir is invalid, bestie, don't do it.
A dollar sign ($) followed by anything other than a left curly brace ({) with a possible namespace? That just gets read as a literal dollar sign. Chill.
Recognized macros include:
${sourceDir}โ path to the project source directory, i.e. the same asCMAKE_SOURCE_DIR.${sourceParentDir}โ path to the project source directory's parent directory.${sourceDirName}โ the last filename component of${sourceDir}. So if${sourceDir}is/path/to/source, this would besource.${presetName}โ the name specified in the preset'snamefield. This one is a preset-specific macro.${generator}โ the generator specified in the preset'sgeneratorfield. For build and test presets, this evaluates to the generator specified byconfigurePreset. Also preset-specific.${hostSystemName}โ added in presets version 3. The name of the host operating system. Contains the same value asCMAKE_HOST_SYSTEM_NAME.${fileDir}โ added in presets version 4. Path to the directory containing the presets file which defines the preset being used.
Changed in presets version 12: this macro always expands to the directory of the current presets file containing the macro, regardless of the preset being used.
Let's walk through it, because this one is a whole storyline ๐:
/path/to/CMakePresets.jsonincludes/path/to/subdir/CMakePresets.json./path/to/subdir/CMakePresets.jsondefines presetBase, which sets variableMY_DIRto${fileDir}./path/to/CMakePresets.jsondefines presetDerived, andDerivedinherits fromBase.
Under preset versions 4-11, MY_DIR will be set to /path/to/ when using the Derived preset, and /path/to/subdir/ when using the Base preset.
When /path/to/subdir/CMakePresets.json specifies version 12 or above, MY_DIR will always be set to /path/to/subdir/, regardless of the preset being used.
๐ Note: since the ${fileDir} macro in version 12 is expanded in the context of the current presets file, it's the version of the current file โ not the version of the root file containing the preset being used โ that dictates this behavior. Iconic but tricky.
${dollar}โ a literal dollar sign ($). That's it. That's the macro.${pathListSep}โ added in presets version 5. The native character for separating lists of paths, like:or;.
So for example, by setting PATH to /path/to/ninja/bin${pathListSep}$env{PATH}, ${pathListSep} will expand to the underlying operating system's character used for concatenation in PATH.
$env{<variable-name>}โ environment variable with name <variable-name>. The variable name may not be an empty string. If the variable is defined in theenvironmentfield, that value is used instead of the value from the parent environment. If the environment variable is not defined, this evaluates as an empty string.
Watch out: while Windows environment variable names are case-insensitive, variable names within a preset are still case-sensitive. That may lead to unexpected results when you're using inconsistent casing. For best results, keep the casing of environment variable names consistent, mwah ๐
$penv{<variable-name>}โ similar to$env{<variable-name>}, except the value only comes from the parent environment, and never from theenvironmentfield. This is what lets you prepend or append values to existing environment variables. For example, settingPATHto/path/to/ninja/bin:$penv{PATH}will prepend/path/to/ninja/binto thePATHenvironment variable. This is needed because$env{<variable-name>}does not allow circular references. Slay ๐ฅ$vendor{<macro-name>}โ an extension point for vendors to insert their own macros. CMake will not be able to use presets which have a$vendor{<macro-name>}macro, and effectively ignores such presets. However, it will still be able to use other presets from the same file.
CMake does not make any attempt to interpret $vendor{<macro-name>} macros. However, to avoid name collisions, IDE vendors should prefix <macro-name> with a very short (preferably <= 4 characters) vendor identifier prefix, followed by a ., followed by the macro name. For example, the Example IDE could have $vendor{xide.ideInstallDir}.
๐ VERSIONS ๐ ๐
The JSON schema of CMake presets files follows a version scheme, where new versions are added and allowed in newer versions of CMake.
Here's the full list of supported versions, the CMake version each one landed in, and a summary of the new features and changes. Buckle up, it's a glow-up timeline โจ
1โ added in version 3.19.
The initial version supports Configure Presets and Macro Expansion.
2โ added in version 3.20.- Build Presets were added.
- Test Presets were added.
3โ added in version 3.21.- The Condition object was added for Configure, Build, and Test Presets.
- Changes to Configure Presets:
- The
installDirfield was added. - The
toolchainFilefield was added. - The
binaryDirfield is now optional. - The
generatorfield is now optional.
- The
- Changes to Macro Expansion:
- The
${hostSystemName}macro was added.
- The
4โ added in version 3.23.- Includes were added to support including other JSON files in
CMakePresets.jsonandCMakeUserPresets.json. - Changes to Build Presets:
- The
resolvePackageReferencesfield was added.
- The
- Changes to Macro Expansion:
- The
${fileDir}macro was added.
- The
- Includes were added to support including other JSON files in
5โ added in version 3.24.- Changes to Test Presets:
- The
testOutputTruncationfield was added to theoutputobject.
- The
- Changes to Macro Expansion:
- The
${pathListSep}macro was added.
- The
- Changes to Test Presets:
6โ added in version 3.25.- Package Presets were added.
- Workflow Presets were added.
- Changes to Test Presets:
- The
outputJUnitFilefield was added to theoutputobject.
- The
7โ added in version 3.27.- Changes to Configure Presets:
- The
tracefield was added.
- The
- Changes to Includes:
- The
includefield now supports$penv{}macro expansion.
- The
- Changes to Configure Presets:
8โ added in version 3.28.- The
$schemafield was added to the root object.
- The
9โ added in version 3.30.- Changes to Includes:
- The
includefield now supports other types of macro expansion.
- The
- Changes to Includes:
10โ added in version 3.31.- The optional
$commentfield was added to support documentation throughoutCMakePresets.jsonandCMakeUserPresets.json. - Changes to Configure Presets:
- The
graphvizfield was added.
- The
- The optional
11โ added in version 4.3.- Changes to Test Presets:
- The
jobsfield now accepts an empty string representing--parallelwith <jobs> omitted.
- The
- Changes to Test Presets:
12โ added in version 4.4.- Changes to Configure Presets:
- The
devfield is renamed toauthorin warnings and errors. - The
uninitializedandunusedClifields were added to errors. - The
installAbsoluteDestinationfield was added to warnings and errors.
- The
- Changes to Macro Expansion:
- The
${fileDir}macro now always expands to the directory of presets file containing the${fileDir}macro, regardless of whether it is inherited by another preset in a different directory.
- The
- Changes to Test Presets:
- The
testPassthroughArgumentsfield was added to forward arguments to test executables.
- The
- Changes to Configure Presets:
๐ SCHEMA ๐
This file provides a machine-readable JSON schema for the CMake presets file format. Go off, machine-readable queen ๐
๐ธ Copyright ๐ธ
2000-2026 Kitware, Inc. and Contributors
aaaaand that's a wrap on the whole page, bestie!! ๐ซถโจ this is CMake presets 4.4.5, dated Oct 28, 2026 โ go build something iconic with it ๐ ๐
๐ฆ where this page comes from
- arch rolling: cmake 4.4.5-1 ยท BSD-3-Clause
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms