From 19f0a3016066be1e5bc15c10d5d681f529acc088 Mon Sep 17 00:00:00 2001 From: BtbN Date: Tue, 28 Jan 2014 08:43:59 +0100 Subject: [PATCH 1/3] Include $ORIGIN in portable mode on unix --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 592ba5f57e2e07..3f1796bd509760 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,9 +47,11 @@ endif() if(APPLE) set(CMAKE_MACOSX_RPATH TRUE) - set(CMAKE_INSTALL_RPATH - "${CMAKE_INSTALL_RPATH};@loader_path/;@executable_path/") set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) + list(APPEND CMAKE_INSTALL_RPATH "@loader_path/" "@executable_path/") +elseif(UNIX AND NOT UNIX_STRUCTURE) + set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) + list(APPEND CMAKE_INSTALL_RPATH "$ORIGIN") endif() if(NOT INSTALLER_RUN) From 074f9627b7adfdb47401996ed3b7affc2d069861 Mon Sep 17 00:00:00 2001 From: BtbN Date: Tue, 28 Jan 2014 11:39:43 +0100 Subject: [PATCH 2/3] 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 afe1c4149ace32..4f5f8bed364a7a 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 67d75be9a4f83e..62ba025c3de0eb 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 f95f46226364b0..e43da855d5d26b 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 cdd6641abe1f12..ce58dd6f1b2a82 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 d905af48d298f2..4e2fc447c3b3d4 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}) From b4d31f4e56515b7caf07055c83da04f21725b9df Mon Sep 17 00:00:00 2001 From: BtbN Date: Tue, 28 Jan 2014 15:43:41 +0100 Subject: [PATCH 3/3] Change library search order to match include search order --- cmake/Modules/FindLibavcodec.cmake | 2 +- cmake/Modules/FindLibavformat.cmake | 2 +- cmake/Modules/FindLibavutil.cmake | 2 +- cmake/Modules/FindLibswresample.cmake | 2 +- cmake/Modules/FindLibx264.cmake | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmake/Modules/FindLibavcodec.cmake b/cmake/Modules/FindLibavcodec.cmake index 5f1589b05886e4..d2297f432c6bed 100644 --- a/cmake/Modules/FindLibavcodec.cmake +++ b/cmake/Modules/FindLibavcodec.cmake @@ -29,7 +29,7 @@ else() find_library(AVCODEC_LIB NAMES avcodec - HINTS ${_AVCODEC_LIBRARY_DIRS} ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} /usr/lib /usr/local/lib /opt/local/lib /sw/lib) + HINTS ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} ${_AVCODEC_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib) set(Libavcodec_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libavcodec include dir") set(Libavcodec_LIBRARIES ${AVCODEC_LIB} CACHE STRING "Libavcodec libraries") diff --git a/cmake/Modules/FindLibavformat.cmake b/cmake/Modules/FindLibavformat.cmake index 791401e918d4cf..2d3686b76c1e7b 100644 --- a/cmake/Modules/FindLibavformat.cmake +++ b/cmake/Modules/FindLibavformat.cmake @@ -29,7 +29,7 @@ else() find_library(AVFORMAT_LIB NAMES avformat - HINTS ${_AVFORMAT_LIBRARY_DIRS} ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} /usr/lib /usr/local/lib /opt/local/lib /sw/lib) + HINTS ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} ${_AVFORMAT_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib) set(Libavformat_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libavformat include dir") set(Libavformat_LIBRARIES ${AVFORMAT_LIB} CACHE STRING "Libavformat libraries") diff --git a/cmake/Modules/FindLibavutil.cmake b/cmake/Modules/FindLibavutil.cmake index 29b760f8f3434f..c0c01f7c605ac1 100644 --- a/cmake/Modules/FindLibavutil.cmake +++ b/cmake/Modules/FindLibavutil.cmake @@ -29,7 +29,7 @@ else() find_library(AVUTIL_LIB NAMES avutil - HINTS ${_AVUTIL_LIBRARY_DIRS} ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} /usr/lib /usr/local/lib /opt/local/lib /sw/lib) + HINTS ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} ${_AVUTIL_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib) set(Libavutil_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libavutil include dir") set(Libavutil_LIBRARIES ${AVUTIL_LIB} CACHE STRING "Libavutil libraries") diff --git a/cmake/Modules/FindLibswresample.cmake b/cmake/Modules/FindLibswresample.cmake index 8f87f7e12b150c..b402effd000243 100644 --- a/cmake/Modules/FindLibswresample.cmake +++ b/cmake/Modules/FindLibswresample.cmake @@ -29,7 +29,7 @@ else() find_library(SWRESAMPLE_LIB NAMES swresample - HINTS ${_SWRESAMPLE_LIBRARY_DIRS} ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} /usr/lib /usr/local/lib /opt/local/lib /sw/lib) + HINTS ${FFMPEG_INCLUDE_DIR}/../lib ${FFMPEG_INCLUDE_DIR}/lib${_lib_suffix} ${_SWRESAMPLE_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib) set(Libswresample_INCLUDE_DIR ${FFMPEG_INCLUDE_DIR} CACHE PATH "Libswresample include dir") set(Libswresample_LIBRARIES ${SWRESAMPLE_LIB} CACHE STRING "Libswresample libraries") diff --git a/cmake/Modules/FindLibx264.cmake b/cmake/Modules/FindLibx264.cmake index 3ea45580691573..3fdf2de44c97d5 100644 --- a/cmake/Modules/FindLibx264.cmake +++ b/cmake/Modules/FindLibx264.cmake @@ -28,7 +28,7 @@ else() find_library(X264_LIB NAMES x264 libx264 - HINTS ${_X264_LIBRARY_DIRS} ${X264_INCLUDE_DIR}/../lib ${X264_INCLUDE_DIR}/lib${_lib_suffix} /usr/lib /usr/local/lib /opt/local/lib /sw/lib) + HINTS ${X264_INCLUDE_DIR}/../lib ${X264_INCLUDE_DIR}/lib${_lib_suffix} ${_X264_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib) set(Libx264_INCLUDE_DIR ${X264_INCLUDE_DIR} CACHE PATH "x264 include dir") set(Libx264_LIBRARIES ${X264_LIB} CACHE STRING "x264 libraries")