CMake: How to specify VS2015.3 toolset with VS2017 installed

Viewed 11659

I have VS2017 installed, with both VS2017 (v141) and VS2015.3 (v140) toolset installed. I need to generate a solution with CMake and I want CMake to be "fooled" as if VS2015 is installed, so I can build the project with v140 toolset.
I know this question is possibly a duplicate of: How cmake specify "Platform Toolset" for a Visual Studio 2015 project?
But the solution it provides doesn't help me.
The error messages are:

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

I tried installing both VS2017 and VS2015.3 (IDE), but VS2015.3 refused to create even a simple console program.
Is there another way to generate a solution with v140 toolset?
(P.S. Don't tell me that I should generate with v141 toolset first and modify the toolset option in Visual Studio. That makes a big difference. )

1 Answers

I've just ran a test and it works for me with the following settings in CMake's GUI (Version 3.10.0 RC4):

enter image description here

Then I get the following output:

The CXX compiler identification is MSVC 19.0.24215.1
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Configuring done
Generating done

And if I open the resulting solution it will - as expected - ask me:

enter image description here

Platform Toolset Mapping

From Marco Foco: Microsoft Visual C++ version Map:

enter image description here

If that don't work ...

First please check the CMakeError.log in your binary output directory. The error should give you a lead on what's wrong.

If that's not helping, you can try several things (besides re-installing VS, which I think won't solve the problem):

  1. One of the Windows SDKs is not fully/correclty installed; Reinstall from Microsoft's web site
  2. Try to give the cmake-gui administrative rights
  3. Check if there is a GNU toolchain with GCC compiler in your PATH environment.

References

Related