1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-11-17 07:10:18 +01:00

Build script for self-contained Mac .app (#185)

* Add CMake settings to build universal binary and find SDL in app bundle

* Source frameworks from extern folder

* Add build script, info plist and big sur style icon

* Add example build workflow (app won't be signed)

* Use macOS 11 runner for better compatibility

* Use better name for the build script, move metadata to Platform/macOS/ folder

* Improve macOS build instructions

* Fix workflow syntax and use a more specific glob pattern too

* Add libs search paths to CMakeLists.txt instead of find files

* Use same /Libs folder as libs search path

* Make build-mac-app.sh not fail on repeated runs

* Make build-mac-app.sh executable
This commit is contained in:
Orazio 2023-08-01 08:01:56 +02:00 committed by GitHub
parent e2f3ae66f8
commit 6ab7b3e772
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 133 additions and 1 deletions

19
.github/workflows/ReleaseBuilds.yml vendored Normal file
View file

@ -0,0 +1,19 @@
name: Make Release Builds
on: [workflow_dispatch]
jobs:
build-macos:
runs-on: macos-11
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
with:
ref: master
- run: bash build-mac-app.sh
- uses: actions/upload-artifact@v3
with:
name: mac-build
path: SpaceCadetPinball-*-mac.dmg

2
.gitignore vendored
View file

@ -266,7 +266,7 @@ __pycache__/
/Export
/DrMem
/Doc private
# Windows local libraries
# Windows and macOS local libraries
/Libs
#CMake generated

View file

@ -19,6 +19,15 @@ if(MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
endif()
if(APPLE)
set(MACOSX_RPATH)
set(CMAKE_BUILD_WITH_INSTALL_RPATH true)
set(CMAKE_INSTALL_RPATH "@executable_path/../Frameworks")
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
list(APPEND SDL2_PATH "${CMAKE_CURRENT_LIST_DIR}/Libs")
list(APPEND SDL2_MIXER_PATH "${CMAKE_CURRENT_LIST_DIR}/Libs")
endif()
# SDL2main is not needed
set(SDL2_BUILDING_LIBRARY ON)

34
Platform/macOS/Info.plist Normal file
View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>SpaceCadetPinball</string>
<key>CFBundleIconFile</key>
<string>SpaceCadetPinball.icns</string>
<key>CFBundleIdentifier</key>
<string>com.github.k4zmu2a.spacecadetpinball</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string></string>
<key>CFBundleName</key>
<string>SpaceCadetPinball</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>CHANGEME_SW_VERSION</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CSResourcesFileMapped</key>
<true/>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>

Binary file not shown.

View file

@ -74,6 +74,10 @@ This project is available as Flatpak on [Flathub](https://flathub.org/apps/detai
### On macOS
Install XCode (or at least Xcode Command Line Tools with `xcode-select --install`) and CMake.
**Manual compilation:**
* **Homebrew**: Install the `SDL2`, `SDL2_mixer` homebrew packages.
* **MacPorts**: Install the `libSDL2`, `libSDL2_mixer` macports packages.
@ -81,6 +85,12 @@ Compile with CMake. Ensure that `CMAKE_OSX_ARCHITECTURES` variable is set for ei
Tested with: macOS Big Sur (Intel) with Xcode 13 & macOS Montery Beta (Apple Silicon) with Xcode 13.
**Automated compilation:**
Run the `build-mac-app.sh` script from the root of the repository. The app will be available in a DMG file named `SpaceCadetPinball-<version>-mac.dmg`.
Tested with: macOS Ventura (Apple Silicon) with Xcode Command Line Tools 14 & macOS Big Sur on GitHub Runner (Intel) with XCode 13.
## Plans
* ~~Decompile original game~~

60
build-mac-app.sh Executable file
View file

@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -xe
mkdir -p Libs
cd Libs
sdl_version='2.28.1'
sdl_filename="SDL2-$sdl_version.dmg"
sdl_url="https://github.com/libsdl-org/SDL/releases/download/release-$sdl_version/$sdl_filename"
sdl_mixer_version='2.7.0'
sdl_mixer_filename="SDL2_mixer-$sdl_mixer_version.dmg"
sdl_mixer_url="https://www.libsdl.org/tmp/$sdl_mixer_filename"
mount_point="$(mktemp -d)"
if [ ! -f "$sdl_filename" ]; then
curl -sSf -L -O "$sdl_url"
fi
echo "2f936225c10a402cab07055e6f75de76f991945c37feb0cf6af633a96d2fb28c $sdl_filename" | shasum -a 256 -c
hdiutil attach "$sdl_filename" -mountpoint "$mount_point" -quiet
cp -a "$mount_point/SDL2.framework" .
hdiutil detach "$mount_point"
if [ ! -f "$sdl_mixer_filename" ]; then
curl -sSf -L -O "$sdl_mixer_url"
fi
echo "f394c714c8aefdcae0ff9d6eefeb5d42f28e56ed09fcaebb796cb672ca11279d $sdl_mixer_filename" | shasum -a 256 -c
hdiutil attach "$sdl_mixer_filename" -mountpoint "$mount_point" -quiet
cp -a "$mount_point/SDL2_mixer.framework" .
hdiutil detach "$mount_point"
cd ..
cmake .
cmake --build .
sw_version='2.0.1'
mkdir -p SpaceCadetPinball.app/Contents/MacOS
mkdir -p SpaceCadetPinball.app/Contents/Resources
mkdir -p SpaceCadetPinball.app/Contents/Frameworks
cp -a Platform/macOS/Info.plist SpaceCadetPinball.app/Contents/
cp -a Platform/macOS/SpaceCadetPinball.icns SpaceCadetPinball.app/Contents/Resources/
cp -a Libs/SDL2.framework SpaceCadetPinball.app/Contents/Frameworks/
cp -a Libs/SDL2_mixer.framework SpaceCadetPinball.app/Contents/Frameworks/
cp -a bin/SpaceCadetPinball SpaceCadetPinball.app/Contents/MacOS/
sed -i '' "s/CHANGEME_SW_VERSION/$sw_version/" SpaceCadetPinball.app/Contents/Info.plist
echo -n "APPL????" > SpaceCadetPinball.app/Contents/PkgInfo
hdiutil create -fs HFS+ -srcfolder SpaceCadetPinball.app -volname "SpaceCadetPinball $sw_version" "SpaceCadetPinball-$sw_version-mac.dmg"
rm -r SpaceCadetPinball.app