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

_realname=collada-dom
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.5.0
pkgrel=8
pkgdesc="API that provides a C++ object representation of a COLLADA XML instance document (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/rdiankov/collada-dom/"
license=("spdx:MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-boost")
depends=("${MINGW_PACKAGE_PREFIX}-boost-libs"
         "${MINGW_PACKAGE_PREFIX}-uriparser"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-minizip"
         "${MINGW_PACKAGE_PREFIX}-zlib")
source=("https://github.com/rdiankov/${_realname}/archive/v${pkgver}/${_realname}.${pkgver}.tar.gz"
        001-mingw-w64-fix.patch
        002-fix-build-with-boost-1.85.patch::https://github.com/rdiankov/collada-dom/pull/43.patch)
sha256sums=('3be672407a7aef60b64ce4b39704b32816b0b28f61ebffd4fbd02c8012901e0d'
            '8469ebf0a5f6309d29a073117cac995324b99ec62a09e2b9501282c358d3fbd6'
            'd4880cd6d6119ca82425af9ad11d62490c07720d43fb50a75fa9d6b010646058')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/001-mingw-w64-fix.patch
  patch -p1 -i "${srcdir}"/002-fix-build-with-boost-1.85.patch
}

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

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

  CXXFLAGS+=" -Wno-deprecated-declarations" \
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
    "${_extra_config[@]}" \
    -DCMAKE_CXX_STANDARD=14 \
    ../${_realname}-${pkgver}

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

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

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