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

_realname=cgal
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=6.1
pkgrel=1
pkgdesc="Computational Geometry Algorithms Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.cgal.org/"
msys2_repository_url="https://github.com/CGAL/cgal"
msys2_references=(
  'archlinux: cgal'
  "cpe: cpe:/a:cgal:computational_geometry_algorithms_library"
  'gentoo: sci-mathematics/cgal'
)
license=("spdx:CC0-1.0 AND BSL-1.0 AND MIT AND LGPL-3.0-or-later AND GPL-3.0-or-later")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-eigen3"
         "${MINGW_PACKAGE_PREFIX}-gmp"
         "${MINGW_PACKAGE_PREFIX}-mpfr")
optdepends=("${MINGW_PACKAGE_PREFIX}-qt6-svg: for CGAL_Qt6"
            "${MINGW_PACKAGE_PREFIX}-qt6-script: for CGAL_Qt6"
            "${MINGW_PACKAGE_PREFIX}-tbb: for some packages, see the CGAL manual")
source=(https://github.com/CGAL/cgal/releases/download/v${pkgver}/CGAL-${pkgver}.tar.xz)
sha256sums=('618da8a8b3f5be46b4f0a47a1efb3c9e6c03d6aab0f5531d56d355d32701d79f')

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 \
      -G"Ninja" \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${_extra_config[@]}" \
      -DCGAL_ENABLE_TESTING=OFF \
      ../CGAL-${pkgver}

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

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

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

  install -Dm644 $srcdir/CGAL-${pkgver}/LICENSE -t "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
  install -Dm644 $srcdir/CGAL-${pkgver}/LICENSE.* -t "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
  install -Dm644 $srcdir/CGAL-${pkgver}/LICENSES/* -t "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
}
