Cygwin cmake not suitable for CMAKE_SYSTEM_NAME

I have very strange behavior on cygwin using cmake. I am trying to check the OS in CMakeLists.txt, but this particular case seems to not work ... Here is an example that causes my problem:

set (FOO "BAR")

message(${CMAKE_SYSTEM_NAME})

if (${CMAKE_SYSTEM_NAME} STREQUAL "CYGWIN")
    message("EQUALS CYGWIN")
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "CYGWIN")
    message("MATCHES CYGWIN")
endif()

if (${FOO} MATCHES "BAR")
    message("MATCHES BAR")
endif()

CMake prints:

CYGWIN
EQUALS CYGWIN
MATCHES BAR

And not the expected "MATCHES CYGWIN". It seems strange to me that it works for other variables (for example, here is FOO). Is there something I'm doing wrong?

Configuration:

  • version cmake 2.8.11.2
  • uname CYGWIN_NT-6.1

PS: I also checked FOO = "CYGWIN" and it does not match any of them. It seems that only this line does not work with MATCHES ...

+3
source share
2 answers

Cause

Signature command ifcmake

if(<variable|string> MATCHES regex)

but not

if(<string> MATCHES regex)

, CYGWIN , , CYGWIN .

</h3 >

CYGWIN (. ):

> cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
project(foo)
message("cygwin variable: ${CYGWIN}")
> cmake -H. -B_builds
...
cygwin variable: 1
...

if (${CMAKE_SYSTEM_NAME} STREQUAL "CYGWIN")
    # variable CYGWIN vs variable CYGWIN, i.e. 1 == 1
    message("EQUALS CYGWIN") # success
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "CYGWIN")
    # variable CYGWIN (i.e. 1) vs regex CYGWIN
    message("MATCHES CYGWIN") # fail
endif()

if (${FOO} MATCHES "BAR")
    # string BAR vs string BAR
    message("MATCHES BAR") # success
endif()

<variable|string> , :

> cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
project(foo)
set("/this/is/definitely/not/a/variable/name" "surprise!")
message("${/this/is/definitely/not/a/variable/name}")
> cmake -H. -B_builds
...
surprise!
...

, string:

string(COMPARE EQUAL "${CMAKE_SYSTEM_NAME}" "CYGWIN" is_cygwin)
if(is_cygwin)
  message("Hello, cygwin!")
endif()

, CYGWIN:

if(CYGWIN)
  message("Hello, cygwin!")
endif()

+3

:

if (${CMAKE_SYSTEM_NAME} MATCHES "CYGWIN")

if (CMAKE_SYSTEM_NAME MATCHES "CYGWIN")

.

+1

All Articles