Ninja not found by CMake - cmake

I'm trying to build some code I got from GitHub using CMake, but keep getting the followings errors:
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 Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:/golang/project/src/github.com/devsisters/goquic/libquic/build/debug/CMakeFiles/2.8.11/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:/golang/project/src/github.com/devsisters/goquic/libquic/build/debug/CMakeFiles/2.8.11/CMakeCXXCompiler.cmake
-- Configuring incomplete, errors occurred!
How do I set these variables correctly?
I used a ./build_libs.sh file that came with the GitHub code to build this.

The script you are executing uses the CMake Ninja generator. For that to work you need Ninja on the path. On most Linux distributions you can install it from a package.
Ubuntu: ninja-build
openSUSE: ninja
If you can't find it for your distribution, you have to download it and add its location to the path environment variable.

My solution: symlink "ninja-build" to "ninja".
# ln -s /usr/bin/ninja /usr/bin/ninja-build
This only works on very old versions of CMake, which I will explain below.
I had already dropped my fresh "ninja" binary into /usr/bin and checked it had 0755 permissions. I was stumped until I ran an strace on the generator command.
# strace cmake -GNinja .. | grep -i ninja
access("ninja-build", R_OK) = -1 ENOENT (No such file or directory)
access("/usr/local/sbin/ninja-build", R_OK) = -1 ENOENT (No such file or directory)
access("/usr/local/bin/ninja-build", R_OK) = -1 ENOENT (No such file or directory)
access("/sbin/ninja-build", R_OK) = -1 ENOENT (No such file or directory)
access("/bin/ninja-build", R_OK) = -1 ENOENT (No such file or directory)
access("/usr/sbin/ninja-build", R_OK) = -1 ENOENT (No such file or directory)
access("/usr/bin/ninja-build", R_OK) = -1 ENOENT (No such file or directory)
access("/opt/texlive/2016/bin/i386-linux/ninja-build", R_OK) = -1 ENOENT (No such file or directory)
access("/root/bin/ninja-build", R_OK) = -1 ENOENT (No such file or directory)
It was looking for "ninja-build", not "ninja"!
I use CMake with Ninja extensively at work and at home, on Windows and Linux. So why haven't I seen this bug before?
Well... in this instance I'm using a very old version of CMake, version 2.8.12. It's so old it's almost fossilised. So presumably it's either a CMake bug which was fixed later, or the Ninja project changed the name of the binary at some point.

In Debian/Ubuntu systems, go ahead and install it
apt install ninja-build
Then rerun CMake.

If ninja really exists in $PATH and it still does not work, you should check the permission of the executable file via ls -l /PATH/TO/NINJA. Make sure others have read and execute permissions (like '-rwxr-xr-x').
See also: 0013910: Ninja generator initialization fails if /usr/bin/ninja is not world-readable

You may still suffer
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.
even you already have::
put ninja in your PATH
ninja executable with proper privilege
newer version of cmake**
Then it might because -D CMAKE_MAKE_PROGRAM and -G Ninja are specified at the same time but CMAKE_MAKE_PROGRAM with invalid value (such as empty).
For example
Android Studio with gradle plugin version :
classpath 'com.android.tools.build:gradle:7.0.0-alpha03'
and not using SDK Manager provided cmake, by:
put cmake executable in PATH environment variable
put ninja executable in PATH environment variable
specify cmake version equal to the one in PATH, in modules's build.gradle, like:
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.19.1" // this line
}
}
Then actually gradle calling cmake like this:
cmake ^
-HD:\dev\android_cv_examples\HelloNDK7\app\src\main\cpp ^
-DCMAKE_SYSTEM_NAME=Android ^
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON ^
-DCMAKE_SYSTEM_VERSION=26 ^
-DANDROID_ABI=arm64-v8a ^
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a ^
-DANDROID_NDK=D:\soft\Android\ndk-r21b ^
-DCMAKE_ANDROID_NDK=D:\soft\Android\ndk-r21b ^
-DCMAKE_TOOLCHAIN_FILE=D:\soft\Android\ndk-r21b\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM= ^
-DCMAKE_C_FLAGS= ^
-DCMAKE_CXX_FLAGS=-std=c++11 ^
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=D:\dev\android_cv_examples\HelloNDK7\app\build\intermediates\cmake\debug\obj\arm64-v8a ^
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=D:\dev\android_cv_examples\HelloNDK7\app\build\intermediates\cmake\debug\obj\arm64-v8a ^
-DCMAKE_BUILD_TYPE=Debug ^
-BD:\dev\android_cv_examples\HelloNDK7\app\.cxx\cmake\debug\arm64-v8a ^
-GNinja ^
-DANDROID_PLATFORM=android-24
Note: If removing previous cmake build cache, and modify that calling script by deleting -DCMAKE_MAKE_PROGRAM then problem will be solved.

