Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If value not equal in cmake 2.8

Tags:

cmake

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?

like image 556
simont Avatar asked Jul 31 '12 13:07

simont


People also ask

What is CMake Strequal?

According to the CMake documentation, the STREQUAL comparison is allowed to take either a VARIABLE or a STRING as either parameter. So, in this example below, the message does NOT print, which is broken: set( FUBARTEST "OK" ) if( FUBARTEST STREQUAL "OK" ) message( "It Worked" ) endif()

What does Add_subdirectory do in CMake?

Add a subdirectory to the build. Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.

How do you set a variable value in CMake?

You can use the command line to set entries in the Cache with the syntax cmake -D var:type=value , just cmake -D var=value or with cmake -C CMakeInitialCache. cmake . You can unset entries in the Cache with unset(... CACHE) .

How do I use environment variables in CMake?

Use the syntax $ENV{VAR} to read environment variable VAR . To test whether an environment variable is defined, use the signature if(DEFINED ENV{<name>}) of the if() command. For general information on environment variables, see the Environment Variables section in the cmake-language(7) manual.


1 Answers

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").  
like image 179
Fraser Avatar answered Sep 28 '22 05:09

Fraser