How do I set the compiler version for Visual Studio generator with cmake presets

I have “14.36-17.6” and “14.37-17.7” build tools installed with VS 17.7.1.

I would like to specify the compiler version to be used in a CMakePresets.json file.

My CMakePresets.json file looks like the following:

{
  "version": 6,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 27,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "windows",
      "generator": "Visual Studio 17 2022",
      "binaryDir": "${sourceDir}/out/build/${presetName}",
      "architecture": {
        "value": "ARM64"
      },
      "toolset": {
        "value": "host=x64,version=14.36"
      },
      "cacheVariables": {
        "CMAKE_VERBOSE_MAKEFILE": "ON",
        "CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo",
        "CMAKE_SYSTEM_VERSION": "10.0"
      }
    }
  ]
}

When I run cmake --fresh --preset windows, I get the following output.

Preset CMake variables:

  CMAKE_CONFIGURATION_TYPES="Debug;RelWithDebInfo"
  CMAKE_SYSTEM_VERSION="10.0"
  CMAKE_VERBOSE_MAKEFILE="ON"

-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_C_COMPILER could be found.



CMake Error at CMakeLists.txt:2 (project):
  No CMAKE_CXX_COMPILER could be found.



-- Configuring incomplete, errors occurred!

If I don’t specify the version=14.36 (or version=14.37) in the toolset block, the “latest” compiler 14.37-17.7 (i.e. 19.37.32822.0) is chosen and both configure and build works.

The issue seems to be that the generated CompilerIdC(XX).vcxproj is not correct. Basically, the imported Microsoft.VCToolsVersion.14.36.17.6.props doesn’t seem to be designed to be used the way cmake is using it, as it refers to another props file that doesn’t exist.

As far as I can tell, cmake just needs to provide the <VCToolsVersion>14.36.32532</VCToolsVersion> and not import the props file in the generated vcxproj file.

Is this a bug in cmake VS generator or is there another way I can specify any compiler version that might be installed with VS?

Thanks.

I think you’re getting bitten by a change made in Visual Studio starting with the 14.36 toolset. See the following issue for details:

https://gitlab.kitware.com/cmake/cmake/-/issues/25192