How to configure VS Code's CMake Tools Extension for GCC and MSYS Makefiles on Windows? - cmake

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?

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.

Related

How to fix Cmake installation error in Open3d? [duplicate]

I'm following this tutorial for building GLFW on Windows, and I'm getting the error when running cmake -S . -B Build:
PS ~\glfw-3.3.2\GLFW> cmake -S . -B Build
CMake Error at CMakeLists.txt:3 (project):
Running
'nmake' '-?'
failed with:
The system cannot find the file specified
-- Configuring incomplete, errors occurred!
See also "~/glfw-3.3.2/GLFW/Build/CMakeFiles/CMakeOutput.log".
Output log is almost completely empty containing only one line with my windows version.
I haven't found any discussions or problems matching mine. And I don't even know does nmake have -? flag since it's not listed on microsoft docs site.
I've tried positioning in other folder because maybe that's the case. But with no luck.
I tried solving it with other error solution's but to no avail.
The solution was to append -G "MinGW Makefiles" to cmake -S . -B Build command. As Tsyvarev suggested I looked more into generators and found out that setting the flags doesn't imply which generator will be used. So manually setting the flags solved the problem for me.
The error is about absent nmake utility, which is a build tool for CMake projects configured with "NMake Makefiles" generator.
You need either to install nmake, or specify (with -G option) other generator, which is available on your platform (Windows) and for which you have a built tool. Possible selection of other generators includes e.g. "MinGW Makefiles" and "Visual Studio" family.

How to install and configure 'cmake' in MSYS2?

How to install and configure 'cmake' in MSYS2?
I have tried installing the following MSYS packages
I am getting the following error on running any cmake commands
'''
CMake Deprecation Warning at CMakeLists.txt:5 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument value or use a ... suffix to tell
CMake that the project does not need compatibility with older versions.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:8 (project):
The CMAKE_C_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:8 (project):
The CMAKE_CXX_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
'''
Please help resolve this error.
CMake on Windows tries to use the MSVC compiler by default (cl). To make it use GCC, add following flags: -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++.
You can search for packages on https://packages.msys2.org and find cmake package :
pacman -S cmake

Set CMAKE_MAKE_PROGRAM to mingw32-make from inside the CMakeLists.txt

Following this post, if I run cmake .. inside my build folder with no options I get the error:
CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_Fortran_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
which I can solve by running
cmake .. -D CMAKE_MAKE_PROGRAM:PATH=/mingw64/bin/mingw32-make
However, I want to set the CMAKE_MAKE_PROGRAM from inside the CMakeLists.txt file. I tried the
if(MSYS)
set(CMAKE_MAKE_PROGRAM /mingw64/bin/mingw32-make)
endif(MSYS)
but it doesn't work. I would appreciate it if you could help me know how I can resolve this problem.
P.S.1. Here is the code.
P.S.2. I tried the
set(CMAKE_MAKE_PROGRAM /mingw64/bin/mingw32-makemingw32-make CACHE FILEPATH "" FORCE)
as suggested in the comments but it did not help.
P.S.3. My operating system is Windows 10 version 1909, and I'm running the above commands in MSYS2 terminal MSYS_NT-10.0-18363
Ok, I think I solved the problem. From here, I needed to install the MSYS2's make:
pacman -S make
This seems like a trend too me. I have recently had several problems in MSYS2 which have been resolved by removing the MinGW package and replacing it with the MSYS2 package. So it tells me that when working inside MSYS2 I should favor MSYS2 packages if they are available.

Installing LLReve using Cmake. Unknown BISON_TARGET error

I am getting the following error :
CMake Error at CMakeLists.txt:9 (BISON_TARGET):
Unknown CMake command "BISON_TARGET".
when I run the command :
cmake .. -GNinja
Please tell me what to do. I tried searching on google a lot and thus came up with the additions and finally ran the command :
cmake .. -D LLVM_DIR=/usr/lib/llvm-5.0/cmake/ -D FLEX_EXECUTABLE=/usr/local/Cellar/flex/2.5.37/bin/ -D FLEX_INCLUDE_DIR=/usr/local/Cellar/flex/2.5.37/include/ -D BISON_EXECUTABLE=/usr/bin/bison
but it still shows the same error :(.
Please someone help.
Your error is occurring because the BISON_TARGET function definition has not yet been supplied. This method, as commented, is supplied by FindBISON. The error indicates that either Bison was not found on your system (hopefully, you have it installed), or cmake was ran from the wrong directory. Bison is included in the top-level CMake file via:
find_package(BISON REQUIRED)
This line to include Bison must be called before using the BISON_TARGET CMake function. The LLReve instructions for compiling this repository are explicit about which directory to run the build commands in:
Go to the llreve directory and run
cd reve
mkdir build
cd build
cmake .. -GNinja
ninja
This would run on the CMake file in the llreve/reve directory, not the llreve/reve/reve directory. Please ensure you are running CMake from the correct location, as not running cmake on the top-level CMake file will often yield errors.

Unknown CMake command "CHECK_INCLUDE_FILE_CXX"

I tried running cmake to generate the build tools for linux on vmime with the latest source from git hub, it generated the following errors. Thoughts??
vmime$ /usr/local/bin/cmake -G "Unix Makefiles"
CMake Error at CMakeLists.txt:20 (INCLUDE):
include could not find load file:
CheckIncludeFileCxx
-- Build type: Debug
CMake Error at CMakeLists.txt:452 (CHECK_INCLUDE_FILE_CXX):
Unknown CMake command "CHECK_INCLUDE_FILE_CXX".
-- Configuring incomplete, errors occurred!
In your CMakeLists.txt at line 20, you have
include(CheckIncludeFileCxx)
This should be
include(CheckIncludeFileCXX)
^^--- Uppercase
Once CheckIncludeFileCXX is properly included, the error on line 452 should also disappear, since the file defines the function CHECK_INCLUDE_FILE_CXX.
It has probably only been tested on Windows; since Windows filenames are case-insensitive this would have worked.