我有一个设置,我收集多个包含目录,我想设置为包含目录,就像在这个模拟中一样:
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}>
)
现在的问题是以下
get_target_property(debug testlib INTERFACE_INCLUDE_DIRECTORIES)
message("${debug}")
打印
/home/user/test-proj/$<BUILD_INTERFACE:/some/dir;/some/other/dir>
其中项目的绝对路径由于某种原因预先包含在include目录中。这导致cmake在某个地方宣布:
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.
我可以以某种方式使用$<BUILD_INTERFACE>
的列表吗?
答案 0 :(得分:4)
@Florian在评论中写道,确实将$<BUILD_INTERFACE:>
放在引号中就可以了:
target_include_directories(testlib PUBLIC
"$<BUILD_INTERFACE:${includePath}>"
)
原因是includePath
是一个列表,因此包含;
,cmake不喜欢在字符串外面。