cmake: problems with out of tree build - windows

With my current CMakeLists.txt files, I can build my project with:
sourceDir> cmake -G "MinGW Makefiles" .
from the source directory.
However I cannot get an out-of-tree build:
buildDir> cmake -G "MinGW Makefiles" ..\MyProg
This is the error I get from cmake:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeMinGWFindMake.cmake:20 (MESSAGE):
sh.exe was found in your PATH, here:
C:/Program Files (x86)/Git/bin/sh.exe
For MinGW make to work correctly sh.exe must NOT be in your path.
Run cmake from a shell that does not have sh.exe in your PATH.
If you want to use a UNIX shell, then use MSYS Makefiles.
Call Stack (most recent call first):
CMakeLists.txt:16 (project)
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:S:/MyProg/build/CMakeFiles/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:S:/MyProg/build/CMakeFiles/CMakeCXXCompiler.cmake
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

That does not make sense those errors come from the environment being setup different. Are both commands being run from the exact same shell? Also, once you configure in-source, you can not do an out of source build. So, to test try this:
mkdir newsource; checkout your source here
mkdir ../build
cd ../build
cmake -G"MinGW Makefiles" ../newsource
mkdir insource; checkout out your source here
cmake -G"MinGW Makefiles" .
Do both of these from the exact same shell.

I found a dirty fix to my problem:
buildDir> cmake -G "MinGW Makefiles" ..\MyProg\
buildDir> cmake -G "MinGW Makefiles" ..\MyProg\
The first time I get the error shown in my question. The second time everything goes as it should.
Let me know if you have a better, more logic solution.

I think you have to remove "MinGW\msys\1.0\bin" from your windows PATH environment variable.

Related

What is wrong with cmake under mingw

mkdir build
cd build
cmake -G "MinGW Makefiles" ..
CMake Error at I:/msys64/mingw32/share/cmake-3.13/Modules/CMakeMinGWFindMake.cmake:12 (message):
sh.exe was found in your PATH, here:
I:/msys64/usr/bin/sh.exe
For MinGW make to work correctly sh.exe must NOT be in your path.
Run cmake from a shell that does not have sh.exe in your PATH.
If you want to use a UNIX shell, then use MSYS Makefiles.
Call Stack (most recent call first):
CMakeLists.txt:16 (PROJECT)
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
but it would appear the the offending sh.exe is part of msys??
OK so try the msys shell... i:\msys64\mingw32
rm -rf build
mkdir build
cd build
cmake -G "MinGW Makefiles" ..
CMake Error at I:/msys64/mingw32/share/cmake-3.13/Modules/CMakeMinGWFindMake.cmake:12 (message):
sh.exe was found in your PATH, here:
I:/msys64/usr/bin/sh.exe
For MinGW make to work correctly sh.exe must NOT be in your path.
Run cmake from a shell that does not have sh.exe in your PATH.
If you want to use a UNIX shell, then use MSYS Makefiles.
Call Stack (most recent call first):
CMakeLists.txt:16 (PROJECT)
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
same thing.
should sh.exe not be there?
one last try...
cmake -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND" ..
$ cmake -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND" ..
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
So it would seem there's a second problem as well?
any help? thanks.
First of all, make sure you have mingw32-make installed:
which mingw32-make
if not /mingw64/bin/mingw32-make then either the path is not in your ~/.bashrc or it is not installed. I think you can install it by
pacman -S mingw64/mingw-w64-x86_64-make
which is also part of mingw-w64-x86_64-toolchain that you have probably already installed. then you should be able to run
cmake -D CMAKE_MAKE_PROGRAM:PATH=/mingw64/bin/mingw32-make
please give it a try and let me know if this works for you.

Can't run Cmake on windows with MinGW and git bash

