I have installed on my machine Visual Studio 2022 17.9 with the MSVC toolsets 14.36, 14.38 and 14.39. I created with Visual Studio a new “CMake project” and after configuring it with cmake -S . -B build -G "Visual Studio 17 2022" I noticed that CMake is choosing MSVC 14.36; the oldest one.
I tried to manually choose the latest toolset by passing -T v143,version=14.39 but every time it fails with No CMAKE_C/CXX_COMPILER could be found.. I tried the same while under the Visual Studio developer Powershell (both with and without specifying -vcvars_ver=14.39) but the result has been either failure to find the compiler, or finding 14.36.
In the Visual Studio Installer’s section for VS 17.9, look under Desktop development with C++ and make sure the MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest) component is installed. If installed, CMake should choose that by default.
If those two files disagree something may be wrong with the VS installation. Try removing the “Latest” component I mentioned above and then installing it again.