Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ninja generator is used instead of Visual Studio 16 2019 #1084

Closed
Celeborn2BeAlive opened this issue Feb 20, 2020 · 14 comments
Closed

Ninja generator is used instead of Visual Studio 16 2019 #1084

Celeborn2BeAlive opened this issue Feb 20, 2020 · 14 comments
Assignees
Labels
bug a bug in the product Feature: configure Feature: kits fixed (release pending) fixed in pre-release and is pending official release IMPORTANT
Milestone

Comments

@Celeborn2BeAlive
Copy link

Brief Issue Summary

When I select the kit "Visual Studio Community 2019 Release - amd64", vscode-cmake-tools is passing '-G Ninja' to cmake instead of '-G "Visual Studio 16 2019" -A x64'.

My cmake-tools-kit.json file contains the entry:

  {
    "name": "Visual Studio Community 2019 Release - amd64",
    "visualStudio": "da769ae6",
    "visualStudioArchitecture": "amd64",
    "preferredGenerator": {
      "name": "Visual Studio 16 2019",
      "platform": "x64"
    }
  },

What is strange is that I get the correct behavior when I select "Visual Studio Community 2017 Release - amd64" (in that case I can see '-G "Visual Studio 15 2017" -A x64' passed to cmake, which is correct). For this one the entry is:

  {
    "name": "Visual Studio Community 2017 Release - amd64",
    "visualStudio": "05246a08",
    "visualStudioArchitecture": "amd64",
    "preferredGenerator": {
      "name": "Visual Studio 15 2017",
      "platform": "x64"
    }
  },

that seems pretty similar to the one for VS 2019. So I don't know how vscode-cmake-tools interprets the file cmake-tools-kits.json, but it seems that it does treat both cases in the same way.

Expected:

  1. "CMake: Select a Kit" command
  2. Choose "Visual Studio Community 2019 Release - amd64"
  3. "CMake: Configure" command
  4. cmake should be called with option '-G "Visual Studio 16 2019" -A x64'

Apparent Behavior:

  1. "CMake: Select a Kit" command
  2. Choose "Visual Studio Community 2019 Release - amd64"
  3. "CMake: Configure" command
  4. cmake is called with option '-G Ninja'

CMake Tools Log

[main] Configuring folder: gltf-viewer-tutorial-git 
[proc] Executing command: C:\Users\laure\scoop\shims\cmake.EXE --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -Hd:/projects/opengl_tds/gltf-viewer/gltf-viewer-tutorial-git -Bd:/projects/opengl_tds/gltf-viewer/build-gltf-viewer-tutorial -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is MSVC 19.23.28106.4
[cmake] -- The CXX compiler identification is MSVC 19.23.28106.4
[cmake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe
[cmake] -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe -- works
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe
[cmake] -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe -- works
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Looking for pthread.h
[cmake] -- Looking for pthread.h - not found
[cmake] -- Found Threads: TRUE  
[cmake] -- Using Win32 for window creation
[cmake] -- Found OpenGL: opengl32   
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: D:/projects/opengl_tds/gltf-viewer/build-gltf-viewer-tutorial

Platform and Versions

  • Operating System: Windows 10 Build 18362
  • CMake Version: 3.16.4
  • VSCode Version: 1.42.1
  • CMake Tools Extension Version: 1.3.0
  • Compiler/Toolchain: Visual C++ 2019
@ghuser404
Copy link

Probably a duplicate of #426?

@andreeis
Copy link
Contributor

andreeis commented Apr 3, 2020

@ghuser404, #426 has something in common with this issue indeed but they are not perfect duplicates. In there the users are complaining also about inconsistent caching, refreshing, updating (etc...) of kits and generator settings which I'm going to look at separately, after ensuring the proper priority rules for generatos are respected. No reload of window should be required to have kits/generator settings take effect.

@Celeborn2BeAlive , I am testing a fix for this but what I wasn't able to reproduce on my side is your not having Ninja chosen for 2017. Just to make sure I'm not overlooking anything or fixing this wrong, I want to get to the bottom of this inconsistent behavior. Do you have any generator setting anywhere that might explain why 2017 generator is chosen over Ninja? Are the two scenarios happening on the same machine and user? Having ninja installed on one and not installed on the other would explain the different choice.

@Celeborn2BeAlive
Copy link
Author

@andreeis Just tried again on my home and work computer.

  • On my home machine I have the same result as you: Ninja is chosen for both VS Community 2017 and 2019.
  • However at work I only have a VS Professional 2017 installed and the extension picks the VS generator.

So maybe the extension choose Ninja for VS Community but not VS Professional. Or it may be because I don't have 2019 installed at all at work.

@bobbrow
Copy link
Member

bobbrow commented Apr 6, 2020

A workaround for now is to set "cmake.preferredGenerators": [] if you don't have it set currently. Then delete your build folder and reload the window.

@andreeis
Copy link
Contributor

andreeis commented Apr 7, 2020

@Celeborn2BeAlive , maybe the difference is that Ninja is not installed on your work computer? The code I fixed in CMake Tools was always picking Ninja first, if installed. If not installed, it would give a chance for the VS generator to be discovered.

@Celeborn2BeAlive
Copy link
Author

@andreeis It seems you are right, I have ninja.exe installed on my home computer, seems to be installed with VS Community 2017 and 2019, but on my work computer I have nothing.
Thank you for the fix ! I hope it will be integrated soon. In the meantime I'll use the workaround mentionned by @bobbrow

@Minimonium
Copy link

@bobbrow Sadly that workaround doesn't work if I need a specific architecture. It always picks the host one.

@andreeis
Copy link
Contributor

This is going to be fixed also with the same PR that is attached.

@bobbrow bobbrow added the fixed (release pending) fixed in pre-release and is pending official release label Apr 17, 2020
@andreeis
Copy link
Contributor

CMake Tools 1.4.0 Beta is available on GitHub.
https://github.com/microsoft/vscode-cmake-tools/releases/tag/1.4.0-beta

Please try it out and let us know if you encounter any issues.

@Minimonium
Copy link

@andreeis Now it initializes a correct cross-compiler for MSVC CMake generator, but there is an issue.

If you have "cmake.preferredGenerators": ["Ninja"], in global settings - CMake-Tools'll never initialize vcvarsall.bat. It's a bit unexpected. Shouldn't it initialize a correct environment anyway if both visualStudio and visualStudioArchitecture are present as per documentation?

@bobbrow
Copy link
Member

bobbrow commented May 15, 2020

Thanks @Minimonium! I moved your comment to a new issue. I can reproduce the problem. We'll get it fixed for 1.4.0.

@andreeis
Copy link
Contributor

This fix is available in CMake Tools #1.4.0 which has been released.

@skalldri
Copy link

skalldri commented Jul 1, 2020

This change (to use Visual Studio as a generator instead of Ninja when compiling with MSVC) has broken my build environment :(. This was is a breaking change but doesn't appear to have been treated as such.

This was also previously advertised as a feature of this extension, per the documentation linked in the extension's homepage.

https://vector-of-bool.github.io/docs/vscode-cmake-tools/kits.html#kits

Quote:

If you use Ninja there is no need to worry about Visual Studio CMake Generators. CMake Tools will prefer Ninja if it is present unless configured otherwise.

@bobbrow
Copy link
Member

bobbrow commented Jul 1, 2020

@skalldri Let's discuss this in a new issue. #1347

@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug a bug in the product Feature: configure Feature: kits fixed (release pending) fixed in pre-release and is pending official release IMPORTANT
Projects
None yet
Development

No branches or pull requests

6 participants