aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorNadia Holmquist Pedersen <nadia@nhp.sh>2021-04-21 23:50:32 +0200
committerGitHub <noreply@github.com>2021-04-21 23:50:32 +0200
commit796ef958629ec71ad7d0c30c15c4e38b0bba7149 (patch)
tree1efe2d8d89d72aeed3f8b3012fea93a7244c205b /tools
parent06e2193c04083bc6395bb420c56d9e7f2c3b9863 (diff)
Improve macOS bundling (#1067)
* Improve macOS bundling * Bundle libs for macOS CI * Add MACOS_BUILD_DMG CMake option and make the CI upload the DMG so we don't lose executable permissions. * Manually copy plugins if macdeployqt doesn't * Ad-hoc codesign the app
Diffstat (limited to 'tools')
-rwxr-xr-xtools/mac-libs.sh68
-rwxr-xr-xtools/msys-dist.sh15
2 files changed, 83 insertions, 0 deletions
diff --git a/tools/mac-libs.sh b/tools/mac-libs.sh
new file mode 100755
index 0000000..1766cf7
--- /dev/null
+++ b/tools/mac-libs.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+
+set -o errexit
+set -o pipefail
+
+build_dmg=0
+app=melonDS.app
+
+if [[ "$1" == "--dmg" ]]; then
+ build_dmg=1
+ shift
+fi
+
+if [[ ! -d "$1" ]]; then
+ echo "Usage: $0 [--dmg] <build-dir>"
+ exit 1
+fi
+
+cd "$1"
+
+# macOS does not have the -f flag for readlink
+abspath() {
+ perl -MCwd -le 'print Cwd::abs_path shift' "$1"
+}
+
+cmake_qtdir=$(grep -E "Qt._DIR" CMakeCache.txt | cut -d= -f2)
+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"
+if [[ ! -d "$plugindir" ]]; then
+ mkdir -p "$plugindir/styles" "$plugindir/platforms"
+ cp "$qtdir/share/qt/plugins/styles/libqmacstyle.dylib" "$plugindir/styles/"
+ cp "$qtdir/share/qt/plugins/platforms/libqcocoa.dylib" "$plugindir/platforms/"
+
+ install_name_tool -add_rpath "@executable_path/../Frameworks" "$app/Contents/MacOS/melonDS"
+fi
+
+# Fix library load paths that macdeployqt forgot about
+fixup_libs() {
+ local libs=($(otool -L "$1" | sed -E 's/\t(.*) \(.*$/\1/' | grep -vE '/System|/usr/lib|\.framework|^\@|:$'))
+
+ for lib in "${libs[@]}"; do
+ local base="$(basename "$lib")"
+ install_name_tool -change "$lib" "@executable_path/../Frameworks/$base" "$1"
+ done
+}
+
+find "$app/Contents/Frameworks" -maxdepth 1 -name '*.dylib' | while read lib; do
+ fixup_libs "$lib"
+done
+
+fixup_libs "$app/Contents/MacOS/melonDS"
+codesign -s - --deep "$app"
+
+if [[ $build_dmg == 1 ]]; then
+ mkdir dmg
+ cp -r "$app" dmg/
+ ln -s /Applications dmg/Applications
+ hdiutil create -volname melonDS -srcfolder dmg -ov -format UDZO melonDS.dmg
+ rm -r dmg
+fi
diff --git a/tools/msys-dist.sh b/tools/msys-dist.sh
new file mode 100755
index 0000000..d95a6d3
--- /dev/null
+++ b/tools/msys-dist.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+if [[ ! -x melonDS.exe ]]; then
+ echo "Run this script from the directory you built melonDS."
+ exit 1
+fi
+
+mkdir -p dist
+
+for lib in $(ldd melonDS.exe | grep mingw | sed "s/.*=> //" | sed "s/(.*)//"); do
+ cp "${lib}" dist
+done
+
+cp melonDS.exe dist
+windeployqt dist