microsoft / microsoft/vscode-cmake-tools
Presets: How to inherit the MSVC environment when toolchains are in use?
- Dominant language
- TypeScript
- Stars
- 1.7k
- Forks
- 546
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 32
Description
When generating with Ninja, there is an expectation that the compilation environment is already set up. This basically means that for MSVC projects, we need to figure out the architecture and toolset prior to invoking CMake. When using Kits and Variants, this is not a problem because the user declares their intent. For presets, we look at the value of `CMAKE_C|CXX_COMPILER` and if it looks like the MSVC compiler, we set up the environment (sneakily using the Kits) prior to invoking CMake.
The problem is that if MSVC is set as the compiler in a toolchain file instead of directly in the Presets file, we aren't aware of what needs to happen. (this is actually the opposite the problem that VS has today)
Perhaps we can key off of the `architecture` and `toolset` values and require that one or both of them be set (with 'strategy == external') and if those are set, we take that as a sign that the user wants the MSVC environment configured. According to CMake documentation [[1]](https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_PLATFORM.html) [[2]](https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_TOOLSET.html), these values can also drive the `Green Hills MULTI` and `XCode` generators, so we could just enable this for the `Ninja` generators and I think that would solve the issue.
cc: @esweet431
Contributor guide
Research direction
Start by tracing how presets select Kits and configure the MSVC environment before invoking CMake with Ninja. Compare direct compiler settings with compiler selection from a toolchain file, and check how architecture, toolset, and external strategy are handled. Done means the intended MSVC environment is configured for Ninja without changing behavior for other generators.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, typescript
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100