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

_realname=meshoptimizer
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.24
pkgrel=1
pkgdesc="Mesh optimization library that makes meshes smaller and faster to render (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://meshoptimizer.org/"
msys2_repository_url="https://github.com/zeux/meshoptimizer"
msys2_references=()
license=("spdx:MIT")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/zeux/meshoptimizer/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('af5f6bc410e2df9f0f80dce1f1d77ff55f53dc08c17fdc07e58367b613c27603')

build() {
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      -DMESHOPT_BUILD_DEMO=OFF \
      -DMESHOPT_BUILD_SHARED_LIBS=ON \
      -DMESHOPT_BUILD_GLTFPACK=ON \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

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

package() {
  cd "${srcdir}"

  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE.md \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
