diff --git a/cmake/Modules/ObsHelpers.cmake b/cmake/Modules/ObsHelpers.cmake index afe1c4149ace3222c120e5a6d11f683663201a6d..4f5f8bed364a7a94d5d444d0ad880f3d44cc426a 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}" "$<TARGET_FILE:${target}>" + 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}/$<CONFIGURATION>/bin/${_bit_suffix}$<TARGET_FILE_NAME:${target}>" 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 67d75be9a4f83e52235421504070bbfcd4a42e60..62ba025c3de0eb3db761c42af0c4525be253854c 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 f95f46226364b0993a8454772acc8d3089526e68..e43da855d5d26b9b09efe351749a8ea81487bda8 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 cdd6641abe1f12205c291bff478eafd0c95e4593..ce58dd6f1b2a828d8d5f1f32699cbeef31c91808 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 d905af48d298f27008816f468e40eec45479f278..4e2fc447c3b3d4275cbc06bec32ae3039ce2ad55 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})