# Copyright 1999-2026 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/lib-cpp/${PN}.git"
    inherit git-r3
else
    KEYWORDS="~amd64"
    SRC_URI="https://gitlab.com/ubports/development/core/lib-cpp/${PN}/-/archive/${PV}/${P}.tar.gz"
fi

DESCRIPTION="Cache of key-value pairs with persistent storage for C++ 11"
HOMEPAGE="https://gitlab.com/ubports/development/core/${PN}"
LICENSE="LGPL-3"

DEPEND="
    dev-libs/boost
    dev-libs/leveldb
"

RDEPEND="${DEPEND}"

BDEPEND="
    dev-build/cmake
    dev-build/cmake-extras
    dev-build/samurai
"

PATCHES=(
    "${FILESDIR}"/002-fix-install-path.patch
    "${FILESDIR}"/003-fix-maybe-uninitialized-warning.patch
)

src_prepare() {
    # disable valgrid
    sed -i "/configure_file(CTestCustom.cmake.in/,/endif()/d" CMakeLists.txt  || die

    # disable tests
    sed -i "/include(CTest)/d" CMakeLists.txt  || die
    cmake_comment_add_subdirectory tests

    # disable coverage report
    sed -i "/find_package(CoverageReport)/d" CMakeLists.txt  || die
    sed -i "/enable_coverage_report(/,/)/d" CMakeLists.txt  || die

    # disable docs
    cmake_comment_add_subdirectory docs
    sed -i '/find_package(DoxygenBuilder)/,/DESTINATION share\/doc\/${LIBNAME})/d' CMakeLists.txt || die

    # disable examples
    cmake_comment_add_subdirectory examples

    lomiri_src_prepare
}