cmake:出树问题

用我当前的CMakeLists.txt文件,我可以用下面的方法构build我的项目:

 sourceDir> cmake -G "MinGW Makefiles" . 

从源目录。

但是,我无法得到一个树外的构build:

 buildDir> cmake -G "MinGW Makefiles" ..\MyProg 

这是我从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! 

这是没有道理的,这些错误来自环境设置不同。 两个命令是从完全相同的shell运行吗? 而且,一旦你配置了源代码,你不能做一个源代码构建。 所以,要测试这个:

mkdir新闻来源; 在这里签出你的来源mkdir ../build cd ../build cmake -G“MinGW Makefiles”../newsource

mkdir内部; 在这里检查你的源代码cmake -G“MinGW Makefiles”。

做这两个从完全相同的外壳。

我发现一个肮脏的修复我的问题:

 buildDir> cmake -G "MinGW Makefiles" ..\MyProg\ buildDir> cmake -G "MinGW Makefiles" ..\MyProg\ 

我第一次得到我的问题中显示的错误。 第二次,所有事情都应该如此。

让我知道如果你有一个更好的,更多的逻辑解决方案。

我想你必须从Windows PATH环境变量中删除“MinGW \ msys \ 1.0 \ bin”。