question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to find Ninja when using CMakePresets.json and clang-cl.exe

See original GitHub issue

Brief Issue Summary

When configuring without CMakePresets.json everything works fine but when I use the CMakePresets.json for vcpkg integration configuration fails with the error Ninja not found.

Ninja ,Cmake and Clang are installed on my system as part of Visual Studio 2019

Expected:

  1. Create CMakePresets.json
  2. Press F7 for configure
  3. Configuration should be generated

Apparent Behavior:

  1. Create CMakePresets.json
  2. Press F7 for configure
  3. Error is logged stating ninja is not found

CMake Tools Log

[main] Building folder: Sandbox 
[main] Configuring folder: Sandbox 
[proc] Executing command: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_C_COMPILER=C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe" "-DCMAKE_CXX_COMPILER=C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe" -DCMAKE_INSTALL_PREFIX=d:/C++/Sandbox/out/install/amd64-windows-clang -DCMAKE_TOOLCHAIN_FILE:FILEPATH=C:/Sdk/vcpkg/scripts/buildsystems/vcpkg.cmake -Hd:/C++/Sandbox -Bd:/C++/Sandbox/out/build/amd64-windows-clang -G Ninja
[cmake] CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "D:/C++/Sandbox/out/build/amd64-windows-clang/CMakeFiles/CMakeOutput.log".

Platform and Versions

  • Operating System: Windows 10
  • CMake Version: 3.19.20122902-MSVC_2
  • VSCode Version: 1.56.2
  • CMake Tools Extension Version: 1.7.3
  • Compiler/Toolchain: Clang 11.0.0 (MSVC CLI) - amd64

Other Notes/Information

My CMakePreset.json, created by following the box2d-lite example

{
  "version": 2,
  "configurePresets": [
    {
      "name": "base-config",
      "description": "Sets generator, build and install directory, vcpkg",
      "hidden": true,
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/out/build/${presetName}",
      "cacheVariables": {
        "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
        "CMAKE_TOOLCHAIN_FILE": {
          "type": "FILEPATH",
          "value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
        }
      },
      "environment": {
        "VCPKG_FEATURE_FLAGS": "manifests,versions,binarycaching,registries"
      }
    },
    {
      "name": "amd64-windows-clang",
      "displayName": "Clang 11.0.0 (MSVC CLI) (Visual Studio Professional 2019 Release - amd64)",
      "inherits": [
        "base-config"
      ],
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Debug",
        "CMAKE_C_COMPILER": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe",
        "CMAKE_CXX_COMPILER": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe"
      },
      "toolset": {
        "value": "amd64",
        "strategy": "external"
      },
      "architecture": {
        "value": "amd64",
        "strategy": "external"
      },
      "vendor": {
        "microsoft.com/VisualStudioSettings/CMake/1.0": {
          "hostOS": [ "Windows" ]
        }
      }
    }
  ],
  "buildPresets": [
    {
      "name": "base-build",
      "description": "Inherits environment from base-config configurePreset",
      "configurePreset": "base-config",
      "hidden": true,
      "inheritConfigureEnvironment": true
    },
    {
      "name": "build",
      "description": "Clean before build (--clean-first)",
      "configurePreset": "amd64-windows-clang",
      "inherits": "base-build",
      "cleanFirst": true
    }
  ]
}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
invycommented, Aug 27, 2021

In case of CMakePresets.json env var from the kit is not being loaded now I assume this is by design since the goal of CMakePresets.json is to give complete control and everything needs to be configured manually.

@BLaZeKiLL I disagree about that statement about design goal. The goal of CMakePresets is to add the ability to read Specific configuration from the file instead of calling cmake with the dozens of options. On ‘normal’ systems (i.e. linux) you usually can have several compilers in PATH (i.e. /usr/bin/gcc, /usr/bin/clang, /usr/bin/clang-10), and ninja/make and others are always available in PATH. Adding of additional compilers usually happens via CMake Toolchains, where you configure for example cross compilation environment, and specify some compilers which are not available on system (but not ninja or make) The goal of CMakePresets is not to configure your whole build environment, but rather to set the tools you wish when configuring your project. In other words: all paths must be considered where compilers and tools are installed.

Even the documentation (https://github.com/microsoft/vscode-cmake-tools/blob/develop/docs/cmake-presets.md) states following:

[!NOTE] If you're a windows developer, you must open Visual Studio Code from a developer command prompt. Or, run the CMake: Scan for Compilers command before the CMake Tools extension can detect build tools (CMake, Ninja) that are installed with Visual Studio.

So this would be the workaround, but it’s ugly.

0reactions
maltevespercommented, Jun 9, 2022

Or am I seeing an incarnation of this and am confused here: https://github.com/microsoft/vscode-cmake-tools/issues/1792#issuecomment-823664675?

@andreeis in case that is your issue I am happy to generate logs. (Is there an issue on github for the issue you mentioned in the linked comment?)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug with ninja in CMakePresets.json - Visual Studio Feedback
I have the following configurations in my CMakePresets.json: ... (x86)/Microsoft Visual Studio/2019/Preview/VC/Tools/Llvm/bin/clang-cl.exe" is not able to ...
Read more >
VS build environment is not set when using clang #2286
CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. When ninja is not in path ......
Read more >
Configure and build with CMake Presets in Visual Studio
The C++ Clang tools for Windows components must be installed for you to build with clang-cl . Build with cl.exe : JSON Copy....
Read more >
Build project using CMake, Ninja and clang for VS 2019
This would make Visual Studio misbehave, as e.g. it will look for CMakeCache.txt in the ... one with "cl.exe", another with "clang-cl.exe".
Read more >
CMakePresets CMake does not find MSVC when Ninja ...
Hey, I noticed that CMake is not able to find the MSVC Compiler when Generator Ninja is selected from CMakePresets.json.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found