Skip to content

Fix target selection when build type doesn't match codemodel configuration#4708

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-build-launch-target-issue
Draft

Fix target selection when build type doesn't match codemodel configuration#4708
Copilot wants to merge 4 commits intomainfrom
copilot/fix-build-launch-target-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 9, 2026

This change addresses item #4219

This changes visible behavior for build/debug/launch target selection when using CMake presets

The following changes are proposed:

  • Add fallback in cmakeFileApiDriver.ts get targets() to use the single available configuration when currentBuildType doesn't match any key in _target_map
  • Apply the same fallback in cmakeServerDriver.ts get targets()
  • Add unit tests covering the resolution logic

The purpose of this change

When using a single-config generator (e.g. Ninja) with presets that don't set CMAKE_BUILD_TYPE in cacheVariables, currentBuildType defaults to "Debug" but the CMake File API codemodel stores targets under "" (empty string). The key mismatch causes _target_map.get("Debug")undefined → empty target list.

Same issue occurs when CMAKE_BUILD_TYPE is overridden inside CMakeLists.txt itself (e.g. set to Release while the preset specifies RelWithDebInfo).

The fix: for single-config generators the target map always has exactly one entry. When the exact key lookup fails and size === 1, use that entry.

// Before
const targets = this._target_map.get(this.currentBuildType);

// After
let targets = this._target_map.get(this.currentBuildType);
if (!targets && this._target_map.size === 1) {
    targets = this._target_map.values().next().value;
}

Multi-config generators are unaffected — they have multiple entries so the fallback never triggers.

Other Notes/Information

Repro: use a CMake preset with Ninja generator, no CMAKE_BUILD_TYPE in cacheVariables, configure, then try to set build/debug/launch target via status bar or sidebar. The quick pick is empty and debug reports "Failed to prepare executable target with name "undefined"".

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 2wrvsblobprodwus2180.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • 40vvsblobprodwus2135.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • b15vsblobprodwus2164.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • b53vsblobprodwus2154.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • d94vsblobprodwus2119.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • k4pvsblobprodwus2140.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • n6wvsblobprodwus2123.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • p2tvsblobprodwus2189.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)
  • v41vsblobprodwus2175.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Unable to set build / debug / launch target</issue_title>
<issue_description>### Brief Issue Summary

Version info

VS code


Version: 1.96.2 (user setup)
Commit: fabdb6a30b49f79a7aba0f2ad9df9b399473380f
Date: 2024-12-19T10:22:47.216Z
OS: Windows_NT x64 10.0.19045

Remote server info

Linux amax 5.15.0-69-generic microsoft/vscode-cmake-tools#76~20.04.1-Ubuntu SMP Mon Mar 20 15:54:19 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Extensions on remote server

I tried

  1. v1.15.31
  2. v1.18.42
  3. v1.19.52 (latest)

Short summary

After using vcpkg and presets.json, the original system using CMakeLists failed to work using extension buttons.

Previsouly I could choose the debug/launch/build target simply by selecting from a quick list for all targets CMake Tools is aware of that can be built. But now, all the version of extensions mentioned above failed to work.

A quick list is like image.

Issue list

The last 3 captures I attached are using "v1.19.52"

1st issue: now no matter the status bar button or the sidebar button, no one shows the target quick list!

Image

2nd issue: failed to debug even if I manually typed the target name and then click "debug"!

Failed to prepare executable target with name "undefined"

Image

3rd issue: nothing is shown after I click the "launch" even if I typed the target name! Nothing!

Image

CMake Tools Diagnostics

Debug Log

