# Maintainer: Jakub Klinkovský <lahwaacz at archlinux dot org>

pkgname=viskores
pkgver=1.0.0
pkgrel=2
pkgdesc="A visualization library for many-threaded devices"
arch=(x86_64 aarch64)
url="https://github.com/Viskores/viskores"
license=(LicenseRef-viskores)
depends=(
  gcc-libs
  glibc
  onetbb
  openmpi libmpi.so
)
makedepends=(
  cmake
  ninja
)
source=(
  $pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz
  fix-cstdint-header.patch
)
b2sums=('dae93e7ff63fcc79eca16df7281c7ffb9ef9e4e66c78d33303c5e1c73c7c6f9a41904ef8f4a3143699c33a68e38cb4b5efd1dc47674e24616238bf38458f6085'
        '0857b6efc636c663a853241b92a3e9c6b3089387bb7bf137f6e8f107d0c968a99e4bc5f7f60d43716d5e7bfeef151de41e4c169f02cd35ae01a07995d2943bf6')

prepare() {
  cd $pkgname-$pkgver
  # https://github.com/Viskores/viskores/pull/129
  patch -p1 -i ../fix-cstdint-header.patch
}

build() {
  local cmake_options=(
    -B build
    -S $pkgname-$pkgver
    -G Ninja
    -W no-dev
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_INSTALL_PREFIX=/usr
    # make sure the options are compatible with VTK requirements
    # https://gitlab.kitware.com/vtk/vtk/-/blob/master/ThirdParty/viskores/vtkviskores/CMakeLists.txt
    -D Viskores_ENABLE_OPENMP=ON
    -D Viskores_ENABLE_TBB=ON
    -D Viskores_ENABLE_MPI=ON
    -D Viskores_USE_DEFAULT_TYPES_FOR_VTK=ON
    # do not install in versioned subdirectories
    -D Viskores_INSTALL_INCLUDE_DIR=include
    -D Viskores_INSTALL_CONFIG_DIR=lib/cmake/viskores
    -D Viskores_INSTALL_SHARE_DIR=share/viskores
  )
  cmake "${cmake_options[@]}"
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -vDm 644 $pkgname-$pkgver/LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
