cmake-presets(7)¶
Contents
Introduction¶
One problem that CMake users often face is sharing settings with other people
for common ways to configure a project. This may be done to support CI builds,
or for users who frequently use the same build. CMake supports two files,
CMakePresets.json and CMakeUserPresets.json, that allow users to
specify common configure options and share them with others.
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 is specified.)
CMakePresets.json is meant to save project-wide builds, while
CMakeUserPresets.json is meant for developers to save their own local
builds. 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.
Format¶
The files are a JSON document with an object as the root:
{
"version": 2,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"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"
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
}
],
"testPresets": [
{
"name": "default",
"configurePreset": "default",
"output": {"outputOnFailure": true},
"execution": {"noTestsAction": "error", "stopOnFailure": true}
}
],
"vendor": {
"example.com/ExampleIDE/1.0": {
"autoFormat": false
}
}
}
The root object recognizes the following fields:
version
A required integer representing the version of the JSON schema. The supported versions are
1and2.
cmakeMinimumRequired
An optional object representing the minimum version of CMake needed to build this project. This object consists of the following fields:
majorAn optional integer representing the major version.
minorAn optional integer representing the minor version.
patchAn optional integer representing the patch version.
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. This is allowed in preset files specifying version 1 or above.
buildPresets
An optional array of Build Preset objects. This is allowed in preset files specifying version 2 or above.
testPresets
An optional array of Test Preset objects. This is allowed in preset files specifying version 2 or above.
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 the cmake --preset option. There must not be two configure presets in the union of
CMakePresets.jsonandCMakeUserPresets.jsonin the same directory with the same name. However, a configure preset may have the same name as a build or test 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=argument, will not show up in theCMake GUI, 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 to inherit from. The preset will inherit all of the fields from the
inheritspresets by default (exceptname,hidden,inherits,description, anddisplayName), but can override them as desired. If multipleinheritspresets provide conflicting values for the same field, the earlier preset in theinheritslist will be preferred. Presets inCMakePresets.jsonmay not inherit from presets inCMakeUserPresets.json.This field can also be a string, which is equivalent to an array containing one string.
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-level
vendorfield. 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.
generator
An optional string representing the generator to use for the preset. If
generatoris not specified, it must be inherited from theinheritspreset (unless this preset ishidden).Note that for Visual Studio generators, unlike in the command line
-Gargument, you cannot include the platform name in the generator name. Use thearchitecturefield instead.
architecture, toolset
Optional fields representing the platform and toolset, respectively, for generators that support them. Each may be either a string or an object with the following fields:
valueAn optional string representing the value.
strategyAn optional string telling CMake how to handle the
architectureortoolsetfield. 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 the
architectureandtoolsetfields. In that case, CMake will ignore the field, but the IDE can use them to set up the environment before invoking CMake.
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. If
binaryDiris not specified, it must be inherited from theinheritspreset (unless this preset ishidden).
cmakeExecutable
An optional string representing the path to the CMake executable to use for this preset. This 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 either
null, 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:
typeAn optional string representing the type of the variable.
valueA 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
inheritsfield, and the preset's variables will be the union of its owncacheVariablesand thecacheVariablesfrom 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.
environment
An optional map of environment variables. The key is the variable name (which may not be an empty string), and the value is either
nullor 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, ifENV_1is$env{ENV_2},ENV_2may not be$env{ENV_1}.)Environment variables are inherited through the
inheritsfield, and the preset's environment will be the union of its ownenvironmentand theenvironmentfrom 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.
warnings
An optional object specifying the warnings to enable. The object may contain the following fields:
devAn optional boolean. Equivalent to passing
-Wdevor-Wno-devon the command line. This may not be set tofalseiferrors.devis set totrue.
deprecatedAn optional boolean. Equivalent to passing
-Wdeprecatedor-Wno-deprecatedon the command line. This may not be set tofalseiferrors.deprecatedis set totrue.
uninitializedAn optional boolean. Setting this to
trueis equivalent to passing--warn-uninitializedon the command line.
unusedCliAn optional boolean. Setting this to
falseis equivalent to passing--no-warn-unused-clion the command line.
systemVarsAn optional boolean. Setting this to
trueis equivalent to passing--check-system-varson the command line.
errors
An optional object specifying the errors to enable. The object may contain the following fields:
devAn optional boolean. Equivalent to passing
-Werror=devor-Wno-error=devon the command line. This may not be set totrueifwarnings.devis set tofalse.
deprecatedAn optional boolean. Equivalent to passing
-Werror=deprecatedor-Wno-error=deprecatedon the command line. This may not be set totrueifwarnings.deprecatedis set tofalse.
debug
An optional object specifying debug options. The object may contain the following fields:
outputAn optional boolean. Setting this to
trueis equivalent to passing--debug-outputon the command line.
tryCompileAn optional boolean. Setting this to
trueis equivalent to passing--debug-trycompileon the command line.
findAn optional boolean. Setting this to
trueis equivalent to passing--debug-findon the command line.
Build Preset¶
Each entry of the buildPresets 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 the cmake --build --preset option. There must not be two build presets in the union of
CMakePresets.jsonandCMakeUserPresets.jsonin the same directory with the same name. However, a build preset may have the same name as a configure or test 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
--presetargument and does not have to have a validconfigurePreset, 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 to inherit from. The preset will inherit all of the fields from the
inheritspresets by default (exceptname,hidden,inherits,description, anddisplayName), but can override them as desired. If multipleinheritspresets provide conflicting values for the same field, the earlier preset in theinheritslist will be preferred. Presets inCMakePresets.jsonmay not inherit from presets inCMakeUserPresets.json.This field can also be a string, which is equivalent to an array containing one string.
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-level
vendorfield. 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 either
nullor 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, ifENV_1is$env{ENV_2},ENV_2may not be$env{ENV_1}.)Environment variables are inherited through the
inheritsfield, and the preset's environment will be the union of its ownenvironmentand theenvironmentfrom 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.
configurePreset
An optional string specifying the name of a configure preset to associate with this build preset. If
configurePresetis not specified, it must be inherited from the inherits preset (unless this preset is hidden). The build directory is inferred from the configure preset, so the build will take place in the samebinaryDirthat the configuration did.
inheritConfigureEnvironment
An optional boolean that defaults to true. If true, the environment variables from the associated configure preset are inherited after all inherited build preset environments, but before environment variables explicitly specified in this build preset.
jobs
An optional integer. Equivalent to passing
--parallelor-jon the command line.
targets
An optional string or array of strings. Equivalent to passing
--targetor-ton the command line. Vendors may ignore the targets property or hide build presets that explicitly specify targets. This field supports macro expansion.
configuration
An optional string. Equivalent to passing
--configon the command line.
cleanFirst
An optional bool. If true, equivalent to passing
--clean-firston the command line.
verbose
An optional bool. If true, equivalent to passing
--verboseon the command line.
nativeToolOptions
An optional array of strings. Equivalent to passing options after
--on the command line. The array values support macro expansion.
Test Preset¶
Each entry of the testPresets 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 the ctest --preset option. There must not be two test presets in the union of
CMakePresets.jsonandCMakeUserPresets.jsonin the same directory with the same name. However, a test preset may have the same name as a configure or build 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
--presetargument and does not have to have a validconfigurePreset, 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 to inherit from. The preset will inherit all of the fields from the
inheritspresets by default (exceptname,hidden,inherits,description, anddisplayName), but can override them as desired. If multipleinheritspresets provide conflicting values for the same field, the earlier preset in theinheritslist will be preferred. Presets inCMakePresets.jsonmay not inherit from presets inCMakeUserPresets.json.This field can also be a string, which is equivalent to an array containing one string.
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-level
vendorfield. 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 either
nullor 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, ifENV_1is$env{ENV_2},ENV_2may not be$env{ENV_1}.)Environment variables are inherited through the
inheritsfield, and the preset's environment will be the union of its ownenvironmentand theenvironmentfrom 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.
configurePreset
An optional string specifying the name of a configure preset to associate with this test preset. If
configurePresetis not specified, it must be inherited from the inherits preset (unless this preset is hidden). The build directory is inferred from the configure preset, so tests will run in the samebinaryDirthat the configuration did and build did.
inheritConfigureEnvironment
An optional boolean that defaults to true. If true, 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.
configuration
An optional string. Equivalent to passing
--build-configon 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.
shortProgressAn optional bool. If true, equivalent to passing
--progresson the command line.
verbosityAn optional string specifying verbosity level. Must be one of the following:
defaultEquivalent to passing no verbosity flags on the command line.
verboseEquivalent to passing
--verboseon the command line.
extraEquivalent to passing
--extra-verboseon the command line.
debugAn optional bool. If true, equivalent to passing
--debugon the command line.
outputOnFailureAn optional bool. If true, equivalent to passing
--output-on-failureon the command line.
quietAn optional bool. If true, equivalent to passing
--quieton the command line.
outputLogFileAn optional string specifying a path to a log file. Equivalent to passing
--output-logon the command line. This field supports macro expansion.
labelSummaryAn optional bool. If false, equivalent to passing
--no-label-summaryon the command line.
subprojectSummaryAn optional bool. If false, equivalent to passing
--no-subproject-summaryon the command line.
maxPassedTestOutputSizeAn optional integer specifying the maximum output for passed tests in bytes. Equivalent to passing
--test-output-size-passedon the command line.
maxFailedTestOutputSizeAn optional integer specifying the maximum output for failed tests in bytes. Equivalent to passing
--test-output-size-failedon the command line.
maxTestNameWidthAn optional integer specifying the maximum width of a test name to output. Equivalent to passing
--max-widthon the command line.
filter
An optional object specifying how to filter the tests to run. The object may contain the following fields.
includeAn optional object specifying which tests to include. The object may contain the following fields.
nameAn optional string specifying a regex for test names. Equivalent to passing
--tests-regexon the command line. This field supports macro expansion.
labelAn optional string specifying a regex for test labels. Equivalent to passing
--label-regexon the command line. This field supports macro expansion.
useUnionAn optional bool. Equivalent to passing
--unionon the command line.
indexAn optional object specifying tests to include by test index. The object may contain the following fields. Can also be an optional string specifying a file with the command line syntax for
--tests-information. If specified as a string, this field supports macro expansion.
startAn optional integer specifying a test index to start testing at.
endAn optional integer specifying a test index to stop testing at.
strideAn optional integer specifying the increment.
specificTestsAn optional array of integers specifying specific test indices to run.
excludeAn optional object specifying which tests to exclude. The object may contain the following fields.
nameAn optional string specifying a regex for test names. Equivalent to passing
--exclude-regexon the command line. This field supports macro expansion.
labelAn optional string specifying a regex for test labels. Equivalent to passing
--label-excludeon the command line. This field supports macro expansion.
fixturesAn optional object specifying which fixtures to exclude from adding tests. The object may contain the following fields.
anyAn optional string specifying a regex for text fixtures to exclude from adding any tests. Equivalent to
--fixture-exclude-anyon the command line. This field supports macro expansion.
setupAn optional string specifying a regex for text fixtures to exclude from adding setup tests. Equivalent to
--fixture-exclude-setupon the command line. This field supports macro expansion.
cleanupAn optional string specifying a regex for text fixtures to exclude from adding cleanup tests. Equivalent to
--fixture-exclude-cleanupon the command line. This field supports macro expansion.
execution
An optional object specifying options for test execution. The object may contain the following fields.
stopOnFailureAn optional bool. If true, equivalent to passing
--stop-on-failureon the command line.
enableFailoverAn optional bool. If true, equivalent to passing
-Fon the command line.
jobsAn optional integer. Equivalent to passing
--parallelon the command line.
resourceSpecFileAn optional string. Equivalent to passing
--resource-spec-fileon the command line. This field supports macro expansion.
testLoadAn optional integer. Equivalent to passing
--test-loadon the command line.
showOnlyAn optional string. Equivalent to passing
--show-onlyon the command line. The string must be one of the following values:
human
json-v1
repeatAn optional object specifying how to repeat tests. Equivalent to passing
--repeaton the command line. The object must have the following fields.
modeA required string. Must be one of the following values:
until-fail
until-pass
after-timeout
countA required integer.
interactiveDebuggingAn optional bool. If true, equivalent to passing
--interactive-debug-mode 1on the command line. If false, equivalent to passing--interactive-debug-mode 0on the command line.
scheduleRandomAn optional bool. If true, equivalent to passing
--schedule-randomon the command line.
timeoutAn optional integer. Equivalent to passing
--timeouton the command line.
noTestsActionAn optional string specifying the behavior if no tests are found. Must be one of the following values:
defaultEquivalent to not passing any value on the command line.
errorEquivalent to passing
--no-tests=erroron the command line.
ignoreEquivalent to passing
--no-tests=ignoreon the command line.
Macro Expansion¶
As mentioned above, some fields support macro expansion. Macros are
recognized in the form $<macro-namespace>{<macro-name>}. All macros are
evaluated in the context of the preset being used, even if the macro is in a
field that was inherited from another preset. For example, if the Base
preset sets variable PRESET_NAME to ${presetName}, and the
Derived preset inherits from Base, PRESET_NAME will be set to
Derived.
It is an error to not put a closing brace at the end of a macro name. For
example, ${sourceDir is invalid. A dollar sign ($) followed by
anything other than a left curly brace ({) with a possible namespace is
interpreted as a literal dollar sign.
Recognized macros include:
${sourceDir}
Path to the project source directory.
${sourceParentDir}
Path to the project source directory's parent directory.
${sourceDirName}
The last filename component of
${sourceDir}. For example, if${sourceDir}is/path/to/source, this would besource.
${presetName}
Name specified in the preset's
namefield.
${generator}
Generator specified in the preset's
generatorfield. For build and test presets, this will evaluate to the generator specified byconfigurePreset.
${dollar}
A literal dollar sign (
$).
$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.Note that while Windows environment variable names are case-insensitive, variable names within a preset are still case-sensitive. This may lead to unexpected results when using inconsistent casing. For best results, keep the casing of environment variable names consistent.
$penv{<variable-name>}
Similar to
$env{<variable-name>}, except that the value only comes from the parent environment, and never from theenvironmentfield. This allows you to 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.
$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}.
Schema¶
This file provides a machine-readable
JSON schema for the CMakePresets.json format.