如何告诉CMake使用Windows路径,而不是Cygwin路径?

时间:2017-08-29 09:09:13

标签: cmake cygwin

我在Cygwin上,我想调用Windows上安装的编译器。我的路径格式有问题。

这非常简单CMakeLists.txt

cmake_minimum_required(VERSION 3.6)

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR Cortex-M4)

set(CMAKE_C_COMPILER iccarm.exe)
set(CMAKE_CXX_COMPILER iccarm.exe)
set(CMAKE_ASM_COMPILER iasmarm.exe)

project("test" C)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

if(NOT EXISTS main.c)
    file(WRITE main.c "int main(void){return 0;}\n")
endif()

add_executable(
    test
    main.c
)

当CMake检查编译器时出现问题:

-- The C compiler identification is IAR
-- Check for working C compiler: /cygdrive/c/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe
-- Check for working C compiler: /cygdrive/c/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe -- broken
CMake Error at /usr/share/cmake-3.6.2/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "/cygdrive/c/Program Files (x86)/IAR Systems/Embedded
  Workbench 8.0/arm/bin/iccarm.exe" is not able to compile a simple test
  program.

  It fails with the following output:

   Change Dir: /cygdrive/c/Users/nobody/home/sandbox/cmakeiar/CMakeFiles/CMakeTmp

这是因为CMake不知道,或者它应该知道,iccarm.exe是一个期待Windows路径的Windows程序。

是否有解决方案可以提供此信息?

我想像:

if(PLATFORM_IS_CYGWIN)
    set(CMAKE_IS_WINDOWS_EXECUTABLE iccarm.exe)
endif()

1 个答案:

答案 0 :(得分:1)

将我的评论转化为答案

请注意,Cygwin的CMake会提供/cygdrive前缀,但Windows安装的CMake版本不会。

我已经在我的CMakeLists.txt环境中使用PATH IAR ARM编译器运行测试,并且可以从Cygwin bash shell成功运行:

$ /cygdrive/c/Program\ Files/CMake/bin/cmake -G "Unix Makefiles" ..
-- The C compiler identification is IAR
-- Check for working C compiler: C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe
-- Check for working C compiler: C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: ...

如果我只是致电cmake ..(Cygwin版本),我会得到同样的错误。