Skip to content

Instantly share code, notes, and snippets.

@asmaloney
Created April 19, 2020 14:13
Show Gist options
  • Save asmaloney/adcfdc185e689046e18f7b3ce7e7c5db to your computer and use it in GitHub Desktop.
Save asmaloney/adcfdc185e689046e18f7b3ce7e7c5db to your computer and use it in GitHub Desktop.
Fix rpath to brew's TBB when running a build
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