How to configure VS Code's CMake Tools Extension for GCC and MSYS Makefiles on Windows?
Asked Answered
D

2

7

This question is about the CMake Tools extension for VS Code. The operation system is Windows 10.

The extension correctly found GCC, which I can verify by having a look at the %LocalAppData%/CMakeTools/cmake-tools-kits.json.

{
  "name": "GCC 10.3.0 x86_64-w64-mingw32",
  "compilers": {
    "C": "C:\\msys64\\mingw64\\bin\\x86_64-w64-mingw32-gcc.exe",
    "CXX": "C:\\msys64\\mingw64\\bin\\x86_64-w64-mingw32-g++.exe"
  }
}

I tried to configure through the respective VS Code command and got an error:

[rollbar] Unhandled exception: Unhandled Promise rejection: configure Error: No usable generator found. {}

Then I added the respective setting to my local settings .vscode/settings.json.

{ "cmake.generator": "MSYS Makefiles" }

I got the following output:

[proc] Executing command: "C:/Program Files/CMake/bin/cmake.exe" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=C:\msys64\mingw64\bin\x86_64-w64-mingw32-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\msys64\mingw64\bin\x86_64-w64-mingw32-g++.exe -H<path to project root> -B<path to build directory> -G "MSYS Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Error: CMake was unable to find a build program corresponding to "MSYS Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
[cmake] CMake Error: CMake was unable to find a build program corresponding to "MSYS Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
[cmake] CMake Error: CMAKE_AR was not found, please set to archive program. 
[cmake] -- Configuring incomplete, errors occurred!

So I extended my local settings.

{
  "cmake.generator": "MSYS Makefiles",
  "cmake.environment": {
    "CMAKE_AR": "C:/msys64/usr/bin/ar.exe",
    "CMAKE_MAKE_PROGRAM": "C:/msys64/usr/bin/make.exe"
  }
}

Got the same output as before. I also tried setting these variables in the CMakeLists.txt and as system environment variables.

What is the proper way to do this?

Dev answered 5/2, 2022 at 17:39 Comment(2)
Variable CMAKE_MAKE_PROGRAM is a CMake variable, not an environment one. (The variable is not listed among environment variables affecting on CMake). So, for set this variable you need to use "cmake.configureSettings" instead of "cmake.environment".Bathymetry
@Bathymetry That's it. Thank you. I got confused with environment and CMake variables. Why didn't you post it as an answer, though?Dev
G
2

I know this is an old request, but I've recently been suffering from this issue.

The trick I found (with the current version of MSYS2 on Windows), was to install the cmake version of mingw64.

With command:

pacman -S mingw-w64-x86_64-cmake

NOTE: This assumes that pacman is defined in your path, otherwise you will need to prefix the pacman with the path.

Then install Ninja:

pacman -S ninja

You shouldn't need to define the configuration in VSCode settings, it should just work.

Greyback answered 1/1, 2023 at 19:39 Comment(0)
E
1

From the command from @Tsyvarev I was able to solve a similar issue for my setup, so I'll might as well post a answer for the next person.

I'm using UCRT64 environment instead of MINGW64, since this is the recommended MSYS2 environment. For OP's question change ucrt64 to mingw64.

Some programs (git for Windows) might ship MINGW64 binaries. If you encounter issues try to set the PATH variable to exclude those directories. If CMake can't find some standard libraries (e.g. openblas) try to set CMAKE_PREFIX_PATH.

My final settings.json looks something like this:

{
  "cmake.cmakePath": "C:/msys64/ucrt64/bin/cmake.exe",
  "cmake.configureSettings": {
    "CMAKE_AR": "C:/msys64/ucrt64/bin/ar.exe",
    "CMAKE_MAKE_PROGRAM": "C:/msys64/usr/bin/make.exe",
    "CMAKE_PREFIX_PATH": "C:/msys64/ucrt64"
  },
  "cmake.environment": {
    "PATH": "C:\\msys64\\ucrt64\\bin;C:\\msys64\\usr\\bin;${env:PATH}"
  },
  "cmake.generator": "MSYS Makefiles",
  [...]
}
Entoderm answered 7/8, 2023 at 16:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.