Search code examples
cmakecygwin

CMAKE does not define the CYGWIN variable


I am using cmake on a cygwin console under Windows 7 64 bit. However the cmake variable CYGWIN (https://cmake.org/cmake/help/v3.3/variable/CYGWIN.html) is undefined. Am I missing something?

For example, here is my CMakeLists.txt:

message("CYGWIN: ${CYGWIN}")
message("CMAKE SYSTEM: ${CMAKE_SYSTEM_NAME}")
project ( foo CXX)

I lauch the cygwin console and do:

cmake path/to/my/CMakeLists.txt

Selected Output:

>    CYGWIN: 
>    CMAKE SYSTEM:
> -- The CXX compiler identification is GNU 4.9.2
> 
>    ( a warning about the WIN32 variable not being defined by cmake anymore)
> 
> -- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++.exe
> -- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++.exe -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> -- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc.exe
> -- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc.exe -- works
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /foo/directory

Configuration:

  • uname CYGWIN_NT-6.1
  • cmake version 3.3.2 (CMake suite maintained and supported by Kitware (kitware.com/cmake).

Solution

  • The CYGWIN cmake variable is defined by the project() command. Moving it before the message commands solves the problem.

    CMakeLists.txt:

    project(foo CXX)
    message("CYGWIN: ${CYGWIN}")
    message("CMAKE SYSTEM: ${CMAKE_SYSTEM_NAME}")
    

    Relevant Output:

    > -- The CXX compiler identification is GNU 4.9.2
    >    (a lot of talking)
    >    CYGWIN: 1
    >    CMAKE SYSTEM: CYGWIN