# Maintainer: Andrew Udvare <audvare@gmail.com>

_realname=bpmdetect
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.8.9
pkgrel=1
pkgdesc="Automatic BPM detection utility."
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/Tatsh/bpmdetect'
msys2_repository_url='https://github.com/Tatsh/bpmdetect'
msys2_references=(
  "gentoo: media-sound/bpmdetect"
)
license=('spdx:GPL-3.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-ffmpeg"
  "${MINGW_PACKAGE_PREFIX}-qt6-base"
  "${MINGW_PACKAGE_PREFIX}-qt6-multimedia"
  "${MINGW_PACKAGE_PREFIX}-soundtouch"
  "${MINGW_PACKAGE_PREFIX}-zlib"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-extra-cmake-modules"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
  "${MINGW_PACKAGE_PREFIX}-qt6-tools"
)
source=("https://github.com/Tatsh/${_realname}/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('50432f5d488666dc998e75cbe0ff889d3ef6087c2981c5bcd8090425c6e3a295')

build() {
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -DCMAKE_BUILD_TYPE=Release \
      -DFHS=ON \
      -G Ninja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

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

check() {
  cmake -DBUILD_TESTS=ON -S ../${_realname}-${pkgver} -B "build-${MSYSTEM}" -DCMAKE_BUILD_TYPE=Debug
  cmake --build "build-${MSYSTEM}-Debug" --config Debug
  ctest --test-dir "build-${MSYSTEM}-Debug" --output-on-failure || true
}

package() {
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}/bin/cmake" --install "build-${MSYSTEM}" --config Release
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE.txt" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.txt"
}
