# SPDX-FileCopyrightText: 2024 Jasem Mutlaq <mutlaqja@ikarustech.com>
#                         2025 Scarlett Moore <sgmoore@kde.org>
#
# SPDX-License-Identifier: CC0-1.0
---
name: kstars
version: 3.7.5
confinement: strict
base: core24
adopt-info: kstars

apps:
    kstars:
        extensions:
        - kde-neon-6
        common-id: org.kde.kstars.desktop
        desktop: usr/share/applications/org.kde.kstars.desktop
        command: usr/bin/kstars
        plugs:
        - home
        - opengl
        - network
        - network-bind
        - unity7
        - joystick
        - pulseaudio
        - serial-port
        - camera
        - gpio
        - gpio-control
        - location-observe
        - hardware-observe
        - hidraw
        - i2c
        - password-manager-service
        - location-control
        - location-observe
        - raw-usb
        - desktop
slots:
    session-dbus-interface:
        interface: dbus
        name: org.kde.kstars
        bus: session
package-repositories:
  - type: apt
    components:
      - main
    suites:
      - noble
    key-id: 444DABCF3667D0283F894EDDE6D4736255751E5D
    url: http://origin.archive.neon.kde.org/user
    key-server: keyserver.ubuntu.com
parts:
  stellarsolver:
    source: https://github.com/rlancaste/stellarsolver.git
    plugin: cmake
    build-packages:
      - libcfitsio-dev
      - libgsl-dev
      - wcslib-dev
    stage-packages:
      - rsync
      - libpopt0
    cmake-parameters:
      - -DCMAKE_INSTALL_PREFIX=/usr
      - -DCMAKE_BUILD_TYPE=Release
      - -DQT_MAJOR_VERSION=6
      - -DBUILD_WITH_QT6=ON
      - -DUSE_QT5=OFF
      - -DBUILD_TESTING=OFF
      - -DCMAKE_INSTALL_SYSCONFDIR=/etc
      - -DCMAKE_INSTALL_LOCALSTATEDIR=/var
      - -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON
      - -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF
      - -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON
      - -DCMAKE_INSTALL_RUNSTATEDIR=/run
      - -DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=ON
      - -DCMAKE_VERBOSE_MAKEFILE=ON
      - -DCMAKE_INSTALL_LIBDIR=lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR
      - --log-level=STATUS
      - -DCMAKE_LIBRARY_PATH=lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR
      - -DCMAKE_MODULE_PATH=$CRAFT_STAGE/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/cmake
      - "-DCMAKE_FIND_ROOT_PATH=$CRAFT_STAGE\\;/snap/kde-qt6-core22-sdk/current\\;/snap/kf6-core22-sdk/current/usr"
    override-stage: |
        craftctl default
        rsync -a --ignore-existing $CRAFT_PART_INSTALL/ /
    prime:
      - -usr/bin/rsync

  kstars:
    after:
      - stellarsolver
    parse-info:
      - usr/share/metainfo/org.kde.kstars.appdata.xml
    plugin: cmake
    source: .
    source-type: local
    cmake-parameters:
      - -DCMAKE_INSTALL_PREFIX=/usr
      - -DCMAKE_BUILD_TYPE=Release
      - -DQT_MAJOR_VERSION=6
      - -DBUILD_WITH_QT6=ON
      - -DBUILD_QT5=OFF
      - -DBUILD_TESTING=OFF
      - -DCMAKE_INSTALL_SYSCONFDIR=/etc
      - -DCMAKE_INSTALL_LOCALSTATEDIR=/var
      - -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON
      - -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF
      - -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON
      - -DCMAKE_INSTALL_RUNSTATEDIR=/run
      - -DCMAKE_SKIP_INSTALL_ALL_DEPENDENCY=ON
      - -DCMAKE_VERBOSE_MAKEFILE=ON
      - -DCMAKE_INSTALL_LIBDIR=lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR
      - --log-level=STATUS
      - -DCMAKE_LIBRARY_PATH=lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR
    build-environment:
      - CMAKE_FIND_ROOT_PATH: "${CMAKE_FIND_ROOT_PATH}:$CRAFT_STAGE"
      - LD_LIBRARY_PATH: "$CRAFT_STAGE/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR:/snap/kde-qt6-core24-sdk/current/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/libproxy:${LD_LIBRARY_PATH}"
    build-packages:
      - libeigen3-dev
      - zlib1g-dev
      - libcfitsio-dev
      - libnova-dev
      - libgsl-dev
      - libindi-dev
      - wcslib-dev
      - libraw-dev
      - libxkbcommon-dev
      - libcurl4-gnutls-dev
    stage-packages:
      - astrometry.net
      - indi-bin
      - xplanet
      - libcfitsio10t64
      - libnova-0.16-0
      - libgsl27
      - libpgsbox8
      - libwcs8
      - libraw23t64
      - libxkbcommon0
      - libcurl3t64-gnutls
    prime:
      - -usr/lib/*/cmake/*
      - -usr/include/*
      - -usr/share/ECM/*
      - -usr/share/man/*
      - -usr/bin/X11
      - -usr/lib/gcc/$CRAFT_ARCH_TRIPLET_BUILD_FOR/6.0.0
      - -usr/lib/aspell/*
      - -usr/share/lintian
  gpu-2404:
    after: [kstars]
    source: https://github.com/canonical/gpu-snap.git
    plugin: dump
    override-prime: |
      craftctl default
      ${CRAFT_PART_SRC}/bin/gpu-2404-cleanup mesa-2404
    prime:
      - bin/gpu-2404-wrapper
  cleanup:
    after:
      - kstars
    plugin: nil
    build-snaps:
      - core24
      - kf6-core24
    override-prime: |
      set -eux
      for snap in "core24" "kf6-core24"; do
        cd "/snap/$snap/current" && find . -type f,l -exec rm -rf "${CRAFT_PRIME}/{}" \;
      done
