# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit cmake xdg

if [[ ${PV} == 9999 ]]; then
    KEYWORDS=""
    EGIT_REPO_URI="https://gitlab.com/ubports/development/apps/${PN}.git"
    inherit git-r3
else
    KEYWORDS="~amd64"
    SRC_URI="https://gitlab.com/ubports/development/apps/${PN}/-/archive/v${PV}/${PN}-v${PV}.tar.gz"
fi

DESCRIPTION="<DESCRIPTION>"
HOMEPAGE="https://gitlab.com/ubports/development/apps/${PN}"

LICENSE="GPL-3"
SLOT="0"
RESTRICT="test"

# 'libreoffice-bin' doesn't contains needed include files
# TODO: check 'LibreOfficeKit' package provided by Lomiri.
#       It's may an alternative to full-fledged libreoffice build
DEPEND="
    dev-qt/qtgui:5
    app-text/poppler[qt5]
    app-office/libreoffice
"

RDEPEND="${DEPEND}"

BDEPEND="
    dev-build/cmake
    dev-build/cmake-extras
    dev-build/samurai
    dev-qt/qtdeclarative:5
"

S="${WORKDIR}/${PN}-v${PV}"

PATCHES=(
    "${FILESDIR}"/001-cmake-fix-quality.patch
)

src_prepare() {
    eapply_user

    # remove ctest from the build
    sed -i '/enable_testing()/d' CMakeLists.txt || die
    sed -i '/add_subdirectory(tests)/d' CMakeLists.txt || die

    cmake_src_prepare
}

src_configure() {
    local mycmakeargs=(
        -DINSTALL_TESTS="OFF"
        -DCLICK_MODE="OFF"
    )

    cmake_src_configure
}

pkg_postinst() {
    xdg_pkg_postinst
    #gnome2_schemas_update
}

pkg_postrm() {
    xdg_pkg_postrm
    #gnome2_schemas_update
}