# Contributor: Marian Buschsieweke <marian.buschsieweke@posteo.net>
# Contributor: Aiden Grossman <agrossman154@yahoo.com>
# Maintainer:
pkgname=vtk
pkgver=9.3.0
pkgrel=4
pkgdesc="A software system for 3D computer graphics, image processing and visualization"
url="https://vtk.org/"
# s390x blocked by netcdf
arch="all !s390x"
license="BSD-3-Clause"
depends_dev="
	boost-dev
	curl-dev
	doxygen
	ffmpeg-dev
	gdal-dev
	glew-dev
	hdf5-dev
	jpeg-dev
	libaec-dev
	libpng-dev
	libxml2-dev
	netcdf-dev
	openmpi-dev
	pdal-dev
	proj-dev
	qt5-qtbase-dev
	qt5-qttools-dev
	qt5-qtx11extras-dev
	sqlite-dev
	tk-dev
	unixodbc-dev
	zlib-dev
	"
makedepends="$depends_dev
	cmake
	samurai
	"
checkdepends="
	xvfb-run
	mesa-dri-gallium
	"
subpackages="$pkgname-doc $pkgname-dev"
source="
	https://www.vtk.org/files/release/${pkgver%.*}/VTK-$pkgver.tar.gz
	https://www.vtk.org/files/release/${pkgver%.*}/VTKData-$pkgver.tar.gz
	https://www.vtk.org/files/release/${pkgver%.*}/VTKLargeData-$pkgver.tar.gz
	disable-tests.patch
	lfs64.patch
	unistd.patch
	loongarch64.patch
	"
builddir="$srcdir/VTK-$pkgver"

case "$CARCH" in
# Tests on RISC-V should be re-enabled when llvmpipe has proper RISC-V support.
# cf. https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26018
riscv64|loongarch64) options="$options !check" ;;
esac

build() {
	CXXFLAGS="$CXXFLAGS -DLOGURU_STACKTRACES=0" \
	cmake -B build -G Ninja \
		-Wno-dev \
		-DCMAKE_SKIP_INSTALL_RPATH=ON \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=ON \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DVTK_USE_LARGE_DATA=ON \
		-DVTK_PYTHON_VERSION="3" \
		-DVTK_CUSTOM_LIBRARY_SUFFIX="" \
		-DCMAKE_BUILD_TYPE=Release \
		-DVTK_MODULE_USE_EXTERNAL_VTK_hdf5=ON \
		-DVTK_MODULE_USE_EXTERNAL_VTK_libproj=ON \
		-DVTK_MODULE_USE_EXTERNAL_VTK_netcdf=ON \
		-DVTK_BUILD_TESTING="$(want_check && echo ON || echo OFF)"
	cmake --build build
}

check() {
	xvfb-run -a ctest \
		--rerun-failed \
		--output-on-failure \
		-E 'FiltersCoreCxx-TestFeatureEdges' \
		--test-dir ./build
}

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

sha512sums="
2722dc8186779df1af5c534f26b20186ea33cb3bca2cef8cb333542b12e738382616e26e8d4d0341cb98c30403f8a896d77ddb04adb07e26d0d548c4a34b7d2f  VTK-9.3.0.tar.gz
385d609c2adc1746c073690b58a3fc25e496946c03f08e6c9e0a69ee406cee447e66d267986c3e5ba9006dd1cb0015b68134bb3c375ae41aef8f3b1e0d923d51  VTKData-9.3.0.tar.gz
d87eb0fb4ce27ae9f4363c54bb711e66c5d2dbcdf508cb5fae9fcc1574407df2816f29d20037297b834440cd8a54fcf8e1d6db14700054f057bff2fe48404d33  VTKLargeData-9.3.0.tar.gz
87e2c4377251d4a4b173fa44d2e4305bfd865a389c50395502869eefd82624942083a5d2d8907a8b6b788b161fefe5b0ab46034c1ed00a23c0accc06b9390590  disable-tests.patch
ec8d73f9fa425c4ad4caa9031e656ecb2d89db7ea31df0fa029ef45dc832b76557b4fef306d2c40ca8694b4bad8f37c0c8672face34728f1bcc764c6df039c6b  lfs64.patch
e814f5d8edc72d868b0209c878702b83723f46215ec1d681058c23c33ed16d6f9a917932705fb37afe8a8915c42bcb639fb2beb553ec103f0a85a08463771668  unistd.patch
3914161f70bca79b438e8aba2f9c3185702ea7c251c1280b275188babb3254a60ab78953307cb93eb1d43060cf44cb3c5ce2f325573ba6df6864420f349e1206  loongarch64.patch
"
