$<INSTALL_INTERFACE:...> generator expression not expanded for target_link_libraries of interface when using install(EXPORT)
Using: CMake 3.9.1 / Linux
I somewhat "mis-use" an INTERFACE library to create and install a Config file for a target that is not build with CMake. In order to make the library relocatable I use the $<INSTALL_INTERFACE:...>
generator expression:
add_library(tool_shared INTERFACE)
target_compile_options(tool_shared INTERFACE "-std=c++11")
target_include_directories(tool_shared INTERFACE "$<INSTALL_INTERFACE:include>")
target_link_libraries(tool_shared INTERFACE"$<INSTALL_INTERFACE:lib/dummy.so>")
[... install actual files (headers, dummy.so) ...]
set_target_properties(tool_shared PROPERTIES EXPORT_NAME Shared)
install( TARGETS tool_shared EXPORT ToolTargets )
install( EXPORT ToolTargets FILE ToolTargets.cmake NAMESPACE Tool:: DESTINATION "lib/cmake/tool")
Unfortunately, in the ToolTargets.cmake
, this is resolved to ${_IMPORT_PREFIX}
only for the INTERFACE_INCLUDE_DIRECTORIES
and not for the INTERFACE_LINK_LIBRARIES
:
# Create imported target Tool::Shared
add_library(Tool::Shared INTERFACE IMPORTED)
set_target_properties(Tool::Shared PROPERTIES
INTERFACE_COMPILE_OPTIONS "-std=c++11"
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
INTERFACE_LINK_LIBRARIES "lib/dummy.so"
)
I already found the reason for this in cmExportFileGenerator.xxx
line 176 where the cmGeneratorExpression::Preprocess
is called without the last boolean argument resolveRelative
that is then set to false.
My question: Is that intended? Is there a better way to use install(EXPORT)
for a library that is build externally (e.g. with external project). Imported targets cannot be installed as far as I understood so the interface target workaround is the only solution I found so far.
Sorry for posting that as an issue (if it should be intended behavior). Please feel free to move that to some more appropriate list.
Christian