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

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

Closed
siddjain opened this issue Aug 24, 2024 · 22 comments
Labels
more info needed More info is needed from the community for us to properly triage and investigate. regression used to work and no longer does. Regressions are typically high priority

Comments

@siddjain
Copy link

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
Copy link
Collaborator

@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

@gcampbell-msft gcampbell-msft added the more info needed More info is needed from the community for us to properly triage and investigate. label Aug 27, 2024
@siddjain
Copy link
Author

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
Copy link

algovoid commented Aug 27, 2024

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

  • start menu > environment variables > Edit the system environment variables > Environment Variables then under System variables -- Path > Edit > New > add path to the Ninja executable directory > OK on all windows to save changes

search_path
image

  • or you can open Cmmand prompt with admin privileges and run this command "setx CMAKE_GENERATOR "Ninja" /M" (remove quotes)
    set variable command

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
Copy link
Collaborator

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
Copy link

gg-sr commented Aug 28, 2024

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.

@Yingzi1234 Yingzi1234 removed the triage label Aug 29, 2024
@gcampbell-msft
Copy link
Collaborator

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

@gg-sr
Copy link

gg-sr commented Aug 29, 2024

@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
Copy link
Collaborator

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

@gg-sr
Copy link

gg-sr commented Aug 29, 2024

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

@gcampbell-msft
Copy link
Collaborator

@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
Copy link
Collaborator

gcampbell-msft commented Aug 29, 2024

@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
Copy link
Collaborator

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

@gg-sr
Copy link

gg-sr commented Aug 30, 2024

@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
Copy link
Collaborator

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

@gcampbell-msft
Copy link
Collaborator

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
Copy link

lit-af commented Aug 30, 2024

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
Copy link
Collaborator

gcampbell-msft commented Aug 30, 2024

@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
Copy link

lit-af commented Aug 30, 2024

@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
Copy link
Collaborator

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
Copy link

lit-af commented Aug 30, 2024

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

@gcampbell-msft
Copy link
Collaborator

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

@jackkoenig
Copy link

I am also hitting the same issue (running on RHEL) and can confirm that the most recently linked cmake-tools vsix1 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!

Footnotes

  1. https://github.com/user-attachments/files/16820099/cmake-tools.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info needed More info is needed from the community for us to properly triage and investigate. regression used to work and no longer does. Regressions are typically high priority
Projects
Status: Completed
Development

No branches or pull requests

8 participants