Skip to content

Commit

Permalink
Add native build for Apple M1 / M2 (arm64) architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Feb 1, 2024
1 parent d04527b commit 4051924
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 5 deletions.
77 changes: 74 additions & 3 deletions .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,83 @@ jobs:
deploy/Hyper*.rpm
######################
####### macOS ########
### macOS (arm64) ####
######################

macOS_arm64:
name: macOS (arm64)
runs-on: macos-14
env:
QT_VERSION: "6"
steps:
# Checkout
- uses: actions/checkout@v3
with:
submodules: true

# Generate cache id
- name: Prepare ccache timestamp
if: env.USE_CACHE == '1'
id: ccache_cache_timestamp
shell: cmake -P {0}
run: |
string(TIMESTAMP current_date "%Y-%m-%d-%H-%M-%S" UTC)
file(APPEND "$ENV{GITHUB_OUTPUT}" "timestamp=${current_date}")
# Download cache
- name: ccache cache files
if: ( env.USE_CACHE == '1' )
uses: actions/cache@v3
with:
path: .ccache
key: macOS-ccache-${{ steps.ccache_cache_timestamp.outputs.timestamp }}
restore-keys: macOS-ccache-

# Install deps
- name: Install deps
shell: bash
run: brew install qt@${{ env.QT_VERSION }} xz ccache zstd webp jpeg-turbo || true

# Set env
- name: Set QT5 env
if: ( env.QT_VERSION == '5' )
shell: bash
run: |
export Qt5_DIR=`brew --prefix qt5`;
echo "Qt5_DIR=$Qt5_DIR" >> $GITHUB_ENV
# Build process
- name: Build packages
env:
PLATFORM: osx
USE_CCACHE: ${{ env.USE_CACHE }}
RESET_CACHE: ${{ env.RESET_CACHE }}
shell: bash
run: ./.ci/ci_build.sh

# Upload artifacts (only on tagged commit)
- name: Upload artifacts
if: startsWith(github.event.ref, 'refs/tags') && github.event_name != 'pull_request'
uses: actions/upload-artifact@v3
with:
path: build/Hyper*.dmg

# Upload artifacts from commit
- name: Upload artifacts from commit
if: (startsWith(github.event.ref, 'refs/tags') != true) && github.event_name != 'pull_request'
uses: actions/upload-artifact@v3
with:
name: Apple_macOS_arm64_DMG_installer
path: build/Hyper*.dmg


######################
##### macOS (x86) ####
######################

