user4168715
user4168715

Reputation: 179

CMAKE string comparison fails

I want to optionally add some library paths in my CMakeLists file and the way to do it to is to have a variable set as:

set(MYLIBDIR "DEFAULT")

If the user wants to specify a custom directory he will change it to:

set(MYLIBDIR /path/to/dir1
/path/to/dir2)

So in order to check if the user has indeed provided extra directories I check:

if(NOT ${MYLIBDIR} STREQUAL "DEFAULT")
 link_directories(${MYLIBDIR})
endif()

When I try to do this I am getting an error from cmake. Is there a way to concatenate all of the elements of a variable before the string comparison?

Upvotes: 12

Views: 52932

Answers (1)

Florian
Florian

Reputation: 43058

Turning my comment into an answer

Concatenating a list would simply be achieved by putting quotes around the variable reference:

if(NOT "${MYLIBDIR}" STREQUAL "DEFAULT")

would be the same as

if(NOT "/path/to/dir1;/path/to/dir2" STREQUAL "DEFAULT")

But I would recommend

if(NOT MYLIBDIR STREQUAL "DEFAULT")

For more details see

Upvotes: 39

Related Questions