diff --git a/CLAUDE.md b/CLAUDE.md index f76c190..761801d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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. -**Target platforms:** Windows and Linux (both required from day one); macOS planned +**Target platforms:** Windows, Linux, and macOS ### Format Support @@ -89,6 +89,25 @@ System packages installed by the script: | `libwpd-dev` | Legacy .doc format | | `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 GitLab CI (`.gitlab-ci.yml`), stages: `build` → `package` → `wiki`. diff --git a/CMakeLists.txt b/CMakeLists.txt index 26d0f41..2fe90b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,13 @@ find_package(Qt6 OPTIONAL_COMPONENTS Pdf DBus) # Third-party libraries find_package(PkgConfig REQUIRED) pkg_check_modules(UCHARDET REQUIRED IMPORTED_TARGET uchardet) + +# Homebrew's uchardet pkg-config sets includedir=…/include/uchardet (one level too deep), +# causing #include 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) 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 @@ -90,6 +99,16 @@ if(WIN32) $<$>:-mwindows>) 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_link_libraries(asteria-qt PRIVATE @@ -174,12 +193,14 @@ qt_add_qml_module(asteria-qt # Install rules install(TARGETS asteria-qt DESTINATION ${CMAKE_INSTALL_BINDIR}) -install(FILES packaging/asteria-qt.desktop - DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) -foreach(SIZE 16 32 48 64 128 256 512) - install(FILES packaging/icons/${SIZE}x${SIZE}/asteria-qt.png - DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/${SIZE}x${SIZE}/apps) -endforeach() +if(UNIX AND NOT APPLE) + install(FILES packaging/asteria-qt.desktop + DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) + foreach(SIZE 16 32 48 64 128 256 512) + install(FILES packaging/icons/${SIZE}x${SIZE}/asteria-qt.png + DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/${SIZE}x${SIZE}/apps) + endforeach() +endif() # Testing enable_testing() diff --git a/packaging/package-macos.sh b/packaging/package-macos.sh new file mode 100755 index 0000000..df07053 --- /dev/null +++ b/packaging/package-macos.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Package macOS build as a .dmg disk image +# Usage: package-macos.sh +set -euo pipefail + +BUILD_DIR="${1:?Usage: package-macos.sh }" +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" diff --git a/scripts/install-deps-macos.sh b/scripts/install-deps-macos.sh new file mode 100755 index 0000000..487917f --- /dev/null +++ b/scripts/install-deps-macos.sh @@ -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"