58

Short version: I have build options that only work on one platform. The autotools file I'm converting form has a check of the form if test "$platform_linux" != "yes". Can I do the same thing in my CMakeLists.txt (test if the value is NOT equal)?

Slightly longer version: I've got a test for various platforms following the advice found here:

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    # Linux specific code
    SET(OperatingSystem "Linux")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

I'd like to do a test of the form IF(${CMAKE_SYSTEM_NAME} NOT MATCHES "Linux"). This doesn't appear to work, and the only documentation I can find is a mailing-list post from 2002, which suggests the NOT isn't valid for cmake prior to 1.2. [Link].

Is this still the case in later cmake versions, specifically 2.6 and/or 2.8?

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
simont
  • 68,704
  • 18
  • 117
  • 136

1 Answers1

100

You're close! The correct syntax for IF is

IF(NOT <expression>)

So in your specific case, you want

IF(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux")
starball
  • 20,030
  • 7
  • 43
  • 238
Fraser
  • 74,704
  • 20
  • 238
  • 215