# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=simvoleon
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.1.0
pkgrel=1
pkgdesc="A volume rendering library for Coin (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/coin3d/simvoleon"
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-coin")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-graphviz"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
options=('!strip' '!buildflags')
source=("${url}/archive/${_realname}-${pkgver}/${_realname}-${_realname}-${pkgver}.tar.gz"
        "https://raw.githubusercontent.com/coin3d/coincodeshare/2504f60/gl/CoinGLPerformance."{h,cpp}
        '0001-simvoleon-2.1.0-use-cpack-off.patch')
sha256sums=('ab3402cb1afe9842c43d26c33b08a25b4e114db243c27f63b2c87269555f81c5'
            'e6bc455e3ac3f92ca07157ec3b67a33377480f9edf184fc40ab56fbef96b0760'
            '377409159032c1c84c77ebdfdedca84fad8b0899f560669bb0a98a72352c4382'
            '23bdbe0bd84ce7a65704e6471f453912aab8b7a531bbb20450318c408028d882')

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

  mkdir -p "lib/VolumeViz/Coin/gl"
  cp -t "lib/VolumeViz/Coin/gl" "${srcdir}/CoinGLPerformance."{h,cpp}

  patch -p1 -i "${srcdir}/0001-simvoleon-2.1.0-use-cpack-off.patch"
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  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=" \
  "${MINGW_PREFIX}"/bin/cmake.exe \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "${extra_config[@]}" \
    -DSIMVOLEON_BUILD_DOCUMENTATION=ON \
    -DSIMVOLEON_BUILD_TESTS=OFF \
    -DSIMVOLEON_EXTRA_LDFLAGS=-lSIMVoleon \
    -DSIMVOLEON_EXTRA_CFLAGS=-DSIMVOLEON_DLL \
    ../${_realname}-${_realname}-${pkgver}

  "${MINGW_PREFIX}"/bin/cmake.exe --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .

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

# vim:set ts=2 sw=2 et:
