# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=crc32c
pkgver=1.1.2
pkgrel=1
pkgdesc="CRC32C implementation with support for CPU-specific acceleration instructions"
url="https://github.com/google/crc32c"
arch="all"
license="BSD-3-Clause"
makedepends="cmake samurai"
checkdepends="benchmark-dev glog-dev gtest-dev"
subpackages="$pkgname-dev"
source="crc32c-$pkgver.tar.gz::https://github.com/google/crc32c/archive/$pkgver.tar.gz
	10-third-party.patch"

build() {
	# Workaround to compile against glog 0.7.0+
	export CXXFLAGS="$CXXFLAGS -DGLOG_USE_GLOG_EXPORT"
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DCRC32C_BUILD_TESTS="$(want_check && echo ON || echo OFF)" \
		-DCRC32C_BUILD_BENCHMARKS="$(want_check && echo ON || echo OFF)" \
		-DCRC32C_USE_GLOG="$(want_check && echo ON || echo OFF)" \
		-DCRC32C_INSTALL=ON \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
	./crc32c_bench
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}
sha512sums="
6325c52b5a6850b9f90086e0c0c86798c008af36e7cfd3a0216184a2d37b3bf7323481ddc6bfe4cbd5b31288b3ee6c69772d03085a13094cf95d00a9756a7196  crc32c-1.1.2.tar.gz
1f83e03d53271ee65a21e04c57392313003227a71a8c6de1fcf6c5d9041eaeb3cd08a9d4b86a610b80c06589cd06d36ae5e224d109256300b05fa65d638beddb  10-third-party.patch
"