I try to build gitql.
I've installed go, CMake and MinGW, and tried to make them work under git bash, but when I call cmake in gitql directory I get this error:
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:14 (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.
-- Configuring incomplete, errors occurred!
See also "C:/Go/src/github.com/cloudson/gitql/libgit2/CMakeFiles/CMakeOutput.log".
See also "C:/Go/src/github.com/cloudson/gitql/libgit2/CMakeFiles/CMakeError.log".
make: *** [prepare] B▒▒d 1
So I've tried to point to gcc from mingw using:
export CC=/c/MinGW/bin/gcc.exe
and when I run make I get this error:
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_14ff0\fast"
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.7/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: C:/Go/src/github.com/cloudson/gitql/libgit2/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_14ff0\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_14ff0\fast"
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:14 (PROJECT)
-- Configuring incomplete, errors occurred!
See also "C:/Go/src/github.com/cloudson/gitql/libgit2/CMakeFiles/CMakeOutput.log".
See also "C:/Go/src/github.com/cloudson/gitql/libgit2/CMakeFiles/CMakeError.log".
make: *** [prepare] B▒▒d 1
How can I inform cmake to use make instead of nmake? I have make installed in C:\Program Files (x86)\GnuWin32\bin which is in $PATH.
I've also try to call cmake -G "MinGW Makefiles" but I've got this error:
CMake Error: The source directory "C:/Go/src/github.com/cloudson/gitql" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
cmake -G "MinGW Makefiles" is effectively the right command to inform CMake you want to use MinGW.
To be complete, you should create a separate folder, let's call it build, and call cmake from it to make an out-of-source build:
cd /path/to/build
cmake -G "MinGW Makefiles" /path/to/CMakeLists.txt
The problem here is gitql doesn't provide any CMakeLists.txt file in the repository, so you just can't use CMake to build it, unless you create your own project file. You can try from the given Makefile, and propose it as a pull request.

Unable to specify the compiler with CMake

I have a problem with this CMakeLists.txt file:
cmake_minimum_required(VERSION 2.6)
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
SET(CMAKE_CXX_COMPILER C:/MinGW/bin/g++)
project(cmake_test)
add_executable(a.exe test.cpp)
Calling cmake with: cmake -G "MinGW Makefiles" , it fails with the following output:
c:\Users\pietro.mele\projects\tests\buildSystem_test\cmake_test>cmake -G "MinGW Makefiles" .
-- The C compiler identification is GNU 4.6.1
-- The CXX compiler identification is GNU 4.6.1
-- Check for working C compiler: C:/MinGW/bin/gcc
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: C:/MinGW/bin/gcc -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "C:/MinGW/bin/gcc" is not able to compile a simple test
program.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:10 (project)
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "C:/MinGW/bin/g++" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
-- Configuring incomplete, errors occurred!
However the gcc compiler is in C:/MinGW/bin/ and it works.
Any idea?
Platform:
Windows 7
MinGW/GCC 4.6
Never try to set the compiler in the CMakeLists.txt file.
See the CMake FAQ about how to use a different compiler:
https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler
(Note that you are attempting method #3 and the FAQ says "(avoid)"...)
We recommend avoiding the "in the CMakeLists" technique because there are problems with it when a different compiler was used for a first configure, and then the CMakeLists file changes to try setting a different compiler... And because the intent of a CMakeLists file should be to work with multiple compilers, according to the preference of the developer running CMake.
The best method is to set the environment variables CC and CXX before calling CMake for the very first time in a build tree.
After CMake detects what compilers to use, it saves them in the CMakeCache.txt file so that it can still generate proper build systems even if those variables disappear from the environment...
If you ever need to change compilers, you need to start with a fresh build tree.
I had similar problem as Pietro,
I am on Window 10 and using "Git Bash".
I tried to execute >>cmake -G "MinGW Makefiles", but I got the same error as Pietro.
Then, I tried >>cmake -G "MSYS Makefiles", but realized that I need to set my environment correctly.
Make sure set a path to C:\MinGW\msys\1.0\bin and check if you have gcc.exe there. If gcc.exe is not there then you have to run C:/MinGW/bin/mingw-get.exe and install gcc from MSYS.
After that it works fine for me
Using with FILEPATH option might work:
set(CMAKE_CXX_COMPILER:FILEPATH C:/MinGW/bin/gcc.exe)
I had the same issue. And in my case the fix was pretty simple. The trick is to simply add the ".exe" to your compilers path. So, instead of :
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
It should be
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc.exe)
The same applies for g++.

cmake problems in Windows

I am trying to compile this (quite complex) piece of code with cmake and MinGW in Windows:
#include <iostream>
int main()
{
std::cout << "Test" << std::endl;
return 0;
}
This is the CMakeLists.txt file (which works correctly in Linux):
cmake_minimum_required(VERSION 2.6)
SET(CMAKE_C_COMPILER path/to/gcc)
SET(CMAKE_CXX_COMPILER path/to/g++)
project(cmake_test)
add_executable(a.exe test.cpp)
With the command:
cmake -G"MinGW Makefiles" .
I get these errors:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeMinGWFindMake.cmake:20 (MESSAGE):
sh.exe was found in your PATH, here:
C:/MinGW/msys/1.0/bin/sh.exe
For MinGW make to work correctly sh.exe must NOT be in your path.
Run cmake from a shell that does not have sh.exe in your PATH.
If you want to use a UNIX shell, then use MSYS Makefiles.
Call Stack (most recent call first):
CMakeLists.txt:8 (project)
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: Could not find cmake module file:C:/cmake_test/CMakeFiles/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: Could not find cmake module file:C:/cmake_test/CMakeFiles/CMakeCXXCompiler.cmake
-- Configuring incomplete, errors occurred!
These errors did not help me much. Considering it works in Linux, it must be something related to the Window's configuration.
Thank you for any help!
Configuration:
- Windows 7
- MinGW/GCC 4.6.1
You may have better results with -G "MSYS Makefiles" instead of "MinGW Makefiles" - but I warn you - it is going to be slow.
This is due to you have in your path C:/MinGW/msys/1.0/bin/, for generating projects with CMake and MinGW, delete it from your path and add C:/MinGW/bin/ instead
Removing sh.exe from the PATH improved thing.
I get more errors, but at a later stage...

Running CMake on Windows

I am currently trying to get CMake to run on my Windows 7 (64-bit) system. I want to compile TagLib for later use with a Qt application I am working on. I would like to compile it with MinGW (not Visual C++ as in this other question).
I download the installer (cmake-2.8.3-win32-x86.exe) and install it (I also opt to add CMake to my path). I then go to the directory why the CMakeLists.txt file is and run cmake .. It then gives me this giant error.
C:\Users\Joel\Downloads\taglib-1.6.3>cmake .
CMake Warning at CMakeLists.txt:1 (project):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Warning at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-cl.cmake:
28 (ENABLE_LANGUAGE):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
Call Stack (most recent call first):
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:60 (INCLUDE)
CMakeLists.txt:1 (project)
CMake Error: your RC compiler: "CMAKE_RC_COMPILER-NOTFOUND" was not found. Please set CMAKE_RC_COM
PILER to a valid compiler path or name.
-- Check for CL compiler version
-- Check for CL compiler version - failed
-- Check if this is a free VC compiler
-- Check if this is a free VC compiler - yes
-- Using FREE VC TOOLS, NO DEBUG available
-- Check for working C compiler: cl
CMake Warning at CMakeLists.txt:2 (PROJECT):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
CMake Warning at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-cl.cmake:
28 (ENABLE_LANGUAGE):
To use the NMake generator, cmake must be run from a shell that can use the
compiler cl from the command line. This environment does not contain
INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
work.
Call Stack (most recent call first):
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:60 (INCLUDE)
CMakeLists.txt:2 (PROJECT)
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeRCInformation.cmake:22
(GET_FILENAME_COMPONENT):
get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-cl.cmake:28 (ENABLE_LANG
UAGE)
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeCInformation.cmake:60 (INCLUDE)
CMakeLists.txt:2 (PROJECT)
CMake Error: CMAKE_RC_COMPILER not set, after EnableLanguage
CMake Error: your C compiler: "cl" was not found. Please set CMAKE_C_COMPILER to a valid compiler
path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: cl -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52
(MESSAGE):
The C compiler "cl" is not able to compile a simple test program.
It fails with the following output:
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:1 (project)
CMake Error: your C compiler: "cl" was not found. Please set CMAKE_C_COMPILER to a valid compiler
path or name.
CMake Error: your CXX compiler: "cl" was not found. Please set CMAKE_CXX_COMPILER to a valid compi
ler path or name.
-- Configuring incomplete, errors occurred!
C:\Users\Joel\Downloads\taglib-1.6.3>
I was kind of surprised that it failed so hard out of the box, considering it advertises itself as a cross-platform make.
I tried setting INCLUDE, LIB, and LIBPATH (Windows environment variables) all to my MinGW binaries directory (C:\MinGW\bin) but it's still giving me the same error. I also tried setting CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to the location of g++ (C:\MinGW\bin\g++).
Does anyone know what's going on here?
SOLUTION:
Per tibur's suggestion, I ran the cmake GUI to create the make files.
I then went into the directory taglib directory and ran mingw32-make.exe to do the actual build.
The default generator for Windows seems to be set to NMAKE. Try to use:
cmake -G "MinGW Makefiles"
Or use the GUI, and select MinGW Makefiles when prompted for a generator. Don't forget to cleanup the directory where you tried to run CMake, or delete the cache in the GUI. Otherwise, it will try again with NMAKE.
There is a vcvars32.bat in your Visual Studio installation directory. You can add call cmd.exe at the end of that batch program and launch it. From that shell you can use CMake or cmake-gui and cl.exe would be known to CMake.
the command that worked for me is:
$ cmake -G "MSYS Makefiles" ..
I'm working on MSYS2/Win10 compiling a QT5 app #64bit (using the MINGW64 shell)
Use: cmake --build
after cmake -G "MinGW Makefiles"

Resources