Handling the installation of external dependencies

Hi all,

I’m trying to get my project, which has a non-CMake-target dependency, to link its dependency publically:

target_link_libraries(MyLibrary
    PUBLIC
         $<BUILD_INTERFACE:${MyDependency}>
         $<INSTALL_INTERFACE:lib/libMyDependency.so>
)

This builds and links MyLibrary without issue, but MyLibrary.config comes out wrong:

set_target_properties(MyPackage::MyLibrary PROPERTIES
     ...
     INTERFACE_LINK_LIBRARIES "MyPackage::MyCMakeDependency;lib/libMyDependency.so"
     ...
)

I would’ve expected lib/libMyDependency.so to be prefixed with ${_IMPORT_PREFIX} in the same way that my interface include directories are. Any thoughts on what I’m doing wrong here?

Thanks!

That wouldn’t work because if a string such as "dl" shows up, that should not get ${_IMPORT_PREFIX} on it. I would recommend making a target and exporting it:

# in build
add_library(external UNKNOWN IMPORTED)
set_target_properties(external PROPERTIES
  IMPORTED_LOCATION "$<BUILD_INTERFACE:${MyDependency}>$<INSTALL_INTERFACE:…>")

I don’t know how easy it is to get ${_IMPORT_PREFIX} as you need it in that property though.