Fix target selection when build type doesn't match codemodel configuration#4708
Draft
Fix target selection when build type doesn't match codemodel configuration#4708
Conversation
…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
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 #4219
This changes visible behavior for build/debug/launch target selection when using CMake presets
The following changes are proposed:
cmakeFileApiDriver.tsget targets()to use the single available configuration whencurrentBuildTypedoesn't match any key in_target_mapcmakeServerDriver.tsget targets()The purpose of this change
When using a single-config generator (e.g. Ninja) with presets that don't set
CMAKE_BUILD_TYPEincacheVariables,currentBuildTypedefaults 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_TYPEis overridden insideCMakeLists.txtitself (e.g. set toReleasewhile the preset specifiesRelWithDebInfo).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.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_TYPEincacheVariables, 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/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install(dns block)40vvsblobprodwus2135.vsblob.vsassets.io/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install(dns block)b15vsblobprodwus2164.vsblob.vsassets.io/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install(dns block)b53vsblobprodwus2154.vsblob.vsassets.io/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install(dns block)d94vsblobprodwus2119.vsblob.vsassets.io/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install(dns block)k4pvsblobprodwus2140.vsblob.vsassets.io/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install(dns block)n6wvsblobprodwus2123.vsblob.vsassets.io/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install(dns block)p2tvsblobprodwus2189.vsblob.vsassets.io/home/REDACTED/work/_temp/ghcca-node/node/bin/node node /usr/local/bin/yarn install(dns block)v41vsblobprodwus2175.vsblob.vsassets.io/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
Remote server info
Extensions on remote server
I tried
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!
2nd issue: failed to debug even if I manually typed the target name and then click "debug"!
3rd issue: nothing is shown after I click the "launch" even if I typed the target name! Nothing!
CMake Tools Diagnostics
Debug Log