# Check IMPORTED libraries SONAME ?

**URL:** <https://discourse.cmake.org/t/check-imported-libraries-soname/13177>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [December 11, 2024, 9:06am UTC](https://discourse.cmake.org/t/check-imported-libraries-soname/13177 "2024-12-11T09:06:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mblanchard](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ee59a6/32.png) [@mblanchard](https://discourse.cmake.org/u/mblanchard)\
**Post date:** [December 11, 2024, 9:06am UTC](https://discourse.cmake.org/t/check-imported-libraries-soname/13177/1 "2024-12-11T09:06:00Z")

</div>

On `UNIX` platforms, the `install(IMPORTED_RUNTIME_ARTIFACTS)` relies on the `IMPORTED` library `SONAME` for proper file detection (see [this comment](https://gitlab.kitware.com/cmake/cmake/-/issues/23249#note_1147163)). 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](https://discourse.cmake.org/t/allow-export-of-imported-libraries/13088/4)…

Anybody tried that before? Any help or idea welcomed…

> **Simple CMake test snippet**
>
> ```auto
> 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}>"
> 
> )
> 
> ```
