在 Eclipse CDT 和 Cygwin Windows 上使用 CMake

Using CMake with Eclipse CDT and Cygwin on Windows

对于一个新项目,我们想使用 CMake。我们正在使用 Eclipse CDT 作为 IDE 和 Cygwin gcc.

我们生成了 CMakeLists.txt 并遵循了 [本教程(选项 2)][1]。

当我尝试 运行 所描述的 Make 目标以使用 CMake 生成 Makefile 时,它​​执行

cmake -E chdir C:/projects/eclipse_ws/MyApp/Build/ cmake -G "Unix Makefiles" ../ Run CMake 

我收到错误

CMake Error: The source directory "C:/projects/eclipse_ws/MyApp/Build/CMake" does not exist.

如果我直接从 Cygwin 控制台 运行 命令它工作得很好,但是我还必须 运行 从 Cygwin 控制台 make,因为 Makefiles 是用 Unix 路径生成的。

编辑:

所以我解决了这个问题(见下面我的回答)。

但我仍然遇到问题。

当我按照教程中的建议尝试 运行 CMake 作为 Eclipse 中的 Make 目标时,出现以下错误:

cmake -E chdir Build/ cmake -G 'Unix Makefiles' ../ 
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
System is unknown to cmake, create:
Platform/MINGW32_NT-6.1 to use this system, please send your config file to cmake@www.cmake.org so it can be added to cmake
Your CMakeCache.txt file was copied to CopyOfCMakeCache.txt. Please send that file to cmake@www.cmake.org.
-- Check for working C compiler: /usr/bin/gcc.exe
System is unknown to cmake, create:
Platform/MINGW32_NT-6.1 to use this system, please send your config file to cmake@www.cmake.org so it can be added to cmake
-- Check for working C compiler: /usr/bin/gcc.exe -- broken
CMake Error at /usr/share/cmake-2.8.9/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
  The C compiler "/usr/bin/gcc.exe" is not able to compile a simple test
  program.

  It fails with the following output:

   Change Dir: /cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles CMakeTmp

  Run Build Command:/usr/bin/make.exe "cmTryCompileExec726566634/fast"

  /usr/bin/make -f CMakeFiles/cmTryCompileExec726566634.dir/build.make
  CMakeFiles/cmTryCompileExec726566634.dir/build

  make[1]: Entering directory
  '/cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles/CMakeTmp'

  /usr/bin/cmake.exe -E cmake_progress_report
  /cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles/CMakeTmp/CMakeFiles
  1

  Building C object
  CMakeFiles/cmTryCompileExec726566634.dir/testCCompiler.c.obj

  /usr/bin/gcc.exe -o
  CMakeFiles/cmTryCompileExec726566634.dir/testCCompiler.c.obj -c
  /cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles/CMakeTmp/testCCompiler.c

  CMakeFiles/cmTryCompileExec726566634.dir/build.make:60: recipe for target
  'CMakeFiles/cmTryCompileExec726566634.dir/testCCompiler.c.obj' failed

  make[1]: Leaving directory
  '/cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles/CMakeTmp'

  make[1]: *** [CMakeFiles/cmTryCompileExec726566634.dir/testCCompiler.c.obj]
  Error 1

  Makefile:117: recipe for target 'cmTryCompileExec726566634/fast' failed

  make: *** [cmTryCompileExec726566634/fast] Error 2

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)

-- Configuring incomplete, errors occurred!

似乎出于某种原因 CMake 假设我有一个 MinGW 环境而不是 Cygwin。

EDIT2 假设是 MinGW 系统,因为 Git 安装在 Cygwin 之前的 PATH 中并且使用了 Git 的 uname 命令(returns MinGW)。

如果您在 Eclipse 的 Make 对话框中选中 "Make Target - Same as the target name",Eclipse 将添加一个

Run CMake

命令(参见问题),CMake 对其进行了错误解释。 我刚刚取消选中 "Same as the target name".