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

EAPI=8

inherit cmake

DESCRIPTION="A compiler wrapper that caches compilation results for faster recompilation"
HOMEPAGE="https://gitlab.com/bits-n-bites/buildcache"
SRC_URI="https://gitlab.com/bits-n-bites/buildcache/-/archive/v${PV}/${PN}-v${PV}.tar.gz -> ${P}.tar.gz"
S="${WORKDIR}/${PN}-v${PV}"

LICENSE="zlib" #"MIT"
SLOT="0"
KEYWORDS="~amd64 ~arm64 ~x86"
IUSE="doc lz4 test"
RESTRICT="!test? ( test )"

BDEPEND="
	virtual/pkgconfig
	doc? ( app-text/doxygen )
	test? ( dev-cpp/gtest )
"

DEPEND="
	app-arch/zstd:=
	sys-libs/zlib:=
	lz4? ( app-arch/lz4:= )
"
RDEPEND="${DEPEND}"

src_prepare() {
	cd "${S}"
	mv ./src/* ./

	epatch "${FILES}/00.test.patch"

	default
	cmake_src_prepare
}

src_configure() {
	local mycmakeargs=(
#		-DBUILDCACHE_ENABLE_LZ4=$(usex lz4)
#		-DBUILDCACHE_ENABLE_LZFSE=OFF  # macOS-only
#		-DBUILDCACHE_ENABLE_TESTS=$(usex test)
		-DBUILD_SHARED_LIBS=ON
	)
	cmake_src_configure
}
