# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=sexpp
pkgver=0.9.0
pkgrel=0
pkgdesc="S-Expressions parser and generator library in C++"
url="https://github.com/rnpgp/sexpp"
arch="all"
license="MIT"
makedepends="cmake samurai"
checkdepends="gtest-dev"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-cli
	"
source="https://github.com/rnpgp/sexpp/archive/v$pkgver/sexpp-$pkgver.tar.gz"

build() {
	_build build-shared -DBUILD_SHARED_LIBS=ON
	_build build-static -DBUILD_SHARED_LIBS=OFF
}

_build() {
	local outdir="$1"; shift

	local crossopts=
	[ "$CBUILD" != "$CHOST" ] \
		&& crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"

	cmake -B "$outdir" -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DDOWNLOAD_GTEST=OFF \
		-DWITH_SEXP_CLI=ON \
		-DWITH_SEXP_TESTS="$(want_check && echo ON || echo OFF)" \
		$crossopts \
		"$@"
	cmake --build "$outdir"
}

check() {
	ctest --test-dir build-shared --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build-static
	DESTDIR="$pkgdir" cmake --install build-shared
}

cli() {
	pkgdesc="S-Expressions parser and generator utility"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/bin
}

sha512sums="
89728b6900406c9831f0b49842f3ffc687cdef4716b4865c2342031f6afa6801a6d0fafab887f9da58e73a11f8c86a40842522741c17ba38bb0c723a58fe5461  sexpp-0.9.0.tar.gz
"
