feat: macOS bundle support

This commit is contained in:
Gary Wang 2024-12-02 00:25:48 +08:00
parent 06af632914
commit e64b871a2f
5 changed files with 151 additions and 8 deletions

View File

@ -1,6 +1,6 @@
name: macOS CI
on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]
jobs:
build:
@ -10,10 +10,19 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install Qt
uses: jurplel/install-qt-action@v3
uses: jurplel/install-qt-action@v4
with:
version: '6.4.2'
version: '6.8.1'
modules: 'qtimageformats'
- name: Run a qt project
run: |
cmake ./ -DPREFER_QT_5=OFF
make
cmake . -Bbuild
cmake --build build
- name: Deploy
run: |
macdeployqt ./build/ppic.app -dmg
ls
- uses: actions/upload-artifact@v4
with:
name: "macos-bundle"
path: build/*.dmg

3
.gitignore vendored
View File

@ -2,6 +2,9 @@
*.user
*.user.*
# Why, macOS, why?
.DS_Store
# Translation files
*.qm
*.mo

View File

@ -107,7 +107,7 @@ if (WIN32)
list(APPEND PPIC_RC_FILES assets/pineapple-pictures.rc)
endif ()
add_executable (${EXE_NAME} WIN32
add_executable (${EXE_NAME}
${PPIC_HEADER_FILES}
${PPIC_CPP_FILES}
${PPIC_QRC_FILES}
@ -201,8 +201,24 @@ endif ()
# Install settings
if (WIN32)
# TODO: try to avoid install to a "bin" subfolder under windows...
# when fixed, don't forget to update the CI config file...
set_target_properties(${EXE_NAME} PROPERTIES
WIN32_EXECUTABLE TRUE
)
elseif (APPLE)
set_source_files_properties(assets/icons/app-icon.icns PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources"
)
target_sources(${EXE_NAME} PUBLIC assets/icons/app-icon.icns)
# See https://cmake.org/cmake/help/v3.15/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.html
set_target_properties(${EXE_NAME} PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/dist/MacOSXBundleInfo.plist.in
MACOSX_BUNDLE_BUNDLE_NAME "Pineapple Pictures"
MACOSX_BUNDLE_GUI_IDENTIFIER net.blumia.pineapple-pictures
MACOSX_BUNDLE_ICON_FILE app-icon.icns # contains the .icns file name, *without* the path.
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
)
elseif (UNIX)
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX /usr)
@ -229,6 +245,7 @@ elseif (UNIX)
endif()
set (INSTALL_TARGETS_DEFAULT_ARGS
BUNDLE DESTINATION .
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Devel

BIN
assets/icons/app-icon.icns Normal file

Binary file not shown.

114
dist/MacOSXBundleInfo.plist.in vendored Normal file
View File

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//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>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
<key>CFBundleGetInfoString</key>
<string>${MACOSX_BUNDLE_INFO_STRING}</string>
<key>CFBundleIconFile</key>
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
<key>CFBundleIdentifier</key>
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleLongVersionString</key>
<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string>
<key>CFBundleName</key>
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>CFBundleDocumentTypes</key>
<array>
<!-- JPEG -->
<dict>
<key>CFBundleTypeName</key>
<string>JPEG Image</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>jpg</string>
<string>jpeg</string>
<string>jfif</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>image/jpeg</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<!-- PNG -->
<dict>
<key>CFBundleTypeName</key>
<string>PNG Image</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>png</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>image/png</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<!-- WebP -->
<dict>
<key>CFBundleTypeName</key>
<string>WebP Image</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>webp</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>image/webp</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<!-- GIF -->
<dict>
<key>CFBundleTypeName</key>
<string>GIF Image</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>gif</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>image/gif</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<!-- SVG -->
<dict>
<key>CFBundleTypeName</key>
<string>SVG Image</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>svg</string>
</array>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>image/svg+xml</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
</dict>
</plist>