# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Lukas Jirkovsky <l.jirkovsky@gmail.com>

pkgname=embree
pkgver=4.3.2
pkgrel=1
pkgdesc="Collection of high-performance ray tracing kernels"
arch=('x86_64' 'aarch64')
url="https://embree.github.io/"
license=('Apache')
depends=('gcc-libs' 'glibc' 'intel-tbb')
makedepends=('cmake' 'ispc' 'freeglut' 'libxmu' 'ninja')
source=(https://github.com/embree/embree/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha256sums=('dc7bb6bac095b2e7bc64321435acd07c6137d6d60e4b79ec07bb0b215ddf81cb')

build() {
    # Embree detects actual ISA at runtime but we have to set a high maximum
    # buildtime version as it would otherwise default to the builder processor.
    cmake \
      -B build \
      -G Ninja \
      -S ${pkgname}-${pkgver} \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DCMAKE_BUILD_TYPE=Release \
      -DEMBREE_ISPC_SUPPORT=ON \
      -DEMBREE_TUTORIALS=OFF \
      -DEMBREE_MAX_ISA="AVX512SKX" \
      -DEMBREE_BACKFACE_CULLING=OFF
    ninja -C build
    # Maybe enable these later once they are out of beta:
      # -DEMBREE_SYCL_SUPPORT=ON \
      # -DEMBREE_SYCL_LARGEGRF=ON
}

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

    mkdir "${pkgdir}"/usr/bin/
    mv "${pkgdir}"/usr/embree-vars.* "${pkgdir}"/usr/bin/
}
