# Maintainer (ArchLinux): Andrea Scarpino <andrea@archlinux.org>
# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>

_realname=extra-cmake-modules
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.83.0
pkgrel=1
pkgdesc='Extra CMake modules (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://projects.kde.org/projects/kdesupport/extra-cmake-modules'
license=('LGPL')
groups=("${MINGW_PACKAGE_PREFIX}-kf5")
depends=("${MINGW_PACKAGE_PREFIX}-cmake"
         "${MINGW_PACKAGE_PREFIX}-png2ico")
makedepends=("${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-requests")
source=("https://download.kde.org/stable/frameworks/${pkgver%.*}/${_realname}-${pkgver}.tar.xz"{,.sig}
        "set-AUTOSTATICPLUGINS.patch")
sha256sums=('72b7f3b3917f3208fff10f0402b0fa3a65815aca924f0f94a4f96383d8e0f81e'
            'SKIP'
            'a246d25065ac7472b3a4e5995b3c6cb32081ffa21c7de7455006398431e6c886')
validpgpkeys=('53E6B47B45CEA3E0D5B7457758D0EE648A48B3BB') # David Faure <faure@kde.org>

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/set-AUTOSTATICPLUGINS.patch"
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_HTML_DOCS=OFF \
    -DBUILD_QTHELP_DOCS=OFF \
    -DBUILD_TESTING=OFF \
    ../${_realname}-${pkgver}

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

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