macOS:
name: macOS
runs-on: macos-12
runs-on: macos-13
env:
QT_VERSION: "5"
steps:
Expand Down Expand Up @@ -292,7 +363,7 @@ jobs:
publish:
name: Publish Releases
if: startsWith(github.event.ref, 'refs/tags') && github.event_name != 'pull_request'
needs: [Linux, windows, macOS]
needs: [Linux, windows, macOS, macOS_arm64]
runs-on: ubuntu-22.04
permissions:
contents: write
Expand Down
54 changes: 52 additions & 2 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ macro(DeployApple TARGET)
install(CODE "set(MYQT_PLUGINS_DIR \"${MYQT_PLUGINS_DIR}\")" COMPONENT "HyperHDR")
install(CODE "set(MY_DEPENDENCY_PATHS \"${TARGET_FILE}\")" COMPONENT "HyperHDR")
install(CODE "set(MY_SYSTEM_LIBS_SKIP \"${SYSTEM_LIBS_SKIP}\")" COMPONENT "HyperHDR")
install(CODE "set(Scope_Qt_VERSION ${Qt_VERSION})" COMPONENT "HyperHDR")
install(CODE [[
#OpenSSL
if(EXISTS "/usr/local/opt/[email protected]/lib" AND IS_DIRECTORY "/usr/local/opt/[email protected]/lib")
message( STATUS "Including OpenSSL libraries")
if(Scope_Qt_VERSION EQUAL 5 AND EXISTS "/usr/local/opt/[email protected]/lib" AND IS_DIRECTORY "/usr/local/opt/[email protected]/lib")
message("Including OpenSSL@1.1 libraries")
file(GLOB filesSSL "/usr/local/opt/[email protected]/lib/*")
foreach(openssl_lib ${filesSSL})
string(FIND ${openssl_lib} "dylib" _indexSSL)
Expand All @@ -51,6 +52,31 @@ macro(DeployApple TARGET)
)
endif()
endforeach()
elseif(NOT (Scope_Qt_VERSION EQUAL 5) AND EXISTS "/opt/homebrew/opt/openssl/lib" AND IS_DIRECTORY "/opt/homebrew/opt/openssl/lib")
if (EXISTS "/opt/homebrew/opt/openssl/lib/libssl.3.dylib")
message("Including OpenSSL@3 libraries")
elseif (EXISTS "/opt/homebrew/opt/openssl/lib/libssl.dylib")
message("Including [email protected] libraries")
else()
message(WARNING "Including unknown version of OpenSSL libraries")
endif()
file(GLOB filesSSL "/opt/homebrew/opt/openssl/lib/*")
foreach(openssl_lib ${filesSSL})
string(FIND ${openssl_lib} "dylib" _indexSSL)
if (${_indexSSL} GREATER -1)
file(INSTALL
DESTINATION "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/Frameworks"
TYPE SHARED_LIBRARY
FILES "${openssl_lib}"
)
else()
file(INSTALL
DESTINATION "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/lib"
TYPE SHARED_LIBRARY
FILES "${openssl_lib}"
)
endif()
endforeach()
else()
message( WARNING "OpenSSL NOT found (https instance will not work)")
endif()
Expand Down Expand Up @@ -131,6 +157,30 @@ macro(DeployApple TARGET)

include(BundleUtilities)
fixup_bundle("${CMAKE_INSTALL_PREFIX}/hyperhdr.app" "${MYQT_PLUGINS}" "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/lib")

EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE OS_ARCHITECTURE )
message( "Detected architecture: '${OS_ARCHITECTURE}'")
if(OS_ARCHITECTURE STREQUAL "arm64")
file(GLOB libSignFramework "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/Frameworks/*.dylib")
list (APPEND libSignFramework "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/MacOS/hyperhdr")
foreach(PLUGIN "platforms" "sqldrivers" "imageformats")
file(GLOB libPlugins "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/plugins/${PLUGIN}/*.dylib")
list (APPEND libSignFramework ${libPlugins})
endforeach()
list (APPEND libSignFramework "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/Frameworks/QtCore.framework/Versions/A/QtCore")
list (APPEND libSignFramework "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/Frameworks/QtDBus.framework/Versions/A/QtDBus")
list (APPEND libSignFramework "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/Frameworks/QtGui.framework/Versions/A/QtGui")
list (APPEND libSignFramework "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/Frameworks/QtSql.framework/Versions/A/QtSql")
list (APPEND libSignFramework "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/Frameworks/QtNetwork.framework/Versions/A/QtNetwork")
list (APPEND libSignFramework "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/Frameworks/QtPdf.framework/Versions/A/QtPdf")
list (APPEND libSignFramework "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/Frameworks/QtSvg.framework/Versions/A/QtSvg")
list (APPEND libSignFramework "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/Frameworks/QtSerialPort.framework/Versions/A/QtSerialPort")
list (APPEND libSignFramework "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/Frameworks/QtWidgets.framework/Versions/A/QtWidgets")
foreach(_fileToSign ${libSignFramework})
message("Fixing: ${_fileToSign}")
execute_process(COMMAND bash -c "codesign --force -s - ${_fileToSign}")
endforeach()
endif()

file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/hyperhdr.app/Contents/lib")
file(REMOVE_RECURSE "${CMAKE_INSTALL_PREFIX}/share")
Expand Down

0 comments on commit 4051924

Please sign in to comment.