# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=qhull
pkgver=2020.2
pkgrel=3
pkgdesc="Calculate convex hulls and related structures"
url="https://www.qhull.org/"
arch="all"
license="custom"
makedepends="cmake samurai"
subpackages="
	$pkgname-static
	$pkgname-dev
	$pkgname-nonreentrant
	$pkgname-doc
	"
source="qhull-$pkgver.tar.gz::https://github.com/qhull/qhull/archive/$pkgver.tar.gz"

build() {
	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 \
		-DCMAKE_SKIP_INSTALL_RPATH=YES \
		$CMAKE_CROSSOPTS
	cmake --build build --target all libqhull
}

check() {
	cd build && ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	mv build/libqhull.so* "$pkgdir"/usr/lib/

	install -Dm644 $builddir/COPYING.txt $pkgdir/usr/share/licenses/$pkgname/LICENSE
}

nonreentrant() {
	amove usr/lib/libqhull.so.*
}

sha512sums="88f50c2a968f56deec61772490617cc877b0ca2d804954ade08297b9bab826076db6b960d6f1feb21c6851e5328cb11c6dd565666517fa78a3d65b901848ff36  qhull-2020.2.tar.gz"
