Skip to content

Commit

Permalink
Merge pull request #105 from vpoguru/master
Browse files Browse the repository at this point in the history
Added builds for macOS
  • Loading branch information
larspalo authored Jun 19, 2024
2 parents cbb7d4c + bebfe09 commit e960d49
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 11 deletions.
64 changes: 63 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,61 @@ jobs:
name: GoOdf-${{github.ref_name}}-windows
path: ${{github.workspace}}/crossbuild/GoOdf*.zip

build-macos-x86:
runs-on: macos-13

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Get dependencies
run: ${{github.workspace}}/scripts/prepare-osx.sh

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build with CMake
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Package with CPack
working-directory: ${{github.workspace}}/build
run: cpack

- uses: actions/upload-artifact@v4
with:
name: GoOdf-${{github.ref_name}}-macos-x86
path: ${{ github.workspace }}/build/GoOdf*.dmg

build-macos-arm:
runs-on: macos-14

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Get dependencies
run: ${{github.workspace}}/scripts/prepare-osx.sh

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build with CMake
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Package with CPack
working-directory: ${{github.workspace}}/build
run: cpack

- uses: actions/upload-artifact@v4
with:
name: GoOdf-${{github.ref_name}}-macos-arm
path: ${{ github.workspace }}/build/GoOdf*.dmg

release:
if: ${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}
needs: [ build-linux, build-appimage, build-cross-windows ]
needs: [ build-linux, build-appimage, build-cross-windows, build-macos-x86, build-macos-arm ]
name: Create GitHub Release
runs-on: ubuntu-latest
steps:
Expand All @@ -125,6 +177,14 @@ jobs:
with:
name: GoOdf-${{github.ref_name}}-windows

- uses: actions/download-artifact@v4
with:
name: GoOdf-${{github.ref_name}}-macos-x86

- uses: actions/download-artifact@v4
with:
name: GoOdf-${{github.ref_name}}-macos-arm

- name: Remove Starting v From Tag
id: remove_v
run: |
Expand All @@ -141,3 +201,5 @@ jobs:
GoOdf-${{env.release_version}}-linux.x86_64.tar.gz
GoOdf-${{env.release_version}}.x86_64.AppImage
GoOdf-${{env.release_version}}-windows.x86_64.zip
GoOdf-${{env.release_version}}-macOS.x86_64.dmg
GoOdf-${{env.release_version}}-macOS.arm64.dmg
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.cproject
build/
/_build/
**/.DS_Store
**/.lib/
62 changes: 52 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC

# Strip binary for release builds
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(CMAKE_CROSSCOMPILING AND WIN32)
if(APPLE)
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND strip ${CMAKE_PROJECT_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
elseif(CMAKE_CROSSCOMPILING AND WIN32)
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND strip --strip-all ${CMAKE_PROJECT_NAME}.exe WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
else()
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND strip --strip-all ${CMAKE_PROJECT_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
Expand All @@ -228,17 +230,25 @@ if(NOT EXISTS "${RESOURCE_DIR}/help")
endif()
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND zip -r ${RESOURCE_DIR}/help/help.zip . WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/help)

# installation rules
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION bin)
install(DIRECTORY ${CMAKE_BINARY_DIR}/share/icons/ DESTINATION share/icons FILES_MATCHING PATTERN "*.png")
install(FILES ${CMAKE_BINARY_DIR}/share/${CMAKE_PROJECT_NAME}/help/help.zip DESTINATION share/${CMAKE_PROJECT_NAME}/help)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt DESTINATION .)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/AUTHORS DESTINATION .)
# Installation rules
if (APPLE)
install(DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}.app DESTINATION .)
# Explicitly set the executable permission
install(PROGRAMS "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app/Contents/MacOS/${CMAKE_PROJECT_NAME}"
DESTINATION "${PROJECT_NAME}.app/Contents/MacOS"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
else()
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION bin)
install(DIRECTORY ${CMAKE_BINARY_DIR}/share/icons/ DESTINATION share/icons FILES_MATCHING PATTERN "*.png")
install(FILES ${CMAKE_BINARY_DIR}/share/${CMAKE_PROJECT_NAME}/help/help.zip DESTINATION share/${CMAKE_PROJECT_NAME}/help)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt DESTINATION .)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/AUTHORS DESTINATION .)
endif()
if(UNIX AND NOT APPLE)
install(FILES ${CMAKE_BINARY_DIR}/share/${CMAKE_PROJECT_NAME}/applications/${CMAKE_PROJECT_NAME}.desktop DESTINATION share/${CMAKE_PROJECT_NAME}/applications)
endif()

