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

_realname=json
_pkgname=nlohmann-json
pkgbase=mingw-w64-${_pkgname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_pkgname}"
pkgver=3.9.1
pkgrel=1
pkgdesc="JSON for Modern C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/nlohmann/json"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
conflicts=("${MINGW_PACKAGE_PREFIX}-nlohmann_json")
provides=("${MINGW_PACKAGE_PREFIX}-nlohmann_json")
replaces=("${MINGW_PACKAGE_PREFIX}-nlohmann_json")
options=('staticlibs' '!strip' '!buildflags')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/nlohmann/json/archive/v${pkgver}.tar.gz")
sha256sums=('4cf0df69731494668bdd6460ed8cb269b68de9c19ad8c27abc24cd72605b2d5b')

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${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 \
    -DJSON_BuildTests=ON \
    -DJSON_Install=ON \
    ../${_realname}-${pkgver}

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  make test
}

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

  make DESTDIR=${pkgdir} install
}
