Make Mac builds a lot smaller by avoiding macdeployqt
This commit is contained in:
parent
796ef95862
commit
9e20aa8a3e
|
@ -27,36 +27,71 @@ abspath() {
|
||||||
cmake_qtdir=$(grep -E "Qt._DIR" CMakeCache.txt | cut -d= -f2)
|
cmake_qtdir=$(grep -E "Qt._DIR" CMakeCache.txt | cut -d= -f2)
|
||||||
qtdir="$(abspath "$cmake_qtdir"/../../..)"
|
qtdir="$(abspath "$cmake_qtdir"/../../..)"
|
||||||
|
|
||||||
if [[ ! -d "$app/Contents/Frameworks" ]]; then
|
|
||||||
"${qtdir}/bin/macdeployqt" "$app"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# We'll have to copy the Qt plugins we need on our own if macdeployqt forgets
|
|
||||||
# Qt6 bug?
|
|
||||||
plugindir="$app/Contents/PlugIns"
|
plugindir="$app/Contents/PlugIns"
|
||||||
if [[ ! -d "$plugindir" ]]; then
|
if [[ ! -d "$plugindir" ]]; then
|
||||||
mkdir -p "$plugindir/styles" "$plugindir/platforms"
|
qt_plugins="$qtdir/plugins"
|
||||||
cp "$qtdir/share/qt/plugins/styles/libqmacstyle.dylib" "$plugindir/styles/"
|
if [[ ! -d "$qt_plugins" ]]; then
|
||||||
cp "$qtdir/share/qt/plugins/platforms/libqcocoa.dylib" "$plugindir/platforms/"
|
qt_plugins="$qtdir/share/qt/plugins"
|
||||||
|
fi
|
||||||
|
|
||||||
install_name_tool -add_rpath "@executable_path/../Frameworks" "$app/Contents/MacOS/melonDS"
|
mkdir -p "$plugindir/styles" "$plugindir/platforms"
|
||||||
|
cp "$qt_plugins/styles/libqmacstyle.dylib" "$plugindir/styles/"
|
||||||
|
cp "$qt_plugins/platforms/libqcocoa.dylib" "$plugindir/platforms/"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Fix library load paths that macdeployqt forgot about
|
mkdir "$app/Contents/Frameworks"
|
||||||
|
install_name_tool -add_rpath "@executable_path/../Frameworks" "$app/Contents/MacOS/melonDS"
|
||||||
|
|
||||||
fixup_libs() {
|
fixup_libs() {
|
||||||
local libs=($(otool -L "$1" | sed -E 's/\t(.*) \(.*$/\1/' | grep -vE '/System|/usr/lib|\.framework|^\@|:$'))
|
local libs=($(otool -L "$1" | grep -vE "/System|/usr/lib|:$" | sed -E 's/\t(.*) \(.*$/\1/'))
|
||||||
|
|
||||||
for lib in "${libs[@]}"; do
|
for lib in "${libs[@]}"; do
|
||||||
local base="$(basename "$lib")"
|
# Dereference symlinks to get the actual .dylib as binaries' load
|
||||||
install_name_tool -change "$lib" "@executable_path/../Frameworks/$base" "$1"
|
# commands can contain paths to symlinked libraries.
|
||||||
|
local abslib="$(abspath "$lib")"
|
||||||
|
|
||||||
|
if [[ "$abslib" == *".framework/"* ]]; then
|
||||||
|
local fwpath="$(echo "$abslib" | sed -E 's@(.*\.framework)/.*@\1/@')"
|
||||||
|
local fwlib="$(echo "$abslib" | sed -E 's/.*\.framework//')"
|
||||||
|
local fwname="$(basename "$fwpath")"
|
||||||
|
local install_path="$app/Contents/Frameworks/$fwname"
|
||||||
|
|
||||||
|
install_name_tool -change "$lib" "@rpath/$fwname/$fwlib" "$1"
|
||||||
|
|
||||||
|
if [[ ! -d "$install_path" ]]; then
|
||||||
|
cp -a "$fwpath" "$install_path"
|
||||||
|
chown -R $UID "$install_path"
|
||||||
|
chmod -R u+w "$install_path"
|
||||||
|
strip -SNTx "$install_path/$fwlib"
|
||||||
|
fixup_libs "$install_path/$fwlib"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
local base="$(basename "$abslib")"
|
||||||
|
local install_path="$app/Contents/Frameworks/$base"
|
||||||
|
|
||||||
|
install_name_tool -change "$lib" "@rpath/$base" "$1"
|
||||||
|
|
||||||
|
if [[ ! -f "$install_path" ]]; then
|
||||||
|
install -m644 "$abslib" "$install_path"
|
||||||
|
strip -SNTx "$install_path"
|
||||||
|
fixup_libs "$install_path"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
find "$app/Contents/Frameworks" -maxdepth 1 -name '*.dylib' | while read lib; do
|
|
||||||
|
fixup_libs "$app/Contents/MacOS/melonDS"
|
||||||
|
find "$app/Contents/PlugIns" -name '*.dylib' | while read lib; do
|
||||||
fixup_libs "$lib"
|
fixup_libs "$lib"
|
||||||
done
|
done
|
||||||
|
|
||||||
fixup_libs "$app/Contents/MacOS/melonDS"
|
bad_rpaths=($(otool -l "$app/Contents/MacOS/melonDS" | grep -E "^ *path (/usr/local|/opt)" | sed -E 's/^ *path (.*) \(.*/\1/'))
|
||||||
|
|
||||||
|
for path in "${bad_rpaths[@]}"; do
|
||||||
|
install_name_tool -delete_rpath "$path" "$app/Contents/MacOS/melonDS"
|
||||||
|
done
|
||||||
|
|
||||||
codesign -s - --deep "$app"
|
codesign -s - --deep "$app"
|
||||||
|
|
||||||
if [[ $build_dmg == 1 ]]; then
|
if [[ $build_dmg == 1 ]]; then
|
||||||
|
|
Loading…
Reference in New Issue