# packaging
# Packaging
set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "${CMAKE_PROJECT_NAME}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CMAKE_PROJECT_DESCRIPTION}")
Expand All @@ -254,14 +264,47 @@ set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGE_EXECUTABLES "${CMAKE_PROJECT_NAME}" "${CMAKE_PROJECT_NAME}")
set(CPACK_SOURCE_IGNORE_FILES ".gitignore" "/build/")
if(WIN32)

if (APPLE)
# Configure and install Info.plist
configure_file(${CMAKE_SOURCE_DIR}/resources/Info.plist.in ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app/Contents/Info.plist)
INSTALL(FILES ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app/Contents/Info.plist DESTINATION "${PROJECT_NAME}.app/Contents/")

# Create the macOS application bundle
add_custom_target(
macOSApplication
ALL
DEPENDS ${CMAKE_PROJECT_NAME} resources
COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app/Contents/MacOS"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app/Contents/Resources"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app/Contents/share"
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_BINARY_DIR}/bin/${CMAKE_PROJECT_NAME}"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app/Contents/MacOS/${CMAKE_PROJECT_NAME}"
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_SOURCE_DIR}/resources/GoOdf.icns"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app/Contents/Resources/GoOdf.icns"
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_BINARY_DIR}/share"
"${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app/Contents/share"
COMMAND "${CMAKE_COMMAND}" -DAPP_DIR="${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app" -P "${CMAKE_SOURCE_DIR}/scripts/SignMacOSApp.cmake"
COMMAND "${CMAKE_COMMAND}" -DAPP_DIR="${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app" -P "${CMAKE_SOURCE_DIR}/scripts/BundleWxWidgetLibraries.cmake"
)

# CPACK configuration
set(CPACK_SYSTEM_NAME "macOS")
set(CPACK_GENERATOR DragNDrop)
set(CPACK_DMG_FORMAT "UDZO")
set(CPACK_DMG_VOLUME_NAME "GoOdf")
set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/resources/GoOdf.icns")

elseif(WIN32)
set(CPACK_SYSTEM_NAME "windows")
set(CPACK_GENERATOR ZIP)
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(CPACK_SYSTEM_NAME "linux")
set(CPACK_GENERATOR TGZ)
endif()

set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}.${CMAKE_SYSTEM_PROCESSOR}")
include(CPack)

Expand All @@ -284,4 +327,3 @@ wxWidgets configuration : ${wxWidgets_CONFIGURATION}
============================================================================
")

Binary file added resources/GoOdf.icns
Binary file not shown.
26 changes: 26 additions & 0 deletions resources/Info.plist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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>CFBundleIdentifier</key>
<string>com.github.GrandOrgue.GoOdf</string>
<key>CFBundleName</key>
<string>GoOdf</string>
<key>CFBundleDisplayName</key>
<string>GoOdf v@PROGRAM_VERSION@</string>
<key>CFBundleVersion</key>
<string>@PROGRAM_VERSION@</string>
<key>CFBundleShortVersionString</key>
<string>@PROGRAM_VERSION@</string>
<key>CFBundleExecutable</key>
<string>GoOdf</string>
<key>CFBundleIconFile</key>
<string>GoOdf.icns</string>
<key>CFBundlePackageType</key>
<string>AAPL</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright 2024 Lars Palo</string>
</dict>
</plist>
25 changes: 25 additions & 0 deletions scripts/BundleWxWidgetLibraries.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Script to bundle wxWidget libraries

set(APP_DIR "${CMAKE_BINARY_DIR}/GoOdf.app")

if(EXISTS "${APP_DIR}")
execute_process(
COMMAND dylibbundler
--bundle-deps
--overwrite-files
--fix-file "${APP_DIR}/Contents/MacOS/GoOdf"
--dest-dir "${APP_DIR}/Contents/Resources/"
--install-path "@executable_path/../Resources/"
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_VARIABLE error_output
)

if(NOT ${result} EQUAL 0)
message(FATAL_ERROR "dylibbundler failed: ${error_output}")
else()
message(STATUS "dylibbundler output: ${output}")
endif()
else()
message(FATAL_ERROR "Application bundle not found: ${APP_DIR}")
endif()
11 changes: 11 additions & 0 deletions scripts/SignMacOSApp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Script for macOS code signing

set(APP_DIR "${CMAKE_BINARY_DIR}/GoOdf.app")

if(EXISTS "${APP_DIR}")
execute_process(COMMAND codesign --force --sign - "${APP_DIR}")
message("Checking code signature...")
execute_process(COMMAND codesign --verify --deep "${APP_DIR}")
else()
message(FATAL_ERROR "Application bundle not found: ${APP_DIR}")
endif()
4 changes: 4 additions & 0 deletions scripts/prepare-osx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

set -e
brew install autoconf-archive autogen automake dylibbundler wxwidgets

0 comments on commit e960d49

Please sign in to comment.