Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake IF(something OR something else)

Does the CMake IF statement have an OR option as well? Something like: IF (NOT this OR that) ... ENDIF?

I have the line if (NOT ${TARGET_PLATFORM} STREQUAL "test"), which removes certain build files from the project. I want to add a second Target platform option, "my_board", which needs to remove those same build files. I tried adding an elseif(NOT ${TARGET_PLATFORM} STREQUAL "my_board") following the first IF, but that was not successful.

Is what I am trying to do possible with CMake, and if so, what is the proper syntax?

Thanks

like image 309
joshua.kurland Avatar asked Oct 02 '13 18:10

joshua.kurland


People also ask

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.

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 is CMake target?

A CMake-based buildsystem is organized as a set of high-level logical targets. Each target corresponds to an executable or library, or is a custom target containing custom commands.


1 Answers

if (NOT (${TARGET_PLATFORM} STREQUAL "test" OR ${TARGET_PLATFORM} STREQUAL "my_board")) 

or more simply

if (CONDITION1 OR CONDITION2) 
like image 199
Chris Maes Avatar answered Sep 29 '22 02:09

Chris Maes