From 97c79c17d313675a13f3faef3bb146d447b09ce4 Mon Sep 17 00:00:00 2001 From: Agel Date: Mon, 16 Mar 2026 11:29:43 +0100 Subject: [PATCH] few changes for running on windows --- .claude/settings.local.json | 10 +-- CLAUDE.md | 11 ++++ CMakeLists.txt | 5 ++ README.md | 104 +++++++++++++++++++++---------- scripts/install-deps-windows.ps1 | 70 --------------------- scripts/install-deps-windows.sh | 29 +++++++++ 6 files changed, 119 insertions(+), 110 deletions(-) delete mode 100644 scripts/install-deps-windows.ps1 create mode 100644 scripts/install-deps-windows.sh diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 5d37486..6d7475f 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -2,15 +2,9 @@ "permissions": { "allow": [ "Bash(find:*)", - "Bash(grep -iv -E '^\\(png|jpg|JPG|gif|mp4|exe|cache|js|css|php|java|cs|properties|class|form|PAS|CPP\\)$')", - "Bash(cmake:*)", - "Bash(for d:*)", - "Bash(do echo:*)", - "Read(//home/agel/Src/asteria/asteria-bookreader/src/components/**)", - "Bash(done)", - "Bash(ctest:*)", "Bash(grep:*)", - "Bash(./build/ReadingModelTest 2>&1)" + "Bash(cmake:*)", + "Bash(ctest:*)", ] } } diff --git a/CLAUDE.md b/CLAUDE.md index 805a266..d548a02 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -39,6 +39,17 @@ Full target format list (derived from actual library inventory): See [README.md](README.md) for setup instructions, dependency installation, and IDE-specific build guides. +### Windows Build Environment + +**All build and test commands on Windows must be run in the MSYS2 MINGW64 shell** (`C:\msys64\mingw64`). This is the only shell where `cmake`, `ninja`, `gcc`, and all Qt/third-party libraries are on `PATH`. Do not use PowerShell, CMD, or the plain MSYS2 shell — they lack the correct toolchain and package prefix. + +To run a command from Claude Code on Windows, invoke it via the MSYS2 MINGW64 bash: +```bash +/c/msys64/mingw64/bin/bash.exe -c "" +# or equivalently: +C:/msys64/usr/bin/bash.exe -i -c "" +``` + ## Test-Driven Development **All new backend logic must be test-driven.** Follow the red-green-refactor cycle strictly: diff --git a/CMakeLists.txt b/CMakeLists.txt index 441161a..44b22a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ find_package(Qt6 OPTIONAL_COMPONENTS Pdf DBus) # Third-party libraries find_package(PkgConfig REQUIRED) pkg_check_modules(UCHARDET REQUIRED uchardet) +find_package(Iconv REQUIRED) # Source files set(SOURCES @@ -67,6 +68,7 @@ endif() target_include_directories(asteria-qt PRIVATE ${UCHARDET_INCLUDE_DIRS}) target_link_libraries(asteria-qt PRIVATE ${UCHARDET_LIBRARIES}) +target_link_libraries(asteria-qt PRIVATE Iconv::Iconv) # Set resource aliases so src/qml/* maps to qrc:/Asteria/* set_source_files_properties(src/qml/Main.qml PROPERTIES QT_RESOURCE_ALIAS Main.qml) @@ -83,6 +85,8 @@ set_source_files_properties(src/qml/pages/ReaderPage.qml PROPERTIES QT_RESOURCE_ set_source_files_properties(src/qml/pages/SettingsPage.qml PROPERTIES QT_RESOURCE_ALIAS pages/SettingsPage.qml) # QML module +qt_policy(SET QTP0004 NEW) + qt_add_qml_module(asteria-qt URI Asteria VERSION 1.0 @@ -120,6 +124,7 @@ function(add_asteria_test TEST_NAME TEST_SOURCE) ) target_include_directories(${TEST_NAME} PRIVATE ${UCHARDET_INCLUDE_DIRS}) target_link_libraries(${TEST_NAME} PRIVATE ${UCHARDET_LIBRARIES}) + target_link_libraries(${TEST_NAME} PRIVATE Iconv::Iconv) add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) endfunction() diff --git a/README.md b/README.md index e676f90..fef11cd 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A cross-platform desktop book/document reader built with Qt6/C++. Reimplementati - **Qt 6.4+** (6.4 minimum for QtPdf; 6.5+ recommended) - **CMake 3.16+** -- **C++17 compiler** — GCC 10+ or Clang 12+ on Linux; MSVC 2022 on Windows +- **C++17 compiler** — GCC 10+ or Clang 12+ on Linux; MinGW-w64 (GCC) via MSYS2 on Windows ## Installing Dependencies @@ -38,38 +38,86 @@ cmake --find-package -DNAME=Qt6 -DCOMPILER_ID=GNU -DLANGUAGE=CXX -DMODE=EXIST ### Windows -**Step 1 — Install Qt 6 manually** via the Qt Online Installer (qt.io/download-open-source): -- Select component: `Qt 6.x → MSVC 2022 64-bit` -- Also select: `Qt PDF`, `Qt SVG` under the same Qt version +All Windows dependencies — Qt 6, MinGW-w64, CMake, Ninja, and all third-party libraries — are installed through **MSYS2**, a Linux-like environment for Windows with a proper package manager (`pacman`). This ensures everything is compiled with the same GCC toolchain with no ABI mismatches. -**Step 2 — Install toolchain and third-party libs** (run in an elevated PowerShell): +**Step 1 — Install Git for Windows** -```powershell -scripts\install-deps-windows.ps1 +Download and install from [git-scm.com/download/win](https://git-scm.com/download/win). During setup: +- Select "Git from the command line and also from 3rd-party software" (recommended PATH option) +- Use the default options for everything else + +**Step 2 — Install MSYS2** + +Download and run the installer from [msys2.org](https://www.msys2.org). Use the default install path (`C:\msys64`). + +After installation, open the **MSYS2 MINGW64** shell (search the Start menu for "MSYS2 MINGW64" — use this shell, not MSYS2 MSYS or UCRT64) and update the package database: + +```bash +pacman -Syu ``` -Installs: VS Build Tools 2022, CMake, Ninja, Git, vcpkg, and third-party libs (QuaZip, uchardet, DjVuLibre, libwpd) via vcpkg. +The shell will likely close itself partway through. Reopen it and run the update again to finish: -**Step 3 — Configure CMake** with your Qt install path: - -```powershell -cmake -B build -DCMAKE_PREFIX_PATH="C:\Qt\6.x.x\msvc2022_64" ` - -DCMAKE_TOOLCHAIN_FILE="C:\vcpkg\scripts\buildsystems\vcpkg.cmake" +```bash +pacman -Syu ``` -Replace `6.x.x` with your installed Qt version (e.g. `6.7.2`). +**Step 3 — Install Qt 6 and all dependencies** + +In the **MSYS2 MINGW64** shell, navigate to the project folder and run the install script (MSYS2 mounts Windows drives as `/c/`, `/d/` etc.): + +```bash +cd /c/path/to/asteria-qt +bash scripts/install-deps-windows.sh +``` + +Or install manually: + +```bash +pacman -S --needed \ + mingw-w64-x86_64-gcc \ + mingw-w64-x86_64-zlib \ + mingw-w64-x86_64-qt6-base \ + mingw-w64-x86_64-qt6-declarative \ + mingw-w64-x86_64-qt6-tools \ + mingw-w64-x86_64-qt6-shadertools \ + mingw-w64-x86_64-qt6-svg \ + mingw-w64-x86_64-cmake \ + mingw-w64-x86_64-ninja \ + mingw-w64-x86_64-uchardet \ + mingw-w64-x86_64-quazip \ + mingw-w64-x86_64-djvulibre \ + mingw-w64-x86_64-libwpd +``` + +Verify the installation: + +```bash +qmake6 --version +gcc --version +cmake --version +``` + +**Step 4 — Clone the repository** + +```bash +git clone https://github.com/your-org/asteria-qt.git +cd asteria-qt +``` ## Building +All build commands run in the **MSYS2 MINGW64** shell on Windows, or a regular terminal on Linux. No extra CMake flags are needed on Windows — MSYS2 installs everything to a standard prefix that CMake finds automatically. + ### Command Line ```bash -# Debug build (Linux — Qt6 found automatically after running install script) -cmake -B build -DCMAKE_BUILD_TYPE=Debug +# Debug build +cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug cmake --build build --parallel # Release build -cmake -B build-release -DCMAKE_BUILD_TYPE=Release +cmake -B build-release -G Ninja -DCMAKE_BUILD_TYPE=Release cmake --build build-release --parallel # Run tests @@ -80,7 +128,7 @@ ctest --test-dir build --output-on-failure ```bash ./build/asteria-qt # Linux -./build/asteria-qt.exe # Windows +./build/asteria-qt.exe # Windows (run from MSYS2 MINGW64 shell) ``` ### CLion @@ -89,27 +137,19 @@ ctest --test-dir build --output-on-failure 2. CLion auto-detects `CMakeLists.txt` and configures 3. Select a CMake profile (Debug/Release) in Settings → Build, Execution, Deployment → CMake 4. Build: `Ctrl+F9` / `⌘F9` | Run: `Shift+F10` / `⌃R` -5. On Windows: set `CMAKE_PREFIX_PATH` to your Qt install path in the CMake profile options field +5. On Windows: set the toolchain to use MSYS2's MinGW (`C:\msys64\mingw64\bin\gcc.exe`) under Settings → Build, Execution, Deployment → Toolchains; leave GDB set to **Bundled** — MSYS2's GDB is newer than CLion supports ### VSCode 1. Install extensions: **C/C++**, **CMake Tools** 2. Open the project root -3. CMake Tools detects `CMakeLists.txt` automatically; select a kit (GCC on Linux, MSVC on Windows) -4. On Windows, add to `.vscode/settings.json`: - ```json - { - "cmake.configureArgs": [ - "-DCMAKE_PREFIX_PATH=C:\\Qt\\6.x.x\\msvc2022_64", - "-DCMAKE_TOOLCHAIN_FILE=C:\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake" - ] - } - ``` +3. CMake Tools detects `CMakeLists.txt` automatically +4. On Windows: when prompted to select a kit, choose the MSYS2 MinGW64 GCC kit (points to `C:\msys64\mingw64\bin\gcc.exe`) 5. Build: `Ctrl+Shift+B` | Run: `F5` (with `launch.json`) or CMake Tools' Run button ### Qt Creator 1. File → Open File or Project → select `CMakeLists.txt` -2. Configure the kit (Qt 6 kit must be registered under Edit → Preferences → Kits) -3. Build: `Ctrl+B` / `⌘B` | Run: `Ctrl+R` / `⌘R` -4. On Windows: ensure the Qt 6 MSVC kit is selected +2. Configure the kit under Edit → Preferences → Kits +3. On Windows: add a kit pointing to MSYS2's Qt (`C:\msys64\mingw64`) and MinGW compiler +4. Build: `Ctrl+B` / `⌘B` | Run: `Ctrl+R` / `⌘R` diff --git a/scripts/install-deps-windows.ps1 b/scripts/install-deps-windows.ps1 deleted file mode 100644 index ab6e3ba..0000000 --- a/scripts/install-deps-windows.ps1 +++ /dev/null @@ -1,70 +0,0 @@ -# Install all development dependencies for asteria-qt on Windows. -# Requires: winget (Windows 10 1709+) and an internet connection. -# Run in an elevated (Administrator) PowerShell session. -# -# After running this script you must add Qt to your PATH / CMAKE_PREFIX_PATH. -# The default Qt install path is: C:\Qt\6.x.x\msvc2022_64\ - -#Requires -RunAsAdministrator -Set-StrictMode -Version Latest -$ErrorActionPreference = 'Stop' - -# ── Build tools ──────────────────────────────────────────────────────────────── -Write-Host "Installing build tools..." -ForegroundColor Cyan - -# Visual Studio Build Tools 2022 (C++ compiler, MSBuild) -winget install --id Microsoft.VisualStudio.2022.BuildTools --silent --override ` - "--wait --quiet --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended" - -# CMake -winget install --id Kitware.CMake --silent - -# Ninja -winget install --id Ninja-build.Ninja --silent - -# Git -winget install --id Git.Git --silent - -# ── Qt 6 ─────────────────────────────────────────────────────────────────────── -Write-Host "" -Write-Host "Qt 6 cannot be installed via winget in a fully unattended way." -ForegroundColor Yellow -Write-Host "Install it manually using the Qt Online Installer:" -ForegroundColor Yellow -Write-Host " https://www.qt.io/download-open-source" -ForegroundColor Cyan -Write-Host "" -Write-Host "In the installer, select Qt 6.7+ and check these components:" -ForegroundColor Yellow -Write-Host " - MSVC 2022 64-bit" -Write-Host " - Qt PDF" -Write-Host " - Qt Quick / Qt Declarative (included by default)" -Write-Host " - Qt SVG" -Write-Host " - Qt Shader Tools" -Write-Host "" -Write-Host "After installing, set CMAKE_PREFIX_PATH in your build commands:" -ForegroundColor Yellow -Write-Host ' cmake -B build -DCMAKE_PREFIX_PATH="C:\Qt\6.7.0\msvc2022_64"' -ForegroundColor Cyan - -# ── vcpkg (for third-party C++ libs) ────────────────────────────────────────── -Write-Host "" -Write-Host "Installing vcpkg for third-party libraries..." -ForegroundColor Cyan - -$vcpkgDir = "C:\vcpkg" -if (-not (Test-Path $vcpkgDir)) { - git clone https://github.com/microsoft/vcpkg.git $vcpkgDir - & "$vcpkgDir\bootstrap-vcpkg.bat" -disableMetrics -} else { - Write-Host "vcpkg already present at $vcpkgDir" -ForegroundColor Green -} - -# ── Third-party libraries via vcpkg ─────────────────────────────────────────── -Write-Host "" -Write-Host "Installing third-party libraries via vcpkg (x64-windows)..." -ForegroundColor Cyan - -$vcpkg = "$vcpkgDir\vcpkg.exe" -& $vcpkg install ` - uchardet:x64-windows ` - quazip:x64-windows ` - minizip:x64-windows ` - djvulibre:x64-windows ` - libwpd:x64-windows - -Write-Host "" -Write-Host "Done. Add vcpkg toolchain to your CMake configure command:" -ForegroundColor Green -Write-Host " -DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake" -ForegroundColor Cyan diff --git a/scripts/install-deps-windows.sh b/scripts/install-deps-windows.sh new file mode 100644 index 0000000..4367f72 --- /dev/null +++ b/scripts/install-deps-windows.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Install all dependencies for asteria-qt on Windows via MSYS2. +# Run this script from the MSYS2 MINGW64 shell: +# bash scripts/install-deps-windows.sh + +set -euo pipefail + +echo "Installing Qt 6 and dependencies via pacman..." + +pacman -S --needed \ + mingw-w64-x86_64-gcc \ + mingw-w64-x86_64-zlib \ + mingw-w64-x86_64-qt6-base \ + mingw-w64-x86_64-qt6-declarative \ + mingw-w64-x86_64-qt6-tools \ + mingw-w64-x86_64-qt6-shadertools \ + mingw-w64-x86_64-qt6-svg \ + mingw-w64-x86_64-cmake \ + mingw-w64-x86_64-ninja \ + mingw-w64-x86_64-uchardet \ + mingw-w64-x86_64-quazip \ + mingw-w64-x86_64-djvulibre \ + mingw-w64-x86_64-libwpd + +echo "" +echo "Done. Verify with:" +echo " qmake6 --version" +echo " gcc --version" +echo " cmake --version"