_realname=soapysdr
_pkgname=SoapySDR
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.8.1
_gitver=soapy-sdr-$pkgver
pkgrel=1
pkgdesc="Vendor and platform neutral SDR support library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/pothosware/SoapySDR"
license=('spdx:BSL-1.0')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-python")
source=($url/archive/$_gitver/$_pkgname-$pkgver.tar.gz
        001-cmake-install-path.patch)
sha256sums=('a508083875ed75d1090c24f88abef9895ad65f0f1b54e96d74094478f0c400e6'
            '110c55a27efac2375a72a9140b21d6d41faf744951efb624db64b7854bfa8a80')

prepare() {
  cd "${srcdir}"/$_pkgname-$_gitver

  patch -Np2 -i "${srcdir}"/001-cmake-install-path.patch
}

build() {
  cd "${srcdir}"/$_pkgname-$_gitver

  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.exe \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -GNinja \
      ../$_pkgname-$_gitver

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

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

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