12

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

WorldSEnder
  • 4,875
  • 2
  • 28
  • 64
  • 1
    Which version of CMake are you using? I looks like CMake does not recognize `$` generator expression and just [prefixes the source path](https://stackoverflow.com/questions/30705284/what-is-the-difference-between-cmake-current-source-dir-and-in-include). What have you tried so far? E.g. did you try to put the generator expression in quotes? – Florian Jun 08 '17 at 07:59
  • @Florian I somehow didn't think of putting the generator expression entirely in quotes, thanks – WorldSEnder Jun 08 '17 at 08:39

1 Answers1

7

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.

WorldSEnder
  • 4,875
  • 2
  • 28
  • 64