Infer MSVC dev environment from preset structure without explicit compiler#4779
Open
Infer MSVC dev environment from preset structure without explicit compiler#4779
Conversation
Copilot AI
added a commit
that referenced
this pull request
Mar 2, 2026
Co-authored-by: hanniavalera <90047725+hanniavalera@users.noreply.github.com>
Detect VS Developer Environment signals from preset structure (VS generator, external toolset/architecture strategy) without requiring explicit CMAKE_CXX_COMPILER in cacheVariables. Add log.info hint when auto mode skips VS Dev Env on Windows. Fixes #4225 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] Improve automatic setup of MSVC dev environment with presets
Infer MSVC dev environment from preset structure without explicit compiler
Mar 2, 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 #4225
This changes visible behavior and documentation
The following changes are proposed:
strategy: "external"on toolset/architecture) without requiring explicitCMAKE_CXX_COMPILER: "cl"incacheVariableslog.infohint on Windows when auto mode skips VS Dev Env setup, so users understand why builds may faildocs/cmake-presets.mdThe purpose of this change
In
"auto"mode,tryApplyVsDevEnvonly activated whenCMAKE_CXX_COMPILERorCMAKE_C_COMPILERwas explicitly set to a recognized compiler incacheVariables. Visual Studio and CLion infer MSVC intent from thetoolset/architecturefields alone. This caused friction for users sharing presets across IDEs.Now, three additional signals trigger VS Dev Env setup in auto mode:
"generator": "Visual Studio 17 2022")"toolset": { "strategy": "external" }"architecture": { "strategy": "external" }This means presets like the following now work without the
clcompiler hint:{ "name": "ninja-msvc", "generator": "Ninja", "toolset": { "value": "v143", "strategy": "external" }, "architecture": { "value": "x64", "strategy": "external" } }Other Notes/Information
hasVsDevEnvSignals()pure function handles signal detection, tested independently"always"and"never"modes are unchangedCMAKE_CXX_COMPILERfollow the same path as before (backward compatible)setstrategy, string toolset), and combined signalsOriginal prompt
This section details on the original issue you should resolve
<issue_title>Improve automatic setup of MSVC dev environment with presets</issue_title>
<issue_description>### Brief Issue Summary
Feedback from Customers:
There should be better feedback about automatic setup of MSVC dev environment with presets. It took me a long time to figure out that I needed to set CMAKE_CXX_COMPILER to cl.exe explicitly in my CMakePresets.json for it to work. Since this is not needed for typical command line / CI workflows where you set up the environment manually (and rely on CMake to correctly guess that you want to compile with MSVC), some help from IDE is desirable here.
From what I can tell, Visual Studio and even JetBrains CLion do not need "CMAKE_CXX_COMPILER": "cl" as an explicit hint in the preset to provide the MSVC environment setup, just the toolset/architecture keys are enough.
Would it be possible to drop this requirement in cmake-tools, reducing friction with presets authored by/for other tools/IDEs?
CMake Tools Diagnostics
Debug Log
Additional Information
No response</issue_description>
<agent_instructions>## Fix Issue #4225 — Improve automatic MSVC dev environment setup with presets
Context
Issue: #4225
HEAD commit at time of writing:
c7ce06129bcfc8248383d93b6d2cb52f00b2394aUsers with presets that use Ninja + MSVC (a common cross-IDE pattern) must currently add
"CMAKE_CXX_COMPILER": "cl"explicitly to theircacheVariablesfor cmake-tools to automatically set up the VS Developer Environment. Visual Studio and CLion do not require this — they infer MSVC intent from thetoolsetandarchitecturefields alone. This is a friction point for users sharing presets across IDEs.Primary entry point
Start your investigation at:
This is the only place where the VS Dev Env decision is made. In
"auto"mode, the function only activates ifCMAKE_CXX_COMPILERorCMAKE_C_COMPILERis explicitly set to a supported compiler name inpreset.cacheVariables. If neither is present, it silently skips setup with no user feedback.Also read:
getToolset()andgetArchitecture()(same file) — these already parse thetoolsetandarchitecturepreset fieldsutil.isSupportedCompiler()insrc/util.ts— the compiler name allowlisttest/unit-tests/presets/presets.test.ts— existing test patterns for this functiondocs/cmake-presets.md— user-facing documentation for this featureProblem to solve
When a configure preset has no explicit
CMAKE_CXX_COMPILER/CMAKE_C_COMPILERbut does have one of these MSVC-intent signals:"generator": "Visual Studio 17 2022")"toolset": { "value": "...", "strategy": "external" }— the"external"strategy explicitly means "the calling IDE should set up the environment""architecture": { "value": "x64", "strategy": "external" }…then cmake-tools should still attempt to activate the VS Dev Env in
"auto"mode, just as it does whenCMAKE_CXX_COMPILER: "cl"is present.Additionally, when
"auto"mode silently skips VS Dev Env on Windows, a user-visiblelog.infomessage should be emitted so users understand why their build may fail and how to fix it.Suggested approach (investigate and improve upon as needed)
This is a starting point — do your own investigation and deviate if the codebase reveals a better or cleaner pattern.
The key change in
tryApplyVsDevEnv:If
effectiveCompilerNameis set butcompilerNamewas not (i.e. inferred), proceed withgetVsDevEnvas normal.When neither
compilerNamenorinfersMsvcis true and we are on Windows, emit: