# Maintainer: Felix Xing (Felixaszx) <felixaszx@outlook.com>

_realname=fastgltf
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.9.0
pkgrel=1
pkgdesc="fastgltf is a speed and usability focused glTF 2.0 library written in modern C++17 with minimal dependencies (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/spnda/fastgltf"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-simdjson")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/spnda/${_realname}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('0bb564e127b14c22f062db50f89381dd2e0a20dbaf4987ca138a4ae8728712f9')

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

   MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      -B "build-${MSYSTEM}"

  cmake --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" cmake --install "${_realname}-${pkgver}/build-${MSYSTEM}"
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE.md \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
