1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-17 21:12:34 +01:00

Merge pull request #15411 from adam-bloom/macos-universal-fix-13524

Fix #13524: macOS Universal app
This commit is contained in:
Michał Janiszewski
2021-10-09 14:22:33 -07:00
committed by GitHub
6 changed files with 141 additions and 20 deletions

View File

@@ -146,21 +146,37 @@ jobs:
echo 'Not going to push build'
fi
macos-cmake:
name: macOS (x64) using CMake
name: macOS (${{ matrix.arch }}) using CMake
runs-on: macos-latest
needs: check-code-formatting
strategy:
fail-fast: false
matrix:
arch: [x64, arm64]
include:
- arch: x64
cache_key: macos-x64
# Note: only build/run tests on the native architecture of the CI agent
# Github macos-latest agents are currently all Intel
build_flags: -DARCH="x86_64" -DWITH_TESTS=on
run_tests: true
- arch: arm64
cache_key: macos-arm64
build_flags: -DARCH="arm64"
run_tests: false
steps:
- name: Checkout
uses: actions/checkout@v2
- name: ccache
uses: hendrikmuhs/ccache-action@v1
with:
key: macos
key: ${{ matrix.cache_key }}
- name: Build OpenRCT2
run: |
HOMEBREW_NO_ANALYTICS=1 brew install ninja
. scripts/setenv -q && build -DWITH_TESTS=on -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=on
. scripts/setenv -q && build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=on ${{ matrix.build_flags }}
- name: Run Tests
if: ${{matrix.run_tests}}
run: . scripts/setenv -q && run-tests
- name: Build artifacts
run: |
@@ -173,7 +189,45 @@ jobs:
- name: Upload artifacts (CI)
uses: actions/upload-artifact@v2
with:
name: OpenRCT2-${{ runner.os }}-cmake
name: OpenRCT2-${{ runner.os }}-${{ matrix.arch }}-cmake
path: artifacts/openrct2-macos.zip
if-no-files-found: error
macos-universal:
name: macOS universal app bundle
runs-on: macos-latest
needs: macos-cmake
steps:
- name: Checkout
uses: actions/checkout@v2
- name: download x64 app bundle
uses: actions/download-artifact@v2
with:
name: OpenRCT2-${{ runner.os }}-x64-cmake
path: macos_universal/x64
- name: download arm64 app bundle
uses: actions/download-artifact@v2
with:
name: OpenRCT2-${{ runner.os }}-arm64-cmake
path: macos_universal/arm64
- name: Make Universal app bundle
run: |
. scripts/setenv
cd macos_universal
unzip x64/openrct2-macos.zip -d x64
unzip arm64/openrct2-macos.zip -d arm64
create-macos-universal
- name: Create artifact
run: |
. scripts/setenv
mkdir -p artifacts
mv macos_universal/OpenRCT2-universal.app artifacts/OpenRCT2.app
echo -e "\033[0;36mCompressing OpenRCT2.app...\033[0m"
cd artifacts
zip -rqy openrct2-macos.zip OpenRCT2.app
- name: Upload artifacts (CI)
uses: actions/upload-artifact@v2
with:
name: OpenRCT2-${{ runner.os }}-universal
path: artifacts/openrct2-macos.zip
if-no-files-found: error
linux-portable:

View File

