Add singleConfig/multiConfig object form for cmake.buildDirectory#4772
Draft
Add singleConfig/multiConfig object form for cmake.buildDirectory#4772
Conversation
…ry (#2426) Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
…t per review Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add option to specify cmake.buildDirectory for generators
Add singleConfig/multiConfig object form for cmake.buildDirectory
Feb 27, 2026
…est host
The test was calling buildDirectory(true) which triggers isDefaultValue()
that checks real vscode.workspace.getConfiguration. In CI's VS Code test
host, no workspace override exists, so isDefaultValue returns true and the
method returns '${sourceDirectory}/build' instead of the custom value.
Changed the test to use multiProject=false since the multiProject=true
codepath depends on VS Code workspace state that cannot be mocked in
the unit test infrastructure.
Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change addresses item #2426
This changes visible behavior
The following changes are proposed:
cmake.buildDirectoryto accept an object withsingleConfigand/ormultiConfigproperties, selecting the appropriate template based on the active generator typeisMultiConfFastfrom the CMake driver to the config reader for branch resolutioncheckBuildDirectoriesduplicate-directory warning (generator unknown at that point)The purpose of this change
Single-config generators (Make, Ninja) typically need
${buildType}in the build path to separate configurations; multi-config generators (Visual Studio, Ninja Multi-Config, Xcode) don't. Today there's no way to use differentcmake.buildDirectorytemplates per generator type.New object form alongside the existing string form (fully backward-compatible):
{ "cmake.buildDirectory": { "singleConfig": "${workspaceFolder}/build/${buildKitTargetArch}-${buildType}", "multiConfig": "${workspaceFolder}/build/${buildKitTargetArch}" } }If only one key is provided, the other falls back to it. If neither is set, falls back to
${workspaceFolder}/build.Other Notes/Information
Files changed:
package.json— schema updated tooneOf(string | object withsingleConfig/multiConfig)package.nls.json— descriptions for the new sub-propertiessrc/config.ts—buildDirectorytype widened,isMultiConfig?: booleanparameter added to resolution method,defaultBuildDirectoryValueconstant extractedsrc/drivers/cmakeDriver.ts—_refreshExpansions()andsetKit()now passthis.isMultiConfFastsrc/projectController.ts—checkBuildDirectories()checks both branches of object formtest/unit-tests/config.test.ts— 8 new tests; fixed a test that was callingbuildDirectory(true)which fails in the VS Code test host becauseisDefaultValue()checks realvscode.workspace.getConfiguration, not internalconfigDataCHANGELOG.md— feature entryNo changes needed for CMake Presets mode —
binaryDircomes from the preset itself.Original prompt
This section details on the original issue you should resolve
<issue_title>[Feature] Add option to specify
cmake.buildDirectoryfor single- and multi-config generators, respectively</issue_title><issue_description>## Problem Description
In CMake Generator, there are single- and multi-config generator to choose. If we use single-config, such as
MinGW Makefiles, I would like to separate build directories for Configurations and Architectures. Thanks to the Substitution Variable provided by CMake-Tools, we can design our custom build directory.1. Single-Config Generator
If I use single-config Generator, for example
MinGW MakefilesorNMake Makefiles, one Makefile file only supports one configuration. So in order to differentiate Debug and Release configurations, I will setcmake.buildDirectorylike this:{ "cmake.buildDirectory": "${workspaceFolder}/build/${buildKitTargetOs}-${buildKitVendor}-${buildKitTargetArch}-${buildType}" }The possible results of build directories will look like this:
2. Multi-Config Generator
However, if I choose to use multi-config generators such as
Ninja Multi-Config, it is a waste to separate different configurations into individual sub-folders. So I will delete${buildType}variable from the single-config format. Here is my format ofcmake.buildDirectory:{ "cmake.buildDirectory": "${workspaceFolder}/build/${buildKitTargetOs}-${buildKitVendor}-${buildKitTargetArch}" }The possible results of build directories will look like:
build/ win32-MSVC-x64/ win32-MSVC-x86/ win32-GCC-x64/ win32-GCC-x86/Expected Setting
I hope CMake-Tools can give us an option to set
cmake.buildDirectoryfor single-config and multi-config, respectively. And Then CMake-Tools will auto-detect which type our currently-used generator belongs to, single-config or multi-config.For example:
{ "cmake.buildDirectory": { "singleConfig": "${workspaceFolder}/build", "multiConfig": "${workspaceFolder}/build", } }Of course, we can still retain the original format of
cmake.buildDirectory. That means both single- and multi-config will use the same format ofcmake.buildDirectory:{ "cmake.buildDirectory": "${workspaceFolder}/build/${buildKitHostOs}_${buildKitTargetOs}" }In my case, I would like to set this settings like this:
{ "cmake.buildDirectory": { "singleConfig": "${workspaceFolder}/build/${buildKitTargetOs}-${buildKitVendor}-${buildKitTargetArch}-${buildType}", "multiConfig": "${workspaceFolder}/build/${buildKitTargetOs}-${buildKitVendor}-${buildKitTargetArch}" } }Platform and Version:
<agent_instructions>## Feature: Add per-generator-type
cmake.buildDirectorysupport (single-config vs. multi-config)Background
Issue: #2426 - #2426
Single-config generators (e.g.
MinGW Makefiles,NMake Makefiles,Unix Makefiles) require a separate build directory per build type, so users typically include${buildType}incmake.buildDirectory.Multi-config generators (
Ninja Multi-Config,Visual Studio,Xcode) manage all configurations in onedirectory, making
${buildType}wasteful.Today there is no way to specify different
cmake.buildDirectoryvalues for the two cases. The request isto allow an object form alongside the existing string form:
{ "cmake.buildDirectory": { "singleConfig": "${workspaceFolder}/build/${buildKitTargetOs}-${buildKitVendor}-${buildKitTargetArch}-${buildType}", "multiConfig": "${workspaceFolder}/build/${buildKitTargetOs}-${buildKitVendor}-${buildKitTargetArch}" } }The existing plain-string form must continue to work — this is a purely additive change.
What to change — starting points only, explore freely
1.
package.json— schemacmake.buildDirectoryis currently declared as a"type": "string". Change it to accept either a stringor an object with optional
singleConfig/multiConfigstring properties (useoneOf). Add a clearmarkdownDescriptionthat explains when each form is chosen. Follow the style of nearby settings.2.
src/config.ts— type + readerExtensionConfigurationSettings, change thebuildDirectoryfield fromstringto...
cmake.buildDirectoryfor single- and multi-config generators, respectively #2426💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.