From cc0c1874817406ca0808471665981642aa3c4f6f Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Tue, 9 Dec 2025 18:49:16 -0800 Subject: [PATCH] Improve macOS app build process and bundle handling. - Updated `make-app-release` script to use `macdeployqt` with proper verbosity and bundle fixup. - Introduced post-build fixup using CMake's `BundleUtilities` to internalize non-Qt dylibs. - Enhanced macOS bundle RPATH settings for accurate Framework resolution. - Added optional `kge_fixup_bundle` CMake target for post-build handling. - Refined `default.nix` to load Nixpkgs in a default argument. --- CMakeLists.txt | 23 ++++++++++++++++++++++- default.nix | 3 ++- make-app-release | 10 +++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6559ba9..071008e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -379,12 +379,18 @@ if (${BUILD_GUI}) ${CMAKE_CURRENT_BINARY_DIR}/kge-Info.plist @ONLY) + # Ensure proper macOS bundle properties and RPATH so our bundled + # frameworks are preferred over system/Homebrew ones. set_target_properties(kge PROPERTIES MACOSX_BUNDLE TRUE MACOSX_BUNDLE_GUI_IDENTIFIER ${KGE_BUNDLE_ID} MACOSX_BUNDLE_BUNDLE_NAME "kge" MACOSX_BUNDLE_ICON_FILE ${MACOSX_BUNDLE_ICON_FILE} - MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/kge-Info.plist") + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/kge-Info.plist" + # Prefer the app's bundled frameworks at runtime + INSTALL_RPATH "@executable_path/../Frameworks" + BUILD_WITH_INSTALL_RPATH TRUE + ) add_dependencies(kge kte) add_custom_command(TARGET kge POST_BUILD @@ -408,4 +414,19 @@ if (${BUILD_GUI}) # Install kge man page only when GUI is built install(FILES docs/kge.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) install(FILES kge.png DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons) + + # Optional post-build bundle fixup (can also be run from scripts). + # This provides a CMake target to run BundleUtilities' fixup_bundle on the + # built app, useful after macdeployqt to ensure non-Qt dylibs are internalized. + if (APPLE) + include(CMakeParseArguments) + add_custom_target(kge_fixup_bundle ALL + COMMAND ${CMAKE_COMMAND} + -DAPP_BUNDLE=$ + -P ${CMAKE_CURRENT_LIST_DIR}/cmake/fix_bundle.cmake + BYPRODUCTS $/Contents/Frameworks + COMMENT "Running fixup_bundle on kge.app to internalize non-Qt dylibs" + VERBATIM) + add_dependencies(kge_fixup_bundle kge) + endif () endif () diff --git a/default.nix b/default.nix index 0568334..6357d11 100644 --- a/default.nix +++ b/default.nix @@ -1,5 +1,6 @@ { - lib, + pkgs ? import {}, + lib ? pkgs.lib, stdenv, cmake, ncurses, diff --git a/make-app-release b/make-app-release index a3b2813..454b50b 100755 --- a/make-app-release +++ b/make-app-release @@ -16,14 +16,18 @@ open . cd .. mkdir -p cmake-build-release-qt -cmake -S . -B cmake-build-release -DBUILD_GUI=ON -DCMAKE_BUILD_TYPE=Release -DENABLE_ASAN=OFF +cmake -S . -B cmake-build-release-qt -DBUILD_GUI=ON -DKTE_USE_QT=ON -DCMAKE_BUILD_TYPE=Release -DENABLE_ASAN=OFF cd cmake-build-release-qt make clean rm -fr kge.app* kge-qt.app* make -mv kge.app kge-qt.app -macdeployqt kge-qt.app -always-overwrite +mv -f kge.app kge-qt.app +# Use the same Qt's macdeployqt as used for building; ensure it overwrites in-bundle paths +macdeployqt kge-qt.app -always-overwrite -verbose=3 + +# Run CMake BundleUtilities fixup to internalize non-Qt dylibs and rewrite install names +cmake -DAPP_BUNDLE="$(pwd)/kge-qt.app" -P "${PWD%/*}/cmake/fix_bundle.cmake" zip -r kge-qt.app.zip kge-qt.app sha256sum kge-qt.app.zip open .