Search code examples
cmakecygwin

How to tell CMake to use Windows paths, not Cygwin ones?


I am on Cygwin and I would like to call a compiler installed on Windows. I have an issue with the paths format.

With this very simple 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
)

I get an issue when CMake checks for the compiler:

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

It is because CMake doesn't know, or perhaps it should know, that iccarm.exe is a Windows program that is expecting windows paths.

Is there a solution to give CMake this information?

I imaging something like:

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

Solution

  • Turning my comments into an answer

    Please be aware that Cygwin's CMake would give /cygdrive prefixes, but Windows installed CMake version won't.

    I've run a test with your CMakeLists.txt, the IAR ARM compilers in my PATH environment and could successfully run from the 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: ...
    

    If I do just call cmake .. (the Cygwin version) I get the same errors you got.