windowscmakemingwout-of-source

cmake: problems with out of tree build


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!

Solution

  • 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.