I have a setup where I collect multiple include directories that I want to set as include directories, as in this mock up:
add_library(testlib SHARED "")
set_target_properties(testlib PROPERTIES LINKER_LANGUAGE CXX)
list(APPEND includePath "/some/dir" "/some/other/dir")
target_include_directories(testlib PUBLIC
$<BUILD_INTERFACE:${includePath}>
)
The problem now is the following
get_target_property(debug testlib INTERFACE_INCLUDE_DIRECTORIES)
message("${debug}")
prints
/home/user/test-proj/$<BUILD_INTERFACE:/some/dir;/some/other/dir>
where the absolute path to the project is for some reason prepended to the include directories. This leads to cmake proclaiming, somewhere down the line:
CMake Error in src/hypro/CMakeLists.txt:
Target "testlib" INTERFACE_INCLUDE_DIRECTORIES property contains path:
"/home/user/test-proj/"
which is prefixed in the source directory.
Can I somehow use a list with $<BUILD_INTERFACE>
?
As @Florian writes in a comment, indeed putting $<BUILD_INTERFACE:>
in quotes does the job:
target_include_directories(testlib PUBLIC
"$<BUILD_INTERFACE:${includePath}>"
)
The reason is that includePath
is a list here, and thus contains a ;
, which cmake doesn't like outside a string.
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