Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly use target_include_directories with lists of includes

Tags:

cmake

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

like image 757
WorldSEnder Avatar asked Jun 08 '17 01:06

WorldSEnder


1 Answers

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.

like image 95
WorldSEnder Avatar answered Nov 12 '22 04:11

WorldSEnder