From 075820028f49ed8b11f1de31155df2208f4989f9 Mon Sep 17 00:00:00 2001 From: BtbN Date: Sun, 13 Apr 2014 11:05:46 -0700 Subject: [PATCH 1/2] Improve bundle fixup --- CMakeLists.txt | 2 ++ cmake/Modules/ObsHelpers.cmake | 26 ++++----------- cmake/helper_subdir/CMakeLists.txt | 3 ++ cmake/osxbundle/fixup_bundle.sh | 51 ++++++++++++++++++++++++++++++ libobs/CMakeLists.txt | 1 - obs/CMakeLists.txt | 3 -- plugins/obs-ffmpeg/CMakeLists.txt | 5 --- plugins/obs-x264/CMakeLists.txt | 1 - 8 files changed, 62 insertions(+), 30 deletions(-) create mode 100644 cmake/helper_subdir/CMakeLists.txt create mode 100755 cmake/osxbundle/fixup_bundle.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 400245ec1..23ef38083 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,6 +76,8 @@ if(NOT INSTALLER_RUN) add_subdirectory(obs) add_subdirectory(plugins) add_subdirectory(test) + + add_subdirectory(cmake/helper_subdir) else() obs_generate_multiarch_installer() endif() diff --git a/cmake/Modules/ObsHelpers.cmake b/cmake/Modules/ObsHelpers.cmake index a8449706c..0fe2d9f70 100644 --- a/cmake/Modules/ObsHelpers.cmake +++ b/cmake/Modules/ObsHelpers.cmake @@ -70,29 +70,15 @@ else() add_definitions(-DOBS_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}/") endif() -function(obs_fixup_install_target target type) - if(NOT APPLE OR NOT BUILD_REDISTRIBUTABLE) +function(obs_finish_bundle) + if(NOT APPLE OR UNIX_STRUCTURE) 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() + install(CODE + "if(DEFINED ENV{FIXUP_BUNDLE}) + execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/cmake/osxbundle/fixup_bundle.sh\" . bin WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}\") + endif()") endfunction() function(obs_generate_multiarch_installer) diff --git a/cmake/helper_subdir/CMakeLists.txt b/cmake/helper_subdir/CMakeLists.txt new file mode 100644 index 000000000..d644c9f19 --- /dev/null +++ b/cmake/helper_subdir/CMakeLists.txt @@ -0,0 +1,3 @@ + +obs_finish_bundle() + diff --git a/cmake/osxbundle/fixup_bundle.sh b/cmake/osxbundle/fixup_bundle.sh new file mode 100755 index 000000000..456d339ca --- /dev/null +++ b/cmake/osxbundle/fixup_bundle.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +if [ "$#" != 2 ]; then + echo "usage: $0 /path/to/install/root relative/lib/destination" + exit 1 +fi + +cd "$1" + +function buildlist() { + otool -L "$@" | + grep -E "(opt|Users)" | + perl -pe 's|^\s+(/.*)\s\(.*$|$1|' | + grep -vE ":$" | + sort -u +} +export -f buildlist + +DEST="$2" +LDEST="@rpath" +TARGETS="$(find . \( -perm +111 -and -type f \))" +FOUNDLIBS="$(buildlist $TARGETS)" +PFOUNDLIBS="" + +while [ "$FOUNDLIBS" != "$PFOUNDLIBS" ]; do + PFOUNDLIBS="$FOUNDLIBS" + FOUNDLIBS="$(buildlist $TARGETS $PFOUNDLIBS)" +done + +INTOOL_CALL=() + +for lib in $FOUNDLIBS; do + libname="$(basename "$lib")" + + INTOOL_CALL+=(-change "$lib" "$LDEST/$libname") + cp "$lib" "$DEST/$libname" + + echo "Fixing up dependency: $libname" +done + +for lib in $FOUNDLIBS; do + libname="$(basename "$lib")" + lib="$DEST/$libname" + + install_name_tool ${INTOOL_CALL[@]} -id "$LDEST/$libname" "$lib" +done + +for target in $TARGETS; do + install_name_tool ${INTOOL_CALL[@]} "$target" +done + diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt index b536b60e5..9f4158534 100644 --- a/libobs/CMakeLists.txt +++ b/libobs/CMakeLists.txt @@ -231,4 +231,3 @@ target_link_libraries(libobs install_obs_core(libobs) install_obs_data(libobs ../build/data/libobs libobs) -obs_fixup_install_target(libobs PATH ${Libswscale_LIBRARIES} ${Libswresample_LIBRARIES} ${Libavutil_LIBRARIES}) diff --git a/obs/CMakeLists.txt b/obs/CMakeLists.txt index 1b71cb0ca..b0935c7a1 100644 --- a/obs/CMakeLists.txt +++ b/obs/CMakeLists.txt @@ -113,6 +113,3 @@ 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 a7e5c1635..e4ccf7c11 100644 --- a/plugins/obs-ffmpeg/CMakeLists.txt +++ b/plugins/obs-ffmpeg/CMakeLists.txt @@ -40,8 +40,3 @@ target_link_libraries(obs-ffmpeg install_obs_plugin(obs-ffmpeg) -obs_fixup_install_target(obs-ffmpeg PATH ${Libavcodec_LIBRARIES}) -obs_fixup_install_target(obs-ffmpeg PATH ${Libavutil_LIBRARIES}) -obs_fixup_install_target(obs-ffmpeg PATH ${Libswscale_LIBRARIES}) -obs_fixup_install_target(obs-ffmpeg PATH ${Libavformat_LIBRARIES}) -obs_fixup_install_target(obs-ffmpeg PATH ${Libswresample_LIBRARIES}) diff --git a/plugins/obs-x264/CMakeLists.txt b/plugins/obs-x264/CMakeLists.txt index c4d655a80..47f1acfba 100644 --- a/plugins/obs-x264/CMakeLists.txt +++ b/plugins/obs-x264/CMakeLists.txt @@ -16,4 +16,3 @@ target_link_libraries(obs-x264 install_obs_plugin(obs-x264) -obs_fixup_install_target(obs-x264 PATH ${Libx264_LIBRARIES}) From ce434c2d62a40eb6afeb5dc5b22efd453c6c6139 Mon Sep 17 00:00:00 2001 From: BtbN Date: Sun, 13 Apr 2014 20:57:43 +0200 Subject: [PATCH 2/2] Also disable missing field initializer warning for C --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23ef38083..14ca96568 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ endif() if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG) set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-function -Werror-implicit-function-declaration -Wno-missing-field-initializers ${CMAKE_CXX_FLAGS} -fno-strict-aliasing") - set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-function -Werror-implicit-function-declaration ${CMAKE_C_FLAGS} -std=gnu99 -fno-strict-aliasing") + set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-function -Werror-implicit-function-declaration -Wno-missing-field-initializers ${CMAKE_C_FLAGS} -std=gnu99 -fno-strict-aliasing") option(USE_LIBC++ "Use libc++ instead of libstdc++" ${APPLE}) if(USE_LIBC++)