# Contributor: Kreijstal <rainb@tfwno.gf>

_realname=nng
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.11
pkgrel=2
pkgdesc="A lightweight, broker-less library (mingw-w64)"
arch=('any')
mingw_arch=( 'ucrt64' 'clang64' 'clangarm64')
url='https://nng.nanomsg.org/'
msys2_repository_url='https://github.com/nanomsg/nng'
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-wolfssl")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/nanomsg/nng/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('12aaff6f8f183ba0fec378af8620c47cf4be6da975d016ec6cdec2fbac0d3534')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-CMAKE_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 \
      -DNNG_ENABLE_TLS=ON \
      -DNNG_TLS_ENGINE=wolf \
      -DNNG_ENABLE_DOC=OFF \
      -DNNG_TESTS=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/${_realname}/LICENSE
}
