microsoft / vscode-cmake-tools

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

Unable to determine what CMake generator to use. Please install or configure a preferred #4005

Closed siddjain closed 2 months ago

siddjain commented 3 months ago

Brief Issue Summary

I installed CMake tools and CMake yesterday and it was working fine (w/ Ninja). Today when I opened VS Code all of a sudden it is giving this error:

[main] Unable to determine what CMake generator to use. Please install or configure a preferred generator, or update settings.json, your Kit configuration or PATH variable. Error: No usable generator found.

I have no idea what is its problem.

CMake Tools Diagnostics

{
  "os": "win32",
  "vscodeVersion": "1.92.2",
  "cmtVersion": "1.18.44",
  "configurations": [
    {
      "folder": "c:\\Users\\xxx\\code\\demo",
      "cmakeVersion": "unknown",
      "configured": false,
      "generator": "unknown",
      "usesPresets": false,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": false,
    "hasCodeModel": false,
    "activeBuildType": "",
    "buildTypesSeen": [],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 0,
    "executablesCount": 0,
    "librariesCount": 0,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": null
    }
  ]
}

Debug Log

[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --version
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -E capabilities
[variant] Loaded new set of variants
[kit] Successfully loaded 4 kits from C:\Users\xxx\AppData\Local\CMakeTools\cmake-tools-kits.json
[proc] The command: ninja --version failed with error: Error: spawn ninja ENOENT
[proc] The command: ninja-build --version failed with error: Error: spawn ninja-build ENOENT
[proc] The command: make --version failed with error: Error: spawn make ENOENT
[main] Unable to determine what CMake generator to use. Please install or configure a preferred generator, or update settings.json, your Kit configuration or PATH variable. Error: No usable generator found.

Additional Information

No response

gcampbell-msft commented 3 months ago

@siddjain Do you have your generator installed on the machine?

For us to investigate what is going on we'd need more information about your project in order to see what is happening. Thanks

siddjain commented 3 months ago

Hi Greg, all I know is that the day I installed CMake tools, it worked perfectly and the very next day I started to get this error. What is CMake generator? I have following executables on my system:

C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools>which ninja
/c/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja

C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools>which cmake
/c/Program Files/CMake/bin/cmake
algovoid commented 3 months ago

Hi siddjain , looks like Cmake can't find a generator although it seems ninja is installed , this is likely a path problem

you can try these steps and see if it solves your problem : 1- download the Ninja binaries from here (ninja-win.zip) 2- Now extract the ninja.exe binary and put in the cmake bin folder ( C:\Program Files\CMake\bin\ ) ninja in cmake folder

3- now you have to add ninja to the path to the system environment variables , there are two ways to do this

search_path image

4- now check if the path was set correctly by running this command "where ninja && ninja --version" , it should print the path and version of ninja check ninja command

5- now close vs code if it's already open and reopen it 6- Reset VScode: Ctrl+shift+P and type "CMake:Reset CMake Tools for Extension State" 7- Configure project: Ctrl+shift+P and type "CMake: Delete Cache and Reconfigure" .

Evelyn-001 commented 3 months ago

siddjain, could you please try to fix your issue according to the algovoid's comment? If it still reproduces, please share us a demo project with clear repro steps. Thanks.

gg-sr commented 2 months ago

Is there a way to disable the new check? In my case, ninja is purposely not in the PATH, and is instead set with CMAKE_MAKE_PROGRAM. This didn't cause problems until a few days ago, but now it does.

gcampbell-msft commented 2 months ago

@gg-sr What version of the extension are you operating on ?

gg-sr commented 2 months ago

@gcampbell-msft Oops, sorry for not including this information in the first place. I'm on v1.19.49. v1.20.0 (pre-release) appears to have the same problem. v1.18.44 works. Not sure if that makes any difference, but this happens in a devcontainer (I haven't tried it outside of a devcontainer).

Diagnostics (note that this occurs both on VS Code 1.92.2 and on 1.93.0):