@@ -20,12 +20,27 @@ if (CCache_FOUND)
endif (CCache_FOUND)
if (APPLE)
set(CMAKE_OSX_ARCHITECTURES "x86_64")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14")
endif ()
execute_process(COMMAND /usr/bin/uname -m OUTPUT_VARIABLE SYSTEM_MACOS_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT DEFINED ARCH)
set(ARCH "${SYSTEM_MACOS_ARCH}")
endif ()
set(CMAKE_OSX_ARCHITECTURES "${ARCH}" CACHE STRING "")
if("${ARCH}" MATCHES "^x86_64")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "")
elseif("${ARCH}" MATCHES "^arm64")
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "")
else()
message("Unknown macOS architecture: ${ARCH}. Behavior may be unexpected.")
endif()
endif ()
project(openrct2 CXX)
if (APPLE)
set(CMAKE_SYSTEM_PROCESSOR "${CMAKE_OSX_ARCHITECTURES}" CACHE STRING "")
endif ()
include(cmake/platform.cmake)
include(CMakeDependentOption)
@@ -110,9 +125,9 @@ if (MACOS_USE_DEPENDENCIES)
# if we're building on macOS, then we need the dependencies
include(cmake/download.cmake)
set(MACOS_DYLIBS_VERSION "28")
set(MACOS_DYLIBS_ZIPFILE "openrct2-libs-v${MACOS_DYLIBS_VERSION}-x64-macos-dylibs.zip")
set(MACOS_DYLIBS_SHA1 "29e5480376cf4ac5943f114387e32685204c8b78")
set(MACOS_DYLIBS_VERSION "29")
set(MACOS_DYLIBS_ZIPFILE "openrct2-libs-v${MACOS_DYLIBS_VERSION}-universal-macos-dylibs.zip")
set(MACOS_DYLIBS_SHA1 "86cf2db4d87173112a00042418d0d18cae360e41")
set(MACOS_DYLIBS_DIR "${ROOT_DIR}/lib/macos")
set(MACOS_DYLIBS_URL "https://github.com/OpenRCT2/Dependencies/releases/download/v${MACOS_DYLIBS_VERSION}/${MACOS_DYLIBS_ZIPFILE}")
@@ -209,6 +224,10 @@ if (NOT DISABLE_DISCORD_RPC)
endif()
endif()
# ensure X86 and X86_64 are always initialized
# may be overwritten below
set(X86 0)
set(X86_64 0)
# Copied from https://github.com/opencv/opencv/blob/dcdd6af5a856826fe62c95322145731e702e54c5/cmake/OpenCVDetectCXXCompiler.cmake#L63-L70
if(MSVC64 OR MINGW64)
set(X86_64 1)
@@ -368,14 +387,16 @@ endif ()
# g2
add_custom_command(
OUTPUT g2.dat
COMMAND ./openrct2-cli sprite build \"${CMAKE_BINARY_DIR}/g2.dat\" \"${ROOT_DIR}/resources/g2/sprites.json\"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_target(g2 DEPENDS ${PROJECT_NAME} g2.dat)
project(openrct2 CXX)
if (NOT (MACOS_BUNDLE AND (NOT CMAKE_OSX_ARCHITECTURES MATCHES "${SYSTEM_MACOS_ARCH}")))
add_custom_command(
OUTPUT g2.dat
COMMAND ./openrct2-cli sprite build \"${CMAKE_BINARY_DIR}/g2.dat\" \"${ROOT_DIR}/resources/g2/sprites.json\"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_target(g2 DEPENDS ${PROJECT_NAME} g2.dat)
else ()
message("Skipping g2.dat generation in macOS cross-compile")
endif ()
# Include tests
if (WITH_TESTS)

View File

@@ -189,6 +189,7 @@ The following people are not part of the development team, but have been contrib
* Michał Janiszewski (janisozaur) - Linux, Travis CI
* Lewis Fox (LRFLEW) - macOS
* Andrew Rimpici (Andy608) - macOS
* Adam Bloom (adam-bloom) - macOS, CI
## Documentation
* (honzi)

View File

@@ -35,6 +35,7 @@
- Fix: [#15503] Freeze when doing specific coaster merges with block brakes.
- Fix: [#15514] Two different “quit to menu” menu items are available in track designer and track design manager.
- Improved: [#3417] Crash dumps are now placed in their own folder.
- Improved: [#13524] macOS arm64 native (universal) app
- Improved: [#15538] Software rendering can now draw in parallel when Multithreading is enabled.
- Change: [#8601] Revert ToonTower base block fix to re-enable support blocking.
- Change: [#15174] [Plugin] Deprecate the type "peep" and add support to target a specific scripting api version.

28
scripts/create-macos-universal Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/bash -e
echo "Creating macOS universal app bundle"
# create app skeleton
mkdir OpenRCT2-universal.app
mkdir OpenRCT2-universal.app/Contents
# copy all resources (most will overwrite)
mkdir OpenRCT2-universal.app/Contents/Resources
# Note: g2.dat is expected to only be in one (matching OS of build machine)
rsync -ah x64/OpenRCT2.app/Contents/Resources/* OpenRCT2-universal.app/Contents/Resources/
rsync -ah arm64/OpenRCT2.app/Contents/Resources/* OpenRCT2-universal.app/Contents/Resources/
# create a universal binary
mkdir OpenRCT2-universal.app/Contents/MacOS
lipo -create x64/OpenRCT2.app/Contents/MacOS/OpenRCT2 arm64/OpenRCT2.app/Contents/MacOS/OpenRCT2 -output OpenRCT2-universal.app/Contents/MacOS/OpenRCT2
# copy frameworks
mkdir OpenRCT2-universal.app/Contents/Frameworks
# with the exception of libopenrct2.dylib, the Frameworks are identical and are already universal dylibs
rsync -ah --exclude 'libopenrct2.dylib' x64/OpenRCT2.app/Contents/Frameworks/* OpenRCT2-universal.app/Contents/Frameworks
lipo -create x64/OpenRCT2.app/Contents/Frameworks/libopenrct2.dylib arm64/OpenRCT2.app/Contents/Frameworks/libopenrct2.dylib -output OpenRCT2-universal.app/Contents/Frameworks/libopenrct2.dylib
# handle Info.plist
defaults import $PWD/OpenRCT2-universal.app/Contents/Info $PWD/x64/OpenRCT2.app/Contents/Info.plist $PWD/arm64/OpenRCT2.app/Contents/Info.plist
arm64_min_ver=$(defaults read $PWD/arm64/OpenRCT2.app/Contents/Info LSMinimumSystemVersion)
x64_min_ver=$(defaults read $PWD/x64/OpenRCT2.app/Contents/Info LSMinimumSystemVersion)
defaults write $PWD/OpenRCT2-universal.app/Contents/Info LSMinimumSystemVersionByArchitecture -dict x86_64 ${x64_min_ver} arm64 ${arm64_min_ver}

View File

@@ -35,6 +35,17 @@ file(GLOB_RECURSE OPENRCT2_UI_HEADERS
if (APPLE)
file(GLOB_RECURSE OPENRCT2_UI_MM_SOURCES "${CMAKE_CURRENT_LIST_DIR}/*.mm")
set_source_files_properties(${OPENRCT2_UI_MM_SOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c++ -fmodules")
if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "arm64")
# cross-compilation workaround for SDL2
# This has been addressed upstream in https://github.com/libsdl-org/SDL/commit/bf1d7a3a15a6c090188974bec8ca84eb1903d4f7
# Remove this workaround after:
# 1) a new SDL release is made containing that fix
# 2) The vcpkg port is updated to use that release
# 3) A new Dependencies release is made with that latest vcpkg version
# 4) That new release is used in this build
set(SDL_DISABLE_IMMINTRIN_H "-DSDL_DISABLE_IMMINTRIN_H")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SDL_DISABLE_IMMINTRIN_H}")
endif ()
endif ()
# Outputs
@@ -141,7 +152,6 @@ if(MACOS_BUNDLE)
target_sources(${PROJECT_NAME}
PUBLIC ${ROOT_DIR}/distribution/readme.txt
PUBLIC ${ROOT_DIR}/distribution/changelog.txt
PUBLIC ${CMAKE_BINARY_DIR}/g2.dat
PUBLIC ${ROOT_DIR}/resources/mac/openrct2.icns
)
@@ -149,10 +159,16 @@ if(MACOS_BUNDLE)
set(BUNDLE_RESOURCES
${ROOT_DIR}/distribution/readme.txt
${ROOT_DIR}/distribution/changelog.txt
${CMAKE_BINARY_DIR}/g2.dat
${ROOT_DIR}/resources/mac/openrct2.icns
)
if (CMAKE_OSX_ARCHITECTURES MATCHES "${SYSTEM_MACOS_ARCH}")
target_sources(${PROJECT_NAME}
PUBLIC ${CMAKE_BINARY_DIR}/g2.dat
)
list(APPEND BUNDLE_RESOURCES ${CMAKE_BINARY_DIR}/g2.dat)
endif()
if(${OPENRCT2_BRANCH} EQUAL master)
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${OPENRCT2_VERSION_TAG}")