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

_realname=json
_pkgname=nlohmann-json
pkgbase=mingw-w64-${_pkgname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_pkgname}"
pkgver=3.12.0
pkgrel=1
pkgdesc="JSON for Modern C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/nlohmann/json"
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
options=('!strip' '!buildflags')
source=("https://github.com/nlohmann/json/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('4b92eb0c06d10683f7447ce9406cb97cd4b453be18d7279320f7b2f025c10187')

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

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

  cmake --build ./
}

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

  ctest ./ || true
}

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

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

  install -vDm644 "${srcdir}/${_realname}-${pkgver}/LICENSE.MIT" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.MIT"
}
