Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMAKE string comparison fails

Tags:

cmake

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?

like image 907
user4168715 Avatar asked Mar 18 '16 15:03

user4168715


Video Answer


1 Answers

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

  • cmake: when to quote variables?
like image 148
Florian Avatar answered Sep 26 '22 22:09

Florian