{
  "os": "linux",
  "vscodeVersion": "1.93.0-insider",
  "cmtVersion": "1.19.49",
  "configurations": [
    {
      "folder": "...",
      "cmakeVersion": "unknown",
      "configured": false,
      "generator": "unknown",
      "usesPresets": false,
      "compilers": {}
    }
  ],
  "cpptoolsIntegration": {
    "isReady": false,
    "hasCodeModel": false,
    "activeBuildType": "",
    "buildTypesSeen": [],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 0,
    "executablesCount": 0,
    "librariesCount": 0,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": true
    }
  ]
}
{
  "os": "linux",
  "vscodeVersion": "1.93.0-insider",
  "cmtVersion": "1.18.44",
  "configurations": [
    {
      "folder": "...",
      "cmakeVersion": "3.28.3",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {
        "C": "/nix/store/03xd70qibzg98s6m35kq363il7zrcbm2-clang-wrapper-16.0.6/bin/clang",
        "CXX": "/nix/store/03xd70qibzg98s6m35kq363il7zrcbm2-clang-wrapper-16.0.6/bin/clang++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": false,
    "hasCodeModel": false,
    "activeBuildType": "",
    "buildTypesSeen": [],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 0,
    "executablesCount": 0,
    "librariesCount": 0,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": false
    }
  ]
}

Note that cmake is similarly not in the PATH, but instead set with cmake.cmakePath (edit: which uses ${workspaceFolder}).

gcampbell-msft commented 2 months ago

@siddjain @gg-sr Do you have a generator defined in cmake.generator or in cmake.preferredGenerators?

gg-sr commented 2 months ago

@gcampbell-msft I do: "cmake.generator": "Ninja". cmake.preferredGenerators is unset.

gcampbell-msft commented 2 months ago

@gg-sr Based on your diagnostics log, it looks like your cmake.generator isn't defined, which makes me think this is expected as we can't find a generator. If you've ran the Reset CMake Tools Extension State this may have gotten returned to the default, so you should set the cmake.generator to your desired generator and this should work as expected.

gcampbell-msft commented 2 months ago

@gg-sr Oh interesting, so this issue still reproduces when you have cmake.generator set to Ninja?

I'm currently not able to reproduce that, are you using a kit? Or are you using the "unspecified" kit?

gcampbell-msft commented 2 months ago

@gg-sr Are you setting CMAKE_MAKE_PROGRAM to an absolute path?

gg-sr commented 2 months ago

@gcampbell-msft Yes, "cmake.generator": "Ninja" is set. CMAKE_MAKE_PROGRAM points to an absolute path. I am using the "unspecified" kit.

I managed to fix my local installation, but unfortunately I don't know exactly what did it as I did multiple things at the same time: unset "cmake.generator": "Ninja", configure, reset the extension state, and set "cmake.generator": "Ninja" again.

The following is still printed on project load (after reloading VS Code), but not when configuring, so configuring / building works again:

[proc] The command: ninja --version failed with error: Error: spawn ninja ENOENT
[proc] The command: ninja-build --version failed with error: Error: spawn ninja-build ENOENT
[proc] The command: ninja --version failed with error: Error: spawn ninja ENOENT
[proc] The command: ninja-build --version failed with error: Error: spawn ninja-build ENOENT

Edit: with diagnostics:

{
  "os": "linux",
  "vscodeVersion": "1.93.0-insider",
  "cmtVersion": "1.19.49",
  "configurations": [
    {
      "folder": "...",
      "cmakeVersion": "3.28.3",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {
        "C": "/nix/store/nz8z2b1q8mypm5m4mg9wv33rxwvazl73-clang-wrapper-16.0.6/bin/clang",
        "CXX": "/nix/store/nz8z2b1q8mypm5m4mg9wv33rxwvazl73-clang-wrapper-16.0.6/bin/clang++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": false,
    "hasCodeModel": false,
    "activeBuildType": "",
    "buildTypesSeen": [],
    "requests": [],
    "responses": [],
    "partialMatches": [],
    "targetCount": 0,
    "executablesCount": 0,
    "librariesCount": 0,
    "targets": []
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": false
    }
  ]
}
gcampbell-msft commented 2 months ago

I believe that this PR #4026 will solve your issues. We hope to merge by EOD tomorrow, thanks!

gcampbell-msft commented 2 months ago

To confirm, @gg-sr and @siddjain, could you please download this vsix from the PR here #4026 and confirm that it fixes the issue?

You'll have to modify the extension from .zip to .vsix to install it manually. Thanks!

cmake-tools.zip

lit-af commented 2 months ago

I encountered a similar issue. CMake would attempt to use MAKE the default generator even if ninja is in the path and listed by cmake --help.

{
    "version": 2,
    "configurePresets": [
      {
        "name": "RealTime-Debug",
        "displayName": "RealTime-Debug",
        "generator": "Ninja",
        "binaryDir": "${sourceDir}/build/${presetName}",
        "cacheVariables": {
          "CMAKE_BUILD_TYPE": "Debug",
          "CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}",
          "CMAKE_TOOLCHAIN_FILE": "$env{AzureSphereDefaultSDKDir}/CMakeFiles/AzureSphereRTCoreToolchain.cmake"
        },
        "environment": { "BuildAllBuildsAllRoots": "true" },
        "vendor": {
          "microsoft.com/VisualStudioSettings/CMake/1.0": {
            "intelliSenseMode": "linux-gcc-arm"
          }
        }
      },
      {
        "name": "RealTime-RelWithDebInfo",
        "displayName": "RealTime-RelWithDebInfo",
        "inherits": "RealTime-Debug",
        "cacheVariables": {
          "CMAKE_BUILD_TYPE": "RelWithDebInfo"
        }
      },
      {
        "name": "RealTime-Release",
        "displayName": "RealTime-Release",
        "inherits": "RealTime-RelWithDebInfo",
        "cacheVariables": {
          "CMAKE_BUILD_TYPE": "Release"
        }
      }
    ]
  }

I'm using a devcontainer based on Ubuntu and I was able to build manually but not using the extension.

gcampbell-msft commented 2 months ago

@siddjain @gg-sr @lit-af

Could you test with this vsix and let me know if this resolves your issue?

cmake-tools.zip

lit-af commented 2 months ago

@siddjain @gg-sr @lit-af

Could you test with this vsix and let me know if this resolves your issue? cmake-tools.zip

I'm trying to install and test it using: code --install-extension path but it won't work. I don't see a .vsix file anywhere. Could you please provide further instructions on how to test please?

gcampbell-msft commented 2 months ago

Sure, please re-download the zip as I just updated it, you can download from here: cmake-tools.zip , you'll need to first modify the file extension from .zip to .vsix, then you can perform the step you mentioned I believe.

lit-af commented 2 months ago

I tested it and I can confirm that it's working on my end.

gcampbell-msft commented 2 months ago

The fix for this issue will be released in the next hour or so in v1.20.2.

jackkoenig commented 2 months ago

I am also hitting the same issue (running on RHEL) and can confirm that the most recently linked cmake-tools vsix^1 fixes the issue. In my case I set cmake.environment PATH (and LD_LIBRARY_PATH) for it to find the various tools that I'm using.

Looking forward to the fix in v1.20.2!