VS: Generators require default toolset to be installed in addition to the requested toolset
The Visual Studio 15 2017 generator requires the default (MSVC 2017 v141) toolset to be installed, even if another is explicitly specified on the command line (e.g. MSVC 2015 with -T v140
). I'd expect the issue to also apply to at least the 2019 and 2022 generators, and maybe 2015 and below (although I'm aware they work a little differently), when other non-default toolsets are requested (e.g. v142 with the 2022 generator), and when they're set via CMAKE_GENERATOR_TOOLSET
instead of -T
.
I'd expect only the toolset you're actually trying to use to be required as it seems to be self-sufficient when CMake isn't installed.
Tested with CMake 3.19.8 on Windows Server 2019.
Repro:
- Spin up a VM or fresh Windows install.
- Install CMake.
- Download the Visual Studio Installer.
- Install the Visual Studio 2017 build tools (may also reproduce with the full IDE, but that's not what I tried). Select the following individual components (some of which aren't required, but they're what the test machine had on it):
- Static analysis tools
- Visual C++ ATL for x86 and x64
- Visual C++ MFC for x86 and x64
- .NET Framework 4.6.1 SDK
- .NET Framework 4.6.1 targeting pack
- Windows 10 SDK (10.0.17134.0)
- VC++ 2015.3 v14.00 (v140) toolset for desktop
- NuGet targets and build tasks
- Visual Studio C++ core features
- Create a minimal
CMakeLists.txt
containingcmake_minimum_required(VERSION 3.1) project(bogus)
- Run
cmake -G "Visual Studio 15 2017" . -T v140
- Observe that the output is
CMake Error at CMakeLists.txt:5 (project): Generator Visual Studio 15 2017 could not find any instance of Visual Studio. -- Configuring incomplete, errors occurred! See also "C:/test/CMakeFiles/CMakeOutput.log".
- If you want, run
vswhere -all -products '*'
and observe that it finds your VS installation. Adding-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64
causes it to find nothing, which is expected as that only concerns the MSVC version that matches MSBuild. Runningvswhere -all -legacy
finds the MSVC 2015 v140 installation, which is what we're trying to use. - Open the Visual Studio Installer again.
- Install the VC++ 2017 version 15.9 v14.16 latest v141 tools component.
- Run
cmake -G "Visual Studio 15 2017" . -T v140
again. - Observe that the project is configured and generated correctly, and references MSVC 2015 v140 , which was installed all along.
- Observe that
vswhere -all -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64
now finds the MSVC 2017 v141 installation.
While it would be a pain, I'd understand if this was expected behaviour. If there's no plan to change it, though, it should really be added to the documentation for the affected generators as it's not intuitive that you need tools you're explicitly not using to be installed for CMake to work.