CMake incorrectly prefixes *.a on link line with -Wl,-Bdynamic for IMPORTED UNKNOWN targets
Description
It seems that at least on the ATS1 platform that CMake 3.23.2 will take an IMPORTED UNKNOWN
target like:
add_library(BinUtils::iberty IMPORTED UNKNOWN GLOBAL)
set_target_properties(BinUtils::iberty PROPERTIES
IMPORTED_LOCATION "/usr/lib64/libiberty.a")
and put that on the link line like:
-Wl,-Bdynamic /usr/lib64/libiberty.a
(And this is a static build with BUILD_SHARED_LIBS=OFF
.)
This causes link-time errors for at least one platform (the DOE ATS1 platform).
The workaround is to look for the *.a
extension and change this to:
add_library(BinUtils::iberty IMPORTED STATIC GLOBAL)
set_target_properties(BinUtils::iberty PROPERTIES
IMPORTED_LOCATION "/usr/lib64/libiberty.a")
when generating that imported target given a list of genetic link line (and translating that into imported targets). This results in putting this on the link line undecorated as:
/usr/lib64/libiberty.a
as it should which fixes the link errors.
For more details, see Trilinos GitHub Issue #10774 and TriBITS GitHub PR #504 for more details.