microsoft / microsoft/vscode-cmake-tools
[Bug] Impossible to use CMake Tools with custom Ninja install on Windows
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.7k
- Forks
- 546
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 32
Description
Brief Issue Summary
It does not seem to be possible to use CMake tools with custom Ninja executable.
Setup:
- I have acquired Ninja using winget, I have added ninja to PATH environment variable, and I have verified it works:
PS C:\Users\rawal> Get-Command ninja
>>
CommandType Name Version Source
----------- ---- ------- ------
Application ninja.exe 0.0.0.0 C:\Users\rawal\AppData\Local\Microsoft\WinGet\Packages\Ninja-build.Ninja_Microsoft.Winget.Source_8wekyb3d8bbwe\ninja.exe
- I have Visual Studio Community 2022 with MSVC compiler.
- I have VSCode on Windows with latest CMake and CMake extension.
VSCode Project:
I have generated CMake project using CMake: Quick Start wizard. It generated simple CMakeLists.txt:
cmake_minimum_required(VERSION 3.10.0)
project(Terraform VERSION 0.1.0 LANGUAGES C CXX)
add_executable(Terraform main.cpp)
as well as CMakePresets.json:
{
"version": 8,
"configurePresets": [
{
"name": "Ninja",
"displayName": "Custom configure preset",
"description": "Sets Ninja generator, build and install directory",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
}
}
]
}
The CMake configuration does not work:
[cmake] -- The C compiler identification is unknown
[cmake] -- The CXX compiler identification is unknown
[cmake] CMake Error at CMakeLists.txt:2 (project):
[cmake] No CMAKE_C_COMPILER could be found.
[cmake]
[cmake] Tell CMake where to find the compiler by setting either the environment
[cmake] variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
[cmake] the compiler, or to the compiler name if it is in the PATH.
This can be easily solved by setting "cmake.useVsDeveloperEnvironment" to "always", however it just kicks the problem down the road, as now, VS Developer Environment will kill all global environment variables including PATH which defines path to Ninja:
[preset] Ninja is not set on PATH, trying to use C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe
So I end up in this circular problem, where Ninja build needs to know path to cl.exe which VS Developer Environment provides but doing so, it deletes the PATH variable leading to Ninja.exe. This causes the CMake Tools to fall back to some stale, internal Ninja.exe executable.
I do not want to be relying on a failure fallback. I want to be using my own up to date Ninja executable. How do I do that?
Curiously, it also appears that automatic detection of VS Developer Environment setup does not seem to work as described:
When Ninja is defined in PATH environment variable and set as Cmake Generator, "cmake.useVsDeveloperEnvironment" set to "auto" will still not trigger.
CMake Tools Diagnostics
{
"os": "win32",
"vscodeVersion": "1.103.0",
"cmtVersion": "1.22.5",
"configurations": [
{
"folder": "d:\\Projects\\Software\\Terraform",
"cmakeVersion": "3.31.6",
"configured": true,
"generator": "Ninja",
"usesPresets": true,
"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
}
]
}
Debug Log
[proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" --version
[proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E capabilities
[kit] Successfully loaded 4 kits from C:\Users\rawal\AppData\Local\CMakeTools\cmake-tools-kits.json
[presetController] Reading and validating the presets file "D:\Projects\Software\Terraform\CMakePresets.json"
[presetController] Successfully validated D:\Projects\Software\Terraform\CMakePresets.json against presets schema
[presetController] Expanding presets file D:\Projects\Software\Terraform\CMakePresets.json
[presetController] Successfully expanded presets file D:\Projects\Software\Terraform\CMakePresets.json
[main] Configuring project: Terraform
[proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:/Projects/Software/Terraform/out/install/Ninja -S D:/Projects/Software/Terraform -B D:/Projects/Software/Terraform/out/build/Ninja -G Ninja
[cmake] -- The C compiler identification is unknown
[cmake] -- The CXX compiler identification is unknown
[cmake] CMake Error at CMakeLists.txt:2 (project):
[cmake] No CMAKE_C_COMPILER could be found.
[cmake]
[cmake] Tell CMake where to find the compiler by setting either the environment
[cmake] variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
[cmake] the compiler, or to the compiler name if it is in the PATH.
[cmake]
[cmake]
[cmake] CMake Error at CMakeLists.txt:2 (project):
[cmake] No CMAKE_CXX_COMPILER could be found.
[cmake]
[cmake] Tell CMake where to find the compiler by setting either the environment
[cmake] variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
[cmake] to the compiler, or to the compiler name if it is in the PATH.
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[proc] The command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=D:/Projects/Software/Terraform/out/install/Ninja -S D:/Projects/Software/Terraform -B D:/Projects/Software/Terraform/out/build/Ninja -G Ninja exited with code: 1
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CMake Tools diagnostics and debug log in this issue, focusing on cmake.useVsDeveloperEnvironment, PATH handling, and Ninja selection on Windows. Trace the relevant configuration and environment setup entry points; done means a custom Ninja on PATH remains usable with the Visual Studio compiler environment, and automatic detection behaves as documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, typescript
- Domain
- build-system, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100