Created
April 19, 2020 14:13
-
-
Save asmaloney/adcfdc185e689046e18f7b3ce7e7c5db to your computer and use it in GitHub Desktop.
Fix rpath to brew's TBB when running a build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( APPLE ) | |
option( FIX_TBB_RPATH | |
"Fix rpath to brew's TBB when running a build (see comment in CMakeLists.txt)" | |
ON | |
) | |
# The problem: | |
# When installed with homebrew, the TBB library libtbbmalloc_proxy.dylib | |
# includes an RPATH to libtbbmalloc.dylib. When you build & run your | |
# application, it might not be able to find this library and you end up | |
# with an error: | |
# | |
# dyld: Library not loaded: @rpath/libtbbmalloc.dylib | |
# | |
# You can try to solve this by setting DYLD_LIBRARY_PATH (& friends), but | |
# you often end up with conflicts between brew libs and the system ones. | |
# | |
# A solution: | |
# Find the path to the installed libtbbmalloc_proxy.dylib. Then in a | |
# post-build step, add the rpath to <target> so the libtbbmalloc.dylib | |
# library can be found when running the application. | |
# | |
# This is not an ideal solution, but I can't find another way around that rpath | |
# built into the TBB library. None of the RPATH cmake options seems to work. | |
if ( FIX_TBB_RPATH ) | |
get_target_property( | |
TBB_LOCATION | |
TBB::tbbmalloc_proxy | |
IMPORTED_LOCATION_RELEASE | |
) | |
get_filename_component( | |
TBB_LIB_LOCATION | |
"${TBB_LOCATION}" | |
DIRECTORY | |
) | |
add_custom_command( | |
TARGET | |
${MY_TARGET} | |
POST_BUILD COMMAND | |
${CMAKE_INSTALL_NAME_TOOL} -add_rpath "${TBB_LIB_LOCATION}" | |
$<TARGET_FILE:${MY_TARGET}>) | |
endif() | |
endif() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment