From 074f9627b7adfdb47401996ed3b7affc2d069861 Mon Sep 17 00:00:00 2001 From: BtbN Date: Tue, 28 Jan 2014 11:39:43 +0100 Subject: [PATCH] Fixup OSX Rpath for imported external libraries on install --- cmake/Modules/ObsHelpers.cmake | 30 +++++++++++++++++++++++++++++- libobs/CMakeLists.txt | 2 ++ obs/CMakeLists.txt | 4 ++++ plugins/obs-ffmpeg/CMakeLists.txt | 3 +++ plugins/obs-outputs/CMakeLists.txt | 2 ++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/ObsHelpers.cmake b/cmake/Modules/ObsHelpers.cmake index afe1c4149..4f5f8bed3 100644 --- a/cmake/Modules/ObsHelpers.cmake +++ b/cmake/Modules/ObsHelpers.cmake @@ -14,6 +14,9 @@ endif() option(INSTALLER_RUN "Build a multiarch installer, needs to run indenepdently after both archs have compiled" FALSE) option(UNIX_STRUCTURE "Build with standard unix filesystem structure" ${_struct_def}) +if(APPLE) + option(BUILD_REDISTRIBUTABLE "Fix rpath of external libraries" FALSE) +endif() if(INSTALLER_RUN AND NOT DEFINED ENV{obsInstallerTempDir}) message(FATAL_ERROR "Environment variable obsInstallerTempDir is needed for multiarch installer generation") @@ -67,6 +70,31 @@ else() add_definitions(-DOBS_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}/") endif() +function(obs_fixup_install_target target type) + if(NOT APPLE OR NOT BUILD_REDISTRIBUTABLE) + return() + endif() + + foreach(data ${ARGN}) + if(type STREQUAL "TARGET") + get_property(fullpath TARGET "${data}" PROPERTY LOCATION) + else() + set(fullpath "${data}") + endif() + + execute_process(COMMAND otool -D "${fullpath}" OUTPUT_VARIABLE otool_out) + string(REGEX REPLACE "(\r?\n)+$" "" otool_out "${otool_out}") + string(REGEX REPLACE ".*\n" "" otool_out "${otool_out}") + + string(REGEX REPLACE ".*/" "@rpath/" newpath "${otool_out}") + + add_custom_command(TARGET ${target} POST_BUILD + COMMAND + install_name_tool -change "${otool_out}" "${newpath}" "$" + VERBATIM) + endforeach() +endfunction() + function(obs_generate_multiarch_installer) install(DIRECTORY "$ENV{obsInstallerTempDir}/" DESTINATION "." @@ -143,9 +171,9 @@ macro(install_obs_core target) "${OBS_OUTPUT_DIR}/$/bin/${_bit_suffix}$" VERBATIM) + if(DEFINED ENV{obsInstallerTempDir}) get_property(target_type TARGET ${target} PROPERTY TYPE) - if("${target_type}" STREQUAL "EXECUTABLE") set(tmp_target_dir "${OBS_EXECUTABLE_DESTINATION}") else() diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt index 67d75be9a..62ba025c3 100644 --- a/libobs/CMakeLists.txt +++ b/libobs/CMakeLists.txt @@ -192,3 +192,5 @@ target_link_libraries(libobs install_obs_core(libobs) install_obs_data(libobs ../build/data/libobs libobs) + +obs_fixup_install_target(libobs PATH ${Libswresample_LIBRARIES} ${Libavutil_LIBRARIES}) diff --git a/obs/CMakeLists.txt b/obs/CMakeLists.txt index f95f46226..e43da855d 100644 --- a/obs/CMakeLists.txt +++ b/obs/CMakeLists.txt @@ -93,3 +93,7 @@ target_link_libraries(obs install_obs_core(obs) install_obs_data(obs ../build/data/obs-studio obs-studio) + +obs_fixup_install_target(obs TARGET Qt5::Widgets) +obs_fixup_install_target(obs TARGET Qt5::Gui) +obs_fixup_install_target(obs TARGET Qt5::Core) diff --git a/plugins/obs-ffmpeg/CMakeLists.txt b/plugins/obs-ffmpeg/CMakeLists.txt index cdd6641ab..ce58dd6f1 100644 --- a/plugins/obs-ffmpeg/CMakeLists.txt +++ b/plugins/obs-ffmpeg/CMakeLists.txt @@ -24,3 +24,6 @@ target_link_libraries(obs-ffmpeg ${Libswresample_LIBRARIES}) install_obs_plugin(obs-ffmpeg) + +obs_fixup_install_target(obs-ffmpeg PATH ${Libavformat_LIBRARIES}) +obs_fixup_install_target(obs-ffmpeg PATH ${Libswresample_LIBRARIES}) diff --git a/plugins/obs-outputs/CMakeLists.txt b/plugins/obs-outputs/CMakeLists.txt index d905af48d..4e2fc447c 100644 --- a/plugins/obs-outputs/CMakeLists.txt +++ b/plugins/obs-outputs/CMakeLists.txt @@ -21,3 +21,5 @@ target_link_libraries(obs-outputs ${Libx264_LIBRARIES}) install_obs_plugin(obs-outputs) + +obs_fixup_install_target(obs-outputs PATH ${Libx264_LIBRARIES})