Krupip
Krupip

Reputation: 4902

CMake cant find instance of Visual Studio 15 2017 generator, but works fine with Visual Studio 16 2019

Similar to CMake: Visual Studio 15 2017 could not find any instance of Visual Studio but in my case I've got my main installations version of MSVC generator working. It's the 2017 generator that doesn't seem to be working for me. Here is my installation setup:

enter image description here

My understanding is that this should work, I should have the appropriate tools.

When I run cmake -G "Visual Studio 16 2019" ../

I get

-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.28.29337.0
-- The CXX compiler identification is MSVC 19.28.29337.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/.../build

Looks good so far. But when I run cmake -G "Visual Studio 15 2017" ../

I get

CMake Error at CMakeLists.txt:2 (project):
  Generator

    Visual Studio 15 2017

  could not find any instance of Visual Studio.



-- Configuring incomplete, errors occurred!
See also "C:/.../build/CMakeFiles/CMakeOutput.log".

I'm currently use this version of cmake:

cmake -version
cmake version 3.20.0-rc2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

so I should have all the latest methods of using cmake.

I know I could manually configure the generators, but that sticks with the cmake cache and gets deleted constantly, and I was under the impression CMake could handle multiple visual studio instances with out such manual tuning, and that I should be able to use environment variables to point to each one at the very least, though that also doesn't appear to be working.

Upvotes: 2

Views: 5439

Answers (2)

Corristo
Corristo

Reputation: 5520

I think this is a case of unfortunate naming. Installing the "VS 2017 C++ x64/x86 build tools" only installs the compiler, linker and standard libraries and not actually the entire "Visual Studio Build Tools 2017" which include MSBuild. But you need the latter to use the "Visual Studio 15 2017" generator. You can find the installer for the 2017 build tools at https://aka.ms/vs/15/release/vs_buildtools.exe

Upvotes: 4

Cory Kramer
Cory Kramer

Reputation: 118021

If you want to generate targeting the Visual Studio 2017 platform toolset (v141), but using Visual Studio 2019 as the generator, you'd use the following CMake generate command

cmake -G "Visual Studio 16 2019" -T v141 ..

Upvotes: 6

Related Questions