Add Mac support

This commit is contained in:
Agel committed 2026-04-10 00:07:16 +02:00
1 parent ad0d7376b3
commit 2568f9089b
4 files changed
+105 -5

No files matched your search

+20 -1
View File
@@ -6,7 +6,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
Asteria Qt is a cross-platform desktop book/document reader built with Qt6/C++. It is a reimplementation of [asteria-bookreader](../asteria-bookreader) (Electron/React) using a native Qt stack. Asteria Qt is a cross-platform desktop book/document reader built with Qt6/C++. It is a reimplementation of [asteria-bookreader](../asteria-bookreader) (Electron/React) using a native Qt stack.
**Target platforms:** Windows and Linux (both required from day one); macOS planned **Target platforms:** Windows, Linux, and macOS
### Format Support ### Format Support
@@ -89,6 +89,25 @@ System packages installed by the script:
| `libwpd-dev` | Legacy .doc format | | `libwpd-dev` | Legacy .doc format |
| `python3-venv` | For aqtinstall | | `python3-venv` | For aqtinstall |
### macOS Build Environment
Requires macOS 12+ with Xcode Command Line Tools (`xcode-select --install`) and [Homebrew](https://brew.sh).
Run `scripts/install-deps-macos.sh` to install Homebrew packages and Qt, then:
```bash
cmake -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_PREFIX_PATH=/opt/qt/6.10.3/macos
cmake --build build --parallel
ctest --test-dir build --output-on-failure
```
Homebrew packages installed by the script: `cmake`, `ninja`, `pkg-config`, `uchardet`, `minizip`. Qt 6.10.3 is installed via `aqtinstall` to `/opt/qt/6.10.3/macos` (universal binary, runs on both Apple Silicon and Intel).
macOS builds use Metal for rendering (already handled in `main.cpp` via `Q_OS_MACOS`). macOS cannot be cross-compiled from Linux; CI must run on a native macOS host.
### CI Build Environment ### CI Build Environment
GitLab CI (`.gitlab-ci.yml`), stages: `build` → `package` → `wiki`. GitLab CI (`.gitlab-ci.yml`), stages: `build` → `package` → `wiki`.
+25 -4
View File
@@ -26,6 +26,13 @@ find_package(Qt6 OPTIONAL_COMPONENTS Pdf DBus)
# Third-party libraries # Third-party libraries
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
pkg_check_modules(UCHARDET REQUIRED IMPORTED_TARGET uchardet) pkg_check_modules(UCHARDET REQUIRED IMPORTED_TARGET uchardet)
# Homebrew's uchardet pkg-config sets includedir=…/include/uchardet (one level too deep),
# causing #include <uchardet/uchardet.h> to fail. Strip the trailing /uchardet if present.
get_target_property(_uchardet_inc PkgConfig::UCHARDET INTERFACE_INCLUDE_DIRECTORIES)
list(TRANSFORM _uchardet_inc REPLACE "/uchardet$" "")
set_target_properties(PkgConfig::UCHARDET PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_uchardet_inc}")
find_package(Iconv REQUIRED) find_package(Iconv REQUIRED)
pkg_check_modules(MINIZIP REQUIRED IMPORTED_TARGET minizip) pkg_check_modules(MINIZIP REQUIRED IMPORTED_TARGET minizip)
@@ -75,7 +82,9 @@ set(SOURCES
) )
list(APPEND SOURCES src/asteria.rc) if(WIN32)
list(APPEND SOURCES src/asteria.rc)
endif()
# Executable # Executable
@@ -90,6 +99,16 @@ if(WIN32)
$<$<NOT:$<CONFIG:Debug>>:-mwindows>) $<$<NOT:$<CONFIG:Debug>>:-mwindows>)
endif() endif()
if(APPLE)
set_target_properties(asteria-qt PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_BUNDLE_NAME "Asteria"
MACOSX_BUNDLE_GUI_IDENTIFIER "com.asteria-bookreader.asteria-qt"
MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}"
)
endif()
target_include_directories(asteria-qt PRIVATE src) target_include_directories(asteria-qt PRIVATE src)
target_link_libraries(asteria-qt PRIVATE target_link_libraries(asteria-qt PRIVATE
@@ -174,12 +193,14 @@ qt_add_qml_module(asteria-qt
# Install rules # Install rules
install(TARGETS asteria-qt DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS asteria-qt DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES packaging/asteria-qt.desktop if(UNIX AND NOT APPLE)
install(FILES packaging/asteria-qt.desktop
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
foreach(SIZE 16 32 48 64 128 256 512) foreach(SIZE 16 32 48 64 128 256 512)
install(FILES packaging/icons/${SIZE}x${SIZE}/asteria-qt.png install(FILES packaging/icons/${SIZE}x${SIZE}/asteria-qt.png
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/${SIZE}x${SIZE}/apps) DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/${SIZE}x${SIZE}/apps)
endforeach() endforeach()
endif()
# Testing # Testing
enable_testing() enable_testing()
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
# Package macOS build as a .dmg disk image
# Usage: package-macos.sh <build-dir> <qt-dir> <output-dir>
set -euo pipefail
BUILD_DIR="${1:?Usage: package-macos.sh <build-dir> <qt-dir> <output-dir>}"
QT_DIR="${2:?}"
OUTPUT_DIR="${3:?}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
APP_PATH="$BUILD_DIR/asteria-qt.app"
DMG_NAME="Asteria-macOS.dmg"
# Deploy Qt frameworks into the .app bundle
"$QT_DIR/bin/macdeployqt" "$APP_PATH" -qmldir="$PROJECT_DIR/src/qml"
# Create .dmg
hdiutil create -volname "Asteria" -srcfolder "$APP_PATH" \
-ov -format UDZO "$BUILD_DIR/$DMG_NAME"
mkdir -p "$OUTPUT_DIR"
mv "$BUILD_DIR/$DMG_NAME" "$OUTPUT_DIR/"
echo "Created: $OUTPUT_DIR/$DMG_NAME"
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
# Install all development dependencies for asteria-qt on macOS.
# Requires Homebrew (https://brew.sh) and Xcode Command Line Tools.
# Run as a normal user (sudo is used only where needed).
set -euo pipefail
brew update
brew install cmake ninja pkg-config uchardet minizip
echo ""
echo "Installing Qt 6.10.3 via aqtinstall → /opt/qt ..."
python3 -m venv /tmp/aqt-venv
/tmp/aqt-venv/bin/pip install --quiet aqtinstall
# Qt for macOS ships as a universal binary (arm64 + x86_64); aqtinstall installs to "macos"
QT_ARCH="clang_64"
QT_DIR_NAME="macos"
sudo mkdir -p /opt/qt
sudo chown "$USER" /opt/qt
/tmp/aqt-venv/bin/aqt install-qt mac desktop 6.10.3 "$QT_ARCH" \
-m qtimageformats qtpdf --outputdir /opt/qt
rm -rf /tmp/aqt-venv
QT_DIR="/opt/qt/6.10.3/$QT_DIR_NAME"
echo ""
echo "All dependencies installed."
echo ""
echo "Qt 6.10.3 is at $QT_DIR"
echo ""
echo "Build with:"
echo " cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=$QT_DIR"
echo " cmake --build build --parallel"
echo " ctest --test-dir build --output-on-failure"