I am using Mac Monterey. I put ninja into /Applications and /Users/USER/Applications and made sure $PATH was pointing to these directories, but no luck.
I only made CMake discover Ninja by installing it via homebrew:
brew install ninja

My issue was fixed by upgrading CMake to the latest version as specified in this answer:
https://askubuntu.com/a/865294/924090
This was apparently an issue in CMake that is now fixed in the latest version. More information here:
https://gitlab.kitware.com/cmake/cmake/-/issues/21486

At U20 was resolved for me only when using "pip install ninja" rather than "sudo apt install ninja-build"

Related

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

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.

How to set CMake variable to include directory

When trying to build this library with Cmake from the Developer Command Prompt for VS, I get this error
CMake Error at cmake/FindEigen.cmake:77 (MESSAGE):
Failed to find Eigen - Could not find eigen3 include directory, set
EIGEN_INCLUDE_DIR to path to eigen3 include directory, e.g.
/usr/local/include/eigen3.
I'd like find out what was intended of me here: am I to set EIGEN_INCLUDE_DIR with a command line argument or by editing the make file?
I've tried cmake -D EIGEN_INGLUDE_DIR=C:\Users\a\Downloads\eigen-3.3.7\eigen-3.3.7 . but received the same error.
cmake -D EIGEN_INGLUDE_DIR=C:\Users\a\Downloads\eigen-3.3.7\eigen-3.3.7 . failed without creating any files (cmake .. at least started building) and gave me this error
CMake Error: The source "C:/Users/a/Downloads/RpolyPlusPlus-master/RpolyPlusPlus-master/build/CMakeLists.txt" does not match the source "C:/Users/a/Downloads/RpolyPlusPlus-master/RpolyPlusPlus-master/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory.
So I just ended up adding this to the .cmake file:
# TODO: Add standard Windows search locations for Eigen.
LIST(APPEND EIGEN_CHECK_INCLUDE_DIRS
/usr/local/include
/usr/local/homebrew/include # Mac OS X
/opt/local/var/macports/software # Mac OS X.
/opt/local/include
/usr/include
C:\\Users\\a\\Downloads\\eigen-3.3.7) <---------------------------------------

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.

project PROJECT called with incorrect number of arguments

when I enter the console:
mkdir build && cd build && cmake .. && make
error occurs:
CMake Error at CMakeLists.txt: 5 (project): project PROJECT called
with incorrect number of arguments
CMake Error at CMakeLists.txt: 19 (find_package): By not providing
"FindQt5Gui.cmake" in CMAKE_MODULE_PATH this project has requested
CMake to find a package configuration file provided by "Qt5Gui", but
CMake did not find one.
Could not find a configuration file provided by "Qt5Gui" with any
of the following names:
Qt5GuiConfig.cmake
qt5gui-config.cmake
Add the installation prefix of "Qt5Gui" to CMAKE_PREFIX_PATH or set
"Qt5Gui_DIR" to a directory containing one of the above files. If
"Qt5Gui" provides a separate development package or SDK, be sure it
has been installed.
on the forums write that this is due to the fact that not installed qt5-defult and gt5-dev-tools, but before the installation and after nothing has changed what to do?