CMake 4.2.3 picks wrong MSVC?

Hi,

so today I tried to build a project where we used to rely on the fact that CMake uses the ambient environment to figure out the compiler to use.

Alas, despite being started in the VS2022 Developer Powershell, it ends up picking VS2026 which is also installed on the system. What gives?

Was our original premise wrong and it doesn’t actually pick it from the environment even though it’s readily available there? I am fairly certain this used to work at some point.

Thanks for any insights.

PS: the installed CMake is the latest one as per WinGet, which is why it’s this one and not 4.3.0.

Not all generators depend on the environment. You selected none and VS generator is the default which detects it from registry values.

1 Like

My experience has been that CMake always picks the newest version of VS installed that it can detect. If you want a specific version of VS you specify it explicitly in the generator.

1 Like

Thanks for the responses!

Sigh, so I guess the premise was wrong. Giving an exact version of VS to generate for defeats the purpose, too.

If you use the Ninja generator, it will use the environment.

Thanks, I understood that. Unfortunately that’s still not equivalent to how it works with the VS generator due to property sheets and such …

Something else you may want to keep in mind when using different Visual Studio environments is that you may want to use specific versions of the Windows SDK. I currently set that using the CMAKE_SYSTEM_VERSION variable:

cmake -G "Visual Studio 18 2026"  -DCMAKE_SYSTEM_VERSION=10.0.26100.0

or

cmake -G "Visual Studio 17 2022"  -DCMAKE_SYSTEM_VERSION=10.0.19041.0

etc.