3

I have multiple versions of MSVC C++ build tools for the same toolset(v142) installed using Visual studio build tools. How can I set the default or preferred version of the MSVC compiler. Is there a registry or environment variable for setting this in Windows or with Cmake?

Cmake picks up the latest version and I want it to use older version for some builds. CMake does seem to have a -T parameter for toolset but in my case both versions are for toolset v142.

Please note that I do not have or intend to use Visual Studio IDE for this since I am dealing with command line builds for CI purposes.

VS build tools

harish
  • 1,836
  • 3
  • 21
  • 26
  • 1
    In case anyone wonders how to select the MSVC (cl.exe) version from the IDE rather than cmake: Go to the project property pages => Advanced => "MSVC Toolset version". This allows you to select the specific compiler version in case you have multiple installed. Note that the available options depends on what "Platform Toolset" you selected (project property pages => General => "Platform Toolset"). Also note that the "Advanced => MSVC Toolset version" is available only for "Platform Toolset" set to "Visual Studio 2019 (v142)" or "Visual Studio 2022 (v143)" or probably later. – Sedenion Mar 13 '23 at 08:16

1 Answers1

5

You can pass the required version via CLI:

$ cmake ... -T v142,version=14.24

See also CMAKE_GENERATOR_TOOLSET variable.

zaufi
  • 6,811
  • 26
  • 34
  • thanks! I did try various combinations with -T (y -T v142.xx.yy or -T 14.24) but seems all of those were incorrect. This worked perfectly! – harish Jun 09 '20 at 11:53