summaryrefslogtreecommitdiff
path: root/cmake/macos/fixup_bundle.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/macos/fixup_bundle.cmake')
-rw-r--r--cmake/macos/fixup_bundle.cmake31
1 files changed, 31 insertions, 0 deletions
diff --git a/cmake/macos/fixup_bundle.cmake b/cmake/macos/fixup_bundle.cmake
new file mode 100644
index 000000000..10b82d939
--- /dev/null
+++ b/cmake/macos/fixup_bundle.cmake
@@ -0,0 +1,31 @@
+# Run at build time (cmake -P) to copy non-system dylibs the executable links
+# against into the .app's Contents/Frameworks and rewrite the load paths, making
+# the bundle self-contained / portable. Invoked from apple_bundle.cmake.
+#
+# Expects -D APP_BUNDLE=<abs path to SpaghettiKart.app> -D EXECUTABLE_NAME=SpaghettiKart
+
+include(BundleUtilities)
+
+set(APP "${APP_BUNDLE}/Contents/MacOS/${EXECUTABLE_NAME}")
+file(REAL_PATH "${APP}" APP)
+
+# Where fixup_bundle should look for the dependencies it needs to copy in.
+set(SEARCH_DIRS
+ "/opt/homebrew/lib" # Homebrew (Apple Silicon)
+ "/usr/local/lib" # Homebrew (Intel) / misc
+ "/opt/local/lib" # MacPorts
+ "${APP_BUNDLE}/Contents/Frameworks"
+)
+
+set(RESOLVED_DIRS "")
+foreach(DIR IN LISTS SEARCH_DIRS)
+ if (EXISTS "${DIR}")
+ file(REAL_PATH "${DIR}" RESOLVED_DIR)
+ list(APPEND RESOLVED_DIRS "${RESOLVED_DIR}")
+ endif()
+endforeach()
+
+message(STATUS "fixup_bundle: ${APP}")
+message(STATUS "fixup_bundle search dirs: ${RESOLVED_DIRS}")
+
+fixup_bundle("${APP}" "" "${RESOLVED_DIRS}")