5

I installed both VS2015 and VS2017. For a cmake project, I want to use cmake to generate a vs2015 project (platform toolset v140).

I Opened the Developer Command Prompt for VS2015 then I ran cmake there. But from the output and also the result sln file, I see it's still using vs2017 (v141) platform toolset.

-- Building for: Visual Studio 15 2017 -- The C compiler identification is MSVC 19.16.27027.1 -- The CXX compiler identification is MSVC 19.16.27027.1 -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- works

Please see the screenshot here: cmake vs2015

So, how to I force cmake to use vs2015?

2 Answers2

7

This is what the -T option is for:

-T Specify toolset name if supported by generator.

Some CMake generators support a toolset name to be given to the native build system to choose a compiler. See the CMAKE_GENERATOR_TOOLSET variable. This is supported only on specific generators:

Visual Studio Generators for VS 2010 and above The Xcode generator for Xcode 3.0 and above See native build system documentation for allowed toolset names.

cmake -G "Visual Studio 15 2017" -T v140

(Note that the generator names for Visual Studio changed between CMake 3.13 and 3.14)

This will generate a Visual Studio 2017 solution, using the 2015 compiler and toolchain. So opening the solution will open VS 2017, but the code will compile with the 2015 toolchain.

If you want to use the 2015 IDE instead, you use the 2015 generator and leave out the -T parameter.

Note that you can also install the v140 toolchain as part of a VS2017 installation, so if you don't plan on using the older IDE, there is really no reason for keeping the VS2015 installation around.

ComicSansMS
  • 51,484
  • 14
  • 155
  • 166
1

cmake -G "Visual Studio 14 2015"

make sure Windows SDK version 10.0.10586.0 is istalled.

to see a list of the generators, run cmake --help