# Maintainer: Francis Giraldeau <francis.giraldeau@nrc-cnrc.gc.ca>

_realname=cgns
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.2.0
pkgrel=1
pkgdesc="CFD General Notation System library and tools (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://cgns.github.io"
license=('zlib')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-hdf5")
source=("${_realname}-${pkgver}.tar.gz"::https://github.com/CGNS/CGNS/archive/v${pkgver}.tar.gz)
sha256sums=('090ec6cb0916d90c16790183fc7c2bd2bd7e9a5e3764b36c8196ba37bf1dc817')

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

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCGNS_ENABLE_HDF5=ON \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}-${pkgver}

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

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

  # license
  install -D -m644 ${srcdir}/${_realname}-${pkgver}/license.txt \
  ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
