# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: AlexWMF <alexxwmf@gmail.com>

_realname=qxmpp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.11.3
pkgrel=1
pkgdesc="Cross-platform C++ XMPP client and server library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('spdx:LGPL-2.1-or-later')
url="https://invent.kde.org/libraries/qxmpp"
msys2_changelog_url='https://invent.kde.org/libraries/qxmpp/-/blob/master/CHANGELOG.md'
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-qt6-base"
         "${MINGW_PACKAGE_PREFIX}-qca-qt6")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://invent.kde.org/libraries/qxmpp/-/archive/v${pkgver}/qxmpp-v${pkgver}.tar.gz")
sha256sums=('b94af16d0bc560357fb43d15d9b1fc98232b06f0a8cd3412df23dbf948c244cb')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    -DBUILD_TESTS=OFF \
    -DBUILD_EXAMPLES=OFF \
    -DQT_VERSION_MAJOR=6 \
    ../${_realname}-v${pkgver}

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

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

  install -d "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}
  install -Dm644 "${srcdir}"/${_realname}-v${pkgver}/LICENSES/* -t "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/
}
