When user has VS2019/VS2022 installed it defaults to the VS2019 toolset

I was trying out VS 2022 and happened to come across this.
I have both VS 2019/2022 installed but it defaults to using the VS 2019 toolset.

# CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(FOOBAR LANGUAGES "CXX" )
add_executable(baz)
target_sources(baz PRIVATE main.cpp)
// Main.cpp
#include <iostream>
int main()
{
    std::cout << "Hello world\n";
}

Here is my VS installations:

PS C:\Users\juaramos\Downloads\0_simple_executable> cmake -B build -G "Visual Studio 17 2022"
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
-- The CXX compiler identification is MSVC 19.29.30133.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/juaramos/Downloads/0_simple_executable/build
PS C:\Users\juaramos\Downloads\0_simple_executable>

Yet for some reason the old toolset is chosen:

image

Is this intentional?

1 Like

Looking at the docs I believe this is not intentional.

“The v143 toolset that comes with VS 17 2022 Preview 4 is selected by default.” - docs

This is talking about the toolset given VS 2022 is being used. Since it is a preview, it is likely not selected by default in the first place.

Cc: @brad.king

I ended up uninstalling vs2019 to see if CMake would stop trying to use the v142 toolset, however instead it now results in a fatal error when configuring a vs project.

 C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(436,5): error MSB8020: The build tools for Visual Studio 2019 (Platform Toolset = 'v142') cannot be found.
PS > cmake --version
cmake version 3.21.0

I just updated to CMake version 3.21.3 and this issue no longer occurs.

I am currently using VS 2022 preview 4.1 for reference.

Ah, that makes sense 3.21.0 had support for preview 1.1. 3.21.1 added support for preview 2, 3.21.2 added support for preview 3.1, and 3.21.3 added support for preview 4. Further preview releases will require additional CMake releases (though 3.21 should get them at least until 3.22.0 is out, maybe more later, but that’s less certain).

2 Likes