Missing libraries after install() (when cmake is used)
oneTBB (from yum repo):
phprus@phprus:~> ls -l /opt/intel/oneapi/tbb/latest
lrwxrwxrwx 1 root root 8 Jan 16 13:16 /opt/intel/oneapi/tbb/latest -> 2021.8.0
CMake:
...
set(TBB_ROOT "/opt/intel/oneapi/tbb/latest")
find_package(TBB 2021 REQUIRED COMPONENTS tbb tbbmalloc tbbmalloc_proxy)
install(IMPORTED_RUNTIME_ARTIFACTS ${TBB_IMPORTED_TARGETS}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
...
cmake install:
phprus@phprus:~/.../build/gcc10-Release> cmake --install . --config Release
...
-- Installing: /.../lib64/libtbb.so.12
-- Installing: /.../lib64/libtbbmalloc.so.2
-- Installing: /.../lib64/libtbbmalloc_proxy.so.2
...
Show installed files:
phprus@phprus:~/.../lib64> ls -l
lrwxrwxrwx 1 phprus users 25 Mar 22 11:27 libtbbmalloc_proxy.so.2 -> libtbbmalloc_proxy.so.2.8
lrwxrwxrwx 1 phprus users 19 Mar 22 11:27 libtbbmalloc.so.2 -> libtbbmalloc.so.2.8
lrwxrwxrwx 1 phprus users 14 Mar 22 11:27 libtbb.so.12 -> libtbb.so.12.8
libtbbmalloc_proxy.so.2.8, libtbbmalloc.so.2.8, libtbb.so.12.8 is missing.
Fix:
Use IMPORTED_SONAME_<CONFIG> for libtbb.so.12 (filename only) and IMPORTED_LOCATION_<CONFIG> for full path to libtbb.so.12.8 (https://cmake.org/cmake/help/latest/command/add_library.html#id5).
And similarly for libtbbmalloc_proxy.so.2.8, libtbbmalloc.so.2.8.
After these changes install(IMPORTED_RUNTIME_ARTIFACTS will work fine (https://cmake.org/cmake/help/latest/command/install.html#imported-runtime-artifacts).
I tested only oneTBB from yum repository.
+1 for using IMPORTED_SONAME_<CONFIG>, the fact that it is missing from the cmake.config of prebuilt TBB releases also may impact the runtime usage on MacOSX.
When missing, CMake won't generate -Wl,-rpath,/opt/alg/oneTBB-2022.3.0-cpp20-arm64/lib when linking against TBB::tbb , and for reason I don't fully grasp, this will lead in a crash EXC_BAD_ACCESS in libtbb.12.17.dylib tbb::detail::r1::governor::release_resources() at the exit of an empty program (I reproduced with just an executable builded with CMake+Ninja, linked to TBB::tbb and just containing int main() { return 0; }
This is the diff I made in the config.cmake and it works fine :
if (EXISTS "${_tbb_release_dll}")
+ get_filename_component(_tbb_filename "${_tbb_release_dll}" NAME)
set_target_properties(TBB::${_tbb_component} PROPERTIES
IMPORTED_LOCATION_RELEASE "${_tbb_release_dll}")
set_property(TARGET TBB::${_tbb_component} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
+ set_property(TARGET TBB::${_tbb_component} APPEND PROPERTY IMPORTED_SONAME_RELEASE "@rpath/${_tbb_filename}")
endif()
[...]
# same thing for debug