[main] Configuring project: cpp-feature-snippets 
[main] Saving open files before configure/build
[driver] Start configure 
[driver] Running pre-configure checks and steps
[cmakefileapi-driver] Configuring using preset
[cmakefileapi-driver] Invoking CMake /usr/local/bin/cmake with arguments ["-DCMAKE_TOOLCHAIN_FILE=/data0/shane/mine/vcpkg/scripts/buildsystems/vcpkg.cmake","-S/data0/shane/mine/workspace/talks-snippets/cpp-feature-snippets","-B/data0/shane/mine/workspace/talks-snippets/cpp-feature-snippets/build","-G","Ninja"]
[proc] Executing command: /usr/local/bin/cmake -DCMAKE_TOOLCHAIN_FILE=/data0/shane/mine/vcpkg/scripts/buildsystems/vcpkg.cmake -S/data0/shane/mine/workspace/talks-snippets/cpp-feature-snippets -B/data0/shane/mine/workspace/talks-snippets/cpp-feature-snippets/build -G Ninja
[proc]   with environment: {"USER":"shane","LC_TIME":"zh_CN.UTF-8","SSH_CLIENT":"10.100.150.206 13245 22","XDG_SESSION_TYPE":"tty","SHLVL":"0","HOME":"/home/shane","MOTD_SHOWN":"pam","OLDPWD":"/home/shane","LC_MONETARY":"zh_CN.UTF-8","SSL_CERT_FILE":"/usr/lib/ssl/certs/ca-certificates.crt","DBUS_SESSION_BUS_ADDRESS":"unix:path=/run/user/1015/bus","LOGNAME":"shane","_":"/data0/shane/.vscode-server/cli/servers/Stable-fabdb6a30b49f79a7aba0f2ad9df9b399473380f/server/node","XDG_SESSION_CLASS":"user","XDG_SESSION_ID":"78400","VSCODE_CLI_REQUIRE_TOKEN":"aeca6ce5-64b4-4085-a03d-4d85b78a4334","PATH":"/data0/shane/.vscode-server/cli/servers/Stable-fabdb6a30b49f79a7aba0f2ad9df9b399473380f/server/bin/remote-cli:/home/shane/miniconda3/envs/py310/bin:/home/shane/miniconda3/condabin:/home/shane/.local/bin:/data0/shane/opensource/clang+llvm-15.0.6-x86_64-linux-gnu-ubuntu-18.04/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/data0/shane/mine/vcpkg","VSCODE_AGENT_FOLDER":"/home/shane/.vscode-server","XDG_RUNTIME_DIR":"/run/user/1015","LC_ADDRESS":"zh_CN.UTF-8","SSL_CERT_DIR":"/usr/lib/ssl/certs","LANG":"en_US.UTF-8","LC_TELEPHONE":"zh_CN.UTF-8","SHELL":"/bin/zsh","LC_NAME":"zh_CN.UTF-8","LC_MEASUREMENT":"zh_CN.UTF-8","LC_IDENTIFICATION":"zh_CN.UTF-8","PWD":"/home/shane","SSH_CONNECTION":"10.100.150.206 13245 10.100.120.23 22","LC_NUMERIC":"zh_CN.UTF-8","LC_PAPER":"zh_CN.UTF-8","VSCODE_CWD":"/home/shane","VSCODE_NLS_CONFIG":"{\"userLocale\":\"en\",\"osLocale\":\"en\",\"resolvedLanguage\":\"en\",\"defaultMessagesFile\":\"/data0/shane/.vscode-server/cli/servers/Stable-fabdb6a30b49f79a7aba0f2ad9df9b399473380f/server/out/nls.messages.json\",\"locale\":\"en\",\"availableLanguages\":{}}","VSCODE_HANDLES_SIGPIPE":"true","ZSH":"/home/shane/.oh-my-zsh","PAGER":"less","LESS":"-R","LSCOLORS":"Gxfxcxdxbxegedabagacad","LS_COLORS":"","AWS_PROFILE":"bizops-prod","PIP_CACHE_DIR":"/data0/shane/.cache/pip","ZOOM_PYPI_INDEX_URL":"https://shane.zhou:<hidden>@artifacts.corp.zoom.us/artifactory/api/pypi/zoom-pypi-virtual/simple","PYTHONPATH":"/home/shane/repos/ai/zoom-ml-utils/src/utils:/home/shane/repos/ai/zoom-ml-utils/src/core:/home/shane/repos/ai/unified-ai:/home/shane/repos/ai/ml-utils/src:/home/shane/repos/asr/smartchat/smart_prompt/src:/home/shan...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes microsoft/vscode-cmake-tools#4219

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI and others added 3 commits February 9, 2026 18:26
…ation

When using CMake presets without CMAKE_BUILD_TYPE set, or when CMAKE_BUILD_TYPE
is changed in CMakeLists.txt, the target map key (from CMake File API codemodel)
may not match currentBuildType. For single-config generators, fall back to the
only available configuration in the target map.

Fixes #4219

Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix unable to set build/debug/launch target in CMake Tools Fix target selection when build type doesn't match codemodel configuration Feb 9, 2026
Copilot AI requested a review from hanniavalera February 9, 2026 18:34
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.

2 participants