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

_realname=qxmpp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.2
pkgrel=1
pkgdesc="Cross-platform C++ XMPP client and server library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=("LGPL")
url="https://github.com/qxmpp-project/qxmpp"
depends=("${MINGW_PACKAGE_PREFIX}-libtheora"
         "${MINGW_PACKAGE_PREFIX}-libvpx"
         "${MINGW_PACKAGE_PREFIX}-opus"
         "${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-speex")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc")
options=(!strip staticlibs)
source=("${_realname}-${pkgver}".tar.gz::"https://github.com/qxmpp-project/${_realname}/archive/v${pkgver}.tar.gz"
        001-fix-install.patch)
sha256sums=('016e23c40c604dd43b15e1888e31d48729d0f80775fb6f7faef1130a52fe0641'
            '9b44f5c0301ede3c83f2213edb1a158abf835aebeedcbc19806acb4ffcfa9564')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-fix-install.patch
}

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

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    -DBUILD_SHARED_LIBS=ON \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install
  
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE.LGPL ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.LGPL
}
