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

_realname=GSL
pkgbase=mingw-w64-microsoft-${_realname,,}
pkgname=("${MINGW_PACKAGE_PREFIX}-microsoft-${_realname,,}")
pkgver=4.2.0
pkgrel=1
pkgdesc="Guidelines Support Library (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/Microsoft/GSL'
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/Microsoft/GSL/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('2c717545a073649126cb99ebd493fa2ae23120077968795d2c69cbab821e4ac6')

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[@]}" \
      -DGSL_TEST=OFF \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

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

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

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