Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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. )

like image 564
Aurus Huang Avatar asked Nov 07 '17 09:11

Aurus Huang


People also ask

What is CMakeSettings JSON?

The CMakeSettings. json file contains information that Visual Studio uses for IntelliSense and to construct the command-line arguments that it passes to CMake for a specified configuration and compiler environment.

How do I know my compiler version in Visual Studio 2017?

Just select the “Individual Components” tab at the top of the installer screen and scroll down to the “Compilers, build tools, and runtimes” section. The 14.11 toolset is included in the VS2017 version 15.5 update 4 installer.


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

  • VS 2010 and CMake: 'rc' is not recognized as an internal or external command
  • MSBuild.exe has stopped cmake error
  • Environment variable used by CMake to detect Visual C++ compiler tools for Ninja
like image 172
Florian Avatar answered Sep 23 '22 01:09

Florian