# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=date
pkgbase=mingw-w64-chrono-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-chrono-${_realname}")
pkgver=3.0.4
pkgrel=1
pkgdesc="A date and time library based on the C++11/14/17 <chrono> header. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/HowardHinnant/date'
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-curl")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/HowardHinnant/date/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-fix-install-cmake-files.patch"
        "002-add-pkgconfig-file.patch")
sha256sums=('56e05531ee8994124eeb498d0e6a5e1c3b9d4fccbecdf555fe266631368fb55f'
            'd0189e1c2a092b84d2907588545b77b9ed73573e64e718bfc81c6a899e17f361'
            '869f1b1d9292aa94b2c939788a853092ae98b58f21120eb7f9dbadab36449582')

prepare() {
  cd "${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}"/001-fix-install-cmake-files.patch
  patch -Np1 -i "${srcdir}"/002-add-pkgconfig-file.patch
}

build() {
  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=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      -DCMAKE_DLL_NAME_WITH_SOVERSION=ON \
      -DBUILD_TZ_LIB=ON \
      -DENABLE_DATE_TESTING=OFF \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

  cmake --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE.txt \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/chrono-${_realname}/LICENSE
}
