Configuring CMake Tools

CMake Tools supports a variety of settings that can be set at the user orworkspace level via VSCode’ssettings.json file. This page talks aboutthe available options and how they are used.

Options marked withSupports substitution allow variable references to appearin their strings. See theVariable Substitution section

Available Settings

cmake.buildArgs

An array of additional arguments to pass tocmake--build.

  • Default:[] (Empty array, no additional arguments)

  • Supports substitution

cmake.buildBeforeRun

Iftrue, build the launch/debug target before letting it execute.

  • Default:true

cmake.buildDirectory

Specify the build directory (The root directory whereCMakeCache.txt willbe generated).

  • Default:${workspaceFolder}/build.

  • Supports substitution

cmake.buildEnvironment

An object containingkey:value pairs of environment variables,which will be passedONLY onto the compiler.

  • Default:null (Unspecified)

  • Supports substitution

cmake.buildToolArgs

An array of additional arguments to pass tothe underlying build tool.

  • Default:[] (Empty array, no additional arguments)

  • Supports substitution

cmake.cacheInit

Path or list of paths to cache-initialization files. Passed to CMake via the-C command-line argument.

  • Default:[] (Empty array, no cache initializer files)

cmake.cmakePath

Specify location of the cmake executable.

  • Default:cmake, which causes CMake Tools to search thePATH environmentvariable, as well as some hard-coded guesses.

  • Supports substitution ofworkspaceRoot,workspaceFolder,workspaceRootFolderName,userHome,${command:...} and${env:...}. Other substitutions willresult in empty string.

cmake.configureArgs

Arguments to CMake that will be passed during the configure process.

  • Default:[] (Empty array, no arguments)

  • Supports substitution

Warning

Always prefer to usecmake.configureSettings orCMake Variants.Never pass-D arguments using this setting.

cmake.configureEnvironment

An object containingkey:value pairs of environment variables,which will be passed onto CMakeONLY when configuring.

  • Default:null (Unspecified)

  • Supports substitution

cmake.configureSettings

An object containingkey:value pairs, which will bepassed onto CMake when configuring.It does the same thing as passing-DVAR_NAME=ON viacmake.configureArgs.

  • Default:null (Unspecified)

  • Supports substitution

cmake.copyCompileCommands

If notnull, copies thecompile_commands.json file generated by CMaketo the path specified by this setting every time CMake successfully configures.

  • Default:null (Do not copy the file)

  • Supports substitution

cmake.defaultVariants

Override the default set of variants that will be supplied when no variants fileis present. SeeCMake Variants.

cmake.environment

An object containingkey:value pairs of environment variables,which will be passed onto CMake when configuring and to the compiler.

  • Default:null (Unspecified)

  • Supports substitution

cmake.generator

Set to a string to override CMake Tools’preferred generator logic. If this isset, CMake will unconditionally use it as the-G CMake generator commandline argument.

cmake.installPrefix

If specified, sets a value forCMAKE_INSTALL_PREFIX when running CMakeconfigure. If not, no value will be passed.

  • Default:null (Unspecified)

  • Supports substitution

Note

IfCMAKE_INSTALL_PREFIX is set viacmake.configureArgs orcmake.configureSettings,cmake.installPrefix will be ignored.

cmake.loggingLevel

An enumerated string setting to change the amount of output CMake Toolsproduces in its output channel. Set to one of “trace”, “debug”, “info”, “note”,“warning”, “error”, or “fatal”, with “trace” being the most verbose.

  • Default:info

Note

Regardless of the logging level, CMake Tools writesall levels of loggingto the CMake Tools log file. This file is useful fortroubleshooting.

cmake.mingwSearchDirs

List of paths to search for a MinGW installation. This means that GCC does notneed to be on your$PATH for it to be found via Kit scanning.

  • Default:["C:\\MinGW"] (Search in C:\MinGW for a MinGW installation)

cmake.parallelJobs

By specifying a number, you can define how many jobs are run in parallel during the build.

cmake.preferredGenerators

A list of strings of generator names to try in order when configuring a CMakeproject for the first time.

cmake.saveBeforeBuild

Iftrue (the default), saves open text documents when build or configure isinvoked before running CMake.

  • Default:true

cmake.sourceDirectory

Directory where the rootCMakeLists.txt will be found.

  • Default:${workspaceFolder}

  • Supports substitution

Variable Substitution

Some options support the replacement of special values in their string valueusing${variable} syntax. The following built-in variables are expanded:

${workspaceRoot}

DEPRECATED. The full path to the workspace root directory

${workspaceFolder}

The full path to the workspace root directory

${workspaceRootFolderName}

The name of the leaf directory in the workspace directory path

${buildType}

The current CMake build type, eg.Debug,Release,MinSizeRel

${buildKit}

The current CMake kit name, eg.GCC7.3.0

${generator}

The name of the CMake generator, eg.Ninja

${projectName}

DEPRECATED. Expands to the constant string “ProjectName

Note

This was deprecated as CMake does not consider there to beoneproject name to use. The concept of a single project does not work inCMake, and this made this feature problematic and buggy. Alternativesinclude${workspaceRootFolderName}.

${userHome}

The full path to the current user’s home directory

Environment Variables

Additionally, environment variables may be substituted with${env:VARNAME}and${env.VARNAME} syntax, where the string for theVARNAME environmentvariable will be replaced. If the named environment variable is undefined, an emptystring will be expanded instead.

Variant Substitution

Variant options may also be substituted with the${variant:VARIANTNAME} syntax,where the name of the currently active choice of the providedVARIANTNAME variantoption will be replaced. If the variant option is undefined, an empty string will beexpanded instead.

Command Substitution

CMake Tools also supports expanding of VSCode commands, similar tolaunch.json. Running a command${command:foo.bar} will execute thefoo.bar VSCode command and replace the string value. Beware of long-runningcommands! It is unspecified when and how many times CMake Tools will execute acommand for a given expansion.