Skip to content

Add singleConfig/multiConfig object form for cmake.buildDirectory#4772

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/add-cmake-build-directory-option
Draft

Add singleConfig/multiConfig object form for cmake.buildDirectory#4772
Copilot wants to merge 4 commits intomainfrom
copilot/add-cmake-build-directory-option

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 27, 2026

This change addresses item #2426

This changes visible behavior

The following changes are proposed:

  • Allow cmake.buildDirectory to accept an object with singleConfig and/or multiConfig properties, selecting the appropriate template based on the active generator type
  • Pass isMultiConfFast from the CMake driver to the config reader for branch resolution
  • Check both branches in checkBuildDirectories duplicate-directory warning (generator unknown at that point)
  • Add unit tests covering string form, object form, fallbacks, and defaults

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 different cmake.buildDirectory templates 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 to oneOf (string | object with singleConfig/multiConfig)
  • package.nls.json — descriptions for the new sub-properties
  • src/config.tsbuildDirectory type widened, isMultiConfig?: boolean parameter added to resolution method, defaultBuildDirectoryValue constant extracted
  • src/drivers/cmakeDriver.ts_refreshExpansions() and setKit() now pass this.isMultiConfFast
  • src/projectController.tscheckBuildDirectories() checks both branches of object form
  • test/unit-tests/config.test.ts — 8 new tests; fixed a test that was calling buildDirectory(true) which fails in the VS Code test host because isDefaultValue() checks real vscode.workspace.getConfiguration, not internal configData
  • CHANGELOG.md — feature entry

No changes needed for CMake Presets modebinaryDir comes from the preset itself.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature] Add option to specify cmake.buildDirectory for 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 Makefiles or NMake Makefiles, one Makefile file only supports one configuration. So in order to differentiate Debug and Release configurations, I will set cmake.buildDirectory like this:

{
  "cmake.buildDirectory": 
    "${workspaceFolder}/build/${buildKitTargetOs}-${buildKitVendor}-${buildKitTargetArch}-${buildType}"
}

The possible results of build directories will look like this:

build/
    win32-MSVC-x64-Debug/
    win32-MSVC-x64-Release/
    win32-MSVC-x86-Debug/
    win32-MSVC-x86-Release/
    win32-GCC-x86-Debug/
    win32-GCC-x86-Release/
    win32-GCC-x86-MinSizeRel/

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 of cmake.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.buildDirectory for 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 of cmake.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:

  • Visual Studio Code Version: 1.65.2
  • CMake Tools Version: 1.9.2
  • CMake Version: 3.21.2</issue_description>

<agent_instructions>## Feature: Add per-generator-type cmake.buildDirectory support (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} in cmake.buildDirectory.
Multi-config generators (Ninja Multi-Config, Visual Studio, Xcode) manage all configurations in one
directory, making ${buildType} wasteful.

Today there is no way to specify different cmake.buildDirectory values for the two cases. The request is
to 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 — schema

cmake.buildDirectory is currently declared as a "type": "string". Change it to accept either a string
or an object with optional singleConfig / multiConfig string properties (use oneOf). Add a clear markdownDescription that explains when each form is chosen. Follow the style of nearby settings.

2. src/config.ts — type + reader

  • In ExtensionConfigurationSettings, change the buildDirectory field from string to
    ...

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 27, 2026 18:27
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add option to specify cmake.buildDirectory for single- and multi-config generators, respectively

2 participants