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?
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
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