0

I'm calling my CMakeLists.txt like this:

cmake ../.. -DTARGET=JETSON_NANO 

Then, this line:

message(STATUS "------------ TARGET: ${TARGET}") 

prints ------------ TARGET: JETSON_NANO

but this line:

if (TARGET STREQUAL JETSON_NANO) 

gives error:

if given arguments: "TARGET" "STREQUAL" "JETSON_NANO" 

Why? TARGET is setted!

1
  • 1
    Note, that when use string literal with STREQUAL or some other if construction, it is better to enclose this literal with double quotes: "JETSON_NANO". Otherwise, if the variable with given name exists, CMake will substitute value of the variable instead of the literal. This is, however, unrelated to your issue. Commented Sep 2, 2019 at 7:51

1 Answer 1

3

TARGET is a special keyword for if command. It is used for check whether given target (in CMake sense) exists. Correct usage of this keyword includes two arguments of if:

if(TARGET JETSON_NANO) # Checks whether CMake target JETSON_NANO exists 

This is why CMake emits error when you use this keyword with three arguments:

if (TARGET STREQUAL "JETSON_NANO") # Error: 'TARGET' keyword requires two `if` arguments 

However, you may swap compared strings in if command:

if ("JETSON_NANO" STREQUAL TARGET) # Compares string "JETSON_NANO" with variable TARGET 

See more about if command in its documentation.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.