# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=cgal
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.2
pkgrel=1
pkgdesc="Computational Geometry Algorithms Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.cgal.org/"
license=("LGPL, GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-eigen3"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-qt5")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-gmp"
         "${MINGW_PACKAGE_PREFIX}-mpfr")
optdepends=("${MINGW_PACKAGE_PREFIX}-eigen3: for some packages, see the CGAL manual"
            "${MINGW_PACKAGE_PREFIX}-qt5: for CGAL_Qt5"
            "${MINGW_PACKAGE_PREFIX}-intel-tbb: for some packages, see the CGAL manual")
source=(https://github.com/CGAL/cgal/releases/download/v${pkgver}/CGAL-${pkgver}.tar.xz)
sha256sums=('744c86edb6e020ab0238f95ffeb9cf8363d98cde17ebb897d3ea93dac4145923')

prepare() {
  plain 'No Step'
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
      -G"MSYS Makefiles" \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_BUILD_TYPE=Release \
      ../CGAL-${pkgver}

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

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --build . --target install
}
