# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmailcom>

_realname=CLI11
pkgbase=mingw-w64-${_realname,,}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname,,}")
pkgver=2.6.1
pkgrel=1
pkgdesc="Command line parser for C++11 (mingw-w64)"
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/CLIUtils/CLI11"
msys2_references=(
  'archlinux: cli11'
  'gentoo: dev-cpp/cli11'
)
license=(spdx:BSD-3-Clause)
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=(${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz)
noextract=("${_realname}-${pkgver}.tar.gz")
sha256sums=('377691f3fac2b340f12a2f79f523c780564578ba3d6eaf5238e9f35895d5ba95')

prepare() {
  rm -rf ${_realname}-${pkgver}
  tar -xzf ${_realname}-${pkgver}.tar.gz || true
}

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

  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=" \
  ${MINGW_PREFIX}/bin/cmake \
    -Wno-dev \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    ${extra_config[@]} \
    -DCLI11_BUILD_TESTS=OFF \
    -DCLI11_BUILD_EXAMPLES=OFF \
    ../${_realname}-${pkgver}

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

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

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