# Maintainer: Aleksandr Serbin <aleksandr.serbin@gmail.com>

_realname=amqp-cpp
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.3.27
pkgrel=1
pkgdesc="C++ library for asynchronous non-blocking communication with RabbitMQ (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/CopernicaMarketingSoftware/AMQP-CPP"
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=(https://github.com/CopernicaMarketingSoftware/AMQP-CPP/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz
        001-cmake-install-config.patch)
sha256sums=('af649ef8b14076325387e0a1d2d16dd8395ff3db75d79cc904eb6c179c1982fe'
            '236787a1151b097cf5584cbbdb9882c9a3507b87168a4671ea54690f3144ee33')

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

build() {
  msg "Build static library"
  mkdir -p "${srcdir}/build-${MSYSTEM}-static" && cd "${srcdir}/build-${MSYSTEM}-static"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DAMQP-CPP_BUILD_SHARED=OFF \
    -DAMQP-CPP_LINUX_TCP=OFF \
    "../${_realname}-${pkgver}"

  cmake --build .

  msg "Build shared library"
  mkdir -p "${srcdir}/build-${MSYSTEM}-shared" && cd "${srcdir}/build-${MSYSTEM}-shared"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DAMQP-CPP_BUILD_SHARED=ON \
    -DAMQP-CPP_LINUX_TCP=OFF \
    "../${_realname}-${pkgver}"

  cmake --build .
}

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

  cd "${srcdir}/build-${MSYSTEM}-shared"
  DESTDIR="${pkgdir}" cmake --install .

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
