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.
[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
Probably a duplicate of #426?
@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.
@andreeis Just tried again on my home and work computer.
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.
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.
@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.
@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
@bobbrow Sadly that workaround doesn't work if I need a specific architecture. It always picks the host one.
This is going to be fixed also with the same PR that is attached.
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.
@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?
Thanks @Minimonium! I moved your comment to a new issue. I can reproduce the problem. We'll get it fixed for 1.4.0.
This fix is available in CMake Tools #1.4.0 which has been released.
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.
@skalldri Let's discuss this in a new issue. #1347
Most helpful comment
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.