# Maintainer: yumetodo <yume-wikijp@live.jp>

_realname=tl-expected
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.3.1
pkgrel=1
pkgdesc="C++11/14/17 std::expected with functional-style extensions (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/TartanLlama/expected'
msys2_references=(
  'anitya: 112689'
  'archlinux: tl-expected'
  'gentoo: dev-cpp/expected'
)
license=('spdx:CC0-1.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/TartanLlama/expected/archive/v${pkgver}/expected-v${pkgver}.tar.gz")
sha256sums=('9a04f4f472fbb5c30bf60402f1ca626c4a76987f867978d0b8a35d7ab3fb8fe7')

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_CXX_STANDARD=17 \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DEXPECTED_BUILD_TESTS=OFF \
    -DEXPECTED_BUILD_PACKAGE=OFF \
    ../expected-${pkgver}

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

check() {
  cd "build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/cmake -DEXPECTED_BUILD_TESTS=ON ../expected-${pkgver}
  ${MINGW_PREFIX}/bin/cmake --build .
  ./tests
}

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

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

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