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
?
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()
Add a subdirectory to the build. Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.
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) .
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.
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").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With