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

_realname=spdlog
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.8.5
pkgrel=2
pkgdesc='Very fast, header-only/compiled, C++ logging library (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/gabime/spdlog'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-fmt")
options=('staticlibs' '!strip' '!buildflags')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/gabime/spdlog/archive/v${pkgver}.tar.gz"
        "0001-fmt-8.0.1.patch")
sha256sums=('944d0bd7c763ac721398dca2bb0f3b5ed16f67cef36810ede5061f35a543b4b8'
            '7218a923e16436b6dd0cf0191b03d7fd0ade4b4741c5a309f8063841e20b4ba8')

prepare() {
  for p in ${srcdir}/*.patch; do
    patch --directory="${_realname}-${pkgver}" --forward --strip=1 <"$p"
  done
}

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 \
    -DSPDLOG_BUILD_BENCH=OFF \
    -DSPDLOG_BUILD_EXAMPLE=OFF \
    -DSPDLOG_BUILD_TESTS=ON \
    -DSPDLOG_FMT_EXTERNAL=ON \
    -DSPDLOG_BUILD_SHARED=ON \
    -DCMAKE_RUNTIME_OUTPUT_DIRECTORY="${srcdir}/build-${MINGW_CHOST}" \
    ../${_realname}-${pkgver}

  make
}

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

  make test
}

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

  make DESTDIR="${pkgdir}" install

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