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

EAPI=8

inherit lomiri

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

DESCRIPTION="D-Bus service for out of process thumbnailing"
HOMEPAGE="https://gitlab.com/ubports/development/core/${PN}"
LICENSE="GPL-3"
SLOT="0"
RESTRICT="test mirror"

DEPEND="
    dev-cpp/persistent-cache-cpp
    dev-libs/boost
    dev-libs/glib
    dev-qt/qtconcurrent
    lomiri-base/lomiri-api
    media-libs/libexif
    media-plugins/gst-plugins-taglib
    sys-libs/libapparmor
"

RDEPEND="${DEPEND}"

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

PATCHES=(
    "${FILESDIR}"/001-fix-template-id-cdtor-error.patch
    "${FILESDIR}"/002-boost-1.90-remove-obsolate-system-component.patch
)

src_prepare() {
    eapply_user

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

    # remove 'valgrind' check
    sed -i "/find_program(MEMORYCHECK_COMMAND NAMES valgrind)/,/endif()/d" CMakeLists.txt || die


    lomiri_src_prepare
}

src_configure() {
    local mycmakeargs=(
        -Dskip-dbus-tests="OFF"
        -DENABLE_DOC="OFF"
        -DWerror="OFF"
    )

    lomiri_src_configure
}

src_install() {
    lomiri_src_install

    # fix "QA Notice" installing to '/usr/etc'
    # package installs to "${CMAKE_INSTALL_SYSCONFDIR}" which shall be '/etc' by default.
    # not sure if it's an bug by Gentoo or by cmake
    if [[ -d "${D}/usr/etc" ]]; then
        mv "${D}/usr/etc" "${D}/etc"
    fi
}