microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.47k stars 452 forks source link

issue with vs2017 cmake generator #191

Closed amigo421 closed 7 years ago

amigo421 commented 7 years ago

image

Loading CMake Tools from c:\dev\workspace\algolist.vscode.cmaketools.json Detected available environment "Visual Studio Community�2017 - x86 Detected available environment "Visual Studio Community�2017 - amd64 Started new CMake Server instance with PID 2668 Build program for generator Ninja is not found. Skipping... Build program for generator Unix Makefiles is not found. Skipping... Build program for generator MinGW Makefiles is not found. Skipping... Build program for generator NMake Makefiles is not found. Skipping... None of preferred generators available on the system.

In other hand - no any issues to generate and build the project from command line

image

and, for sure , vc15 is there:

image

ytimenkov commented 7 years ago

@amigo421 You've hit both issues I've identified and fixed in #186 and corresponding PR:

  1. VS generator is not in the list of preferred generators (although CMake will use it when run from command line w/o -G option).
  2. When CMake Tools does detection, it checks for programs without original environment, so it can't find nmake.

You have few options:

  1. Add Visual Studio 15 2017 to cmake.preferredGenerators or to cmake.generator to force it.
  2. Run VS Code from Developer command prompt so nmake will be in your path, for initial setup. In this case you should then activate Visual Studio environment so CMake Tools will take care of vcvars.
ytimenkov commented 7 years ago

@amigo421 I see you have localized UI. Do you have issues with CMake output, like #153 ?

amigo421 commented 7 years ago

thank you , the including this generator into prefered list solved the problem. just want to understand - previously, I was using this extension and NMake generator was in use by default, and without dev env allocating ( I supposed the extension performed a detection ), NMake is preferable due the UI issue, and yes, this is still there forme too.

also please look at the screenshot - I've selected x64 env, but cmake generating was performed for x86.

image

ytimenkov commented 7 years ago

@amigo421 On Windows platforms CMake Tools try to eliminate the need for running VS code from Developer command prompt. Internally they try to discover Visual Studio installations, and collect environment variables which are initialized by vcvarsall.bat. So then when you run 'configure' or 'build', CMake Tools will run underlying command with those discovered variables, as if it was ran from command prompt.

Then there is a trick with Environment and Generator. When you specify 'Visual Studio 15 2017' you explicitly tell CMake to generate solution for x86 platform. If you want to run 64-bit code change it to 'Visual Studio 15 2017 Win64 and do clean configure. CMake itself does not require Developer Command prompt for VS generators, because it gets installation path from registry and MSBuild knows exactly where to find compiler for given platform, it doesn't matter which environment you use in this case.

It makes difference for NMake generator though (and Ninja). Then CMake discovers compiler by just running cl.exe and stores its full path, so you have to select proper environment.

I don't know how it worked before, maybe it was a 'legacy mode' when CMake Tools just ran cmake without specifying -G and msbuild was picked up, you just didn't notice. (that's similar to your initial complaint).

ytimenkov commented 7 years ago

BTW, this discrepancy between environment and generator is also addressed in PR to #186, with more fundamental fix proposed in #190.

amigo421 commented 7 years ago

yes, I didn't use Visual Studio generator previously, and we had a discussion with extension author how to detect toolchain and SDK location. so it worked previously for server mode (cmake) and vs2015 toolchain without my side dev env setting up.

so I'll come back to vs2015 build tools and try , hope this will work without extra configuring otherwise, yes, I'll need to rn vscode from allocated vc dev env ...

ytimenkov commented 7 years ago

otherwise, yes, I'll need to rn vscode from allocated vc dev env

Please set cmake.generator to whatever you use then. This overrides generator detection and delegates work to CMake itself which runs in modified environment and should be able to find nmake (if it's what you use).

amigo421 commented 7 years ago

okay, thank you so please close the request then