Improve bundle fixup

This commit is contained in:
BtbN
2014-04-13 11:05:46 -07:00
parent 2451b80ef6
commit 075820028f
8 changed files with 62 additions and 30 deletions

View File

@@ -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}" "$<TARGET_FILE:${target}>"
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)

View File

@@ -0,0 +1,3 @@
obs_finish_bundle()

51
cmake/osxbundle/fixup_bundle.sh Executable file
View File

@@ -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