On UNIX
platforms, the install(IMPORTED_RUNTIME_ARTIFACTS)
relies on the IMPORTED
library SONAME
for proper file detection (see this comment). And because the IMPORTED
libraries SONAME
may not be set or may not match the actual filenames on disk, IMPORTED
libraries have two properties that one can set to teach CMake doing the right thing: IMPORTED_SONAME
& IMPORTED_NO_SONAME
.
So you can somehow “fix” broken SONAME
if you known they are missing or broken. In my case (projet with +100 third-party IMPORTED
libraries) manually checking for SONAME
s when introducing or updating a third-party is not really an option and I’m trying to setup a configure-time or build-time check that would make sure every IMPORTED
libraries do have SONAME
set.
This have been proven more difficult than I was initially expecting (but I may have miss something of course). My best idea so far has been to declare a build-time add_custom_target()
target checking for $<TARGET_SONAME_IMPORT_FILE_NAME>
genex value. Seems like that value is always empty though… I believe this means the value has not (yet?) been computed at generation-time. Looking at the CMake code, I thought that exporting the IMPORTED
target with export(TARGETS)
would force CMake reading that SONAME
, but exporting IMPORTED
targets is not an option…
Anybody tried that before? Any help or idea welcomed…
Simple CMake test snippet
set(boost_target TPL::BOOST::boost_filesystem)
find_library(boost_library_path
NAMES
boost_filesystem
PATHS
"${BOOST_DIR}"
NO_DEFAULT_PATH NO_CACHE
REQUIRED
)
add_library(${boost_target} SHARED IMPORTED GLOBAL)
set_target_properties(${boost_target}
PROPERTIES
IMPORTED_LOCATION "${boost_library_path}"
)
string(MAKE_C_IDENTIFIER
${boost_target}::check boost_check_target)
add_custom_target(${boost_check_target} ALL
COMMAND
"${CMAKE_COMMAND}" "-E" "echo"
"$TARGET_SONAME_IMPORT_FILE_NAME=$<TARGET_SONAME_IMPORT_FILE_NAME:${boost_target}>"
)