# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=libkml
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.0
pkgrel=11
pkgdesc="Reference implementation of OGC KML 2.2 (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/libkml/libkml/"
license=('spdx:BSD-3-Clause')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-boost"
             #"${MINGW_PACKAGE_PREFIX}-python"
             #"${MINGW_PACKAGE_PREFIX}-swig"
             )
depends=("${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-minizip"
         "${MINGW_PACKAGE_PREFIX}-uriparser"
         "${MINGW_PACKAGE_PREFIX}-zlib")
#optdepends=("${MINGW_PACKAGE_PREFIX}-python"
#            "${MINGW_PACKAGE_PREFIX}-swig")
source=("https://github.com/libkml/libkml/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-libkml-1.3.0.patch"
        "002-resolve-conflicts-with-system-minizip.patch"
        "strptime.c")
sha256sums=('8892439e5570091965aaffe30b08631fdf7ca7f81f6495b4648f0950d7ea7963'
            '3692ee34904bbc2ba9a186df80e8d870162abf973151cb16715f26b752020875'
            '0a95ae7d92a584fe1a8bc93fa810a9b6b69e6e373ba10d51e1d86c836af5f885'
            'b698cc0438313d8d4c55770a25245a63052d667717cc03e6d3c0c0c5e56b72e6')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/001-libkml-1.3.0.patch"
  patch -Np1 -i "${srcdir}/002-resolve-conflicts-with-system-minizip.patch"
  cp -f ../strptime.c src/kml/base/contrib
}

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe -Wno-dev \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_CXX_STANDARD=14 \
    -DWITH_SWIG=OFF \
    -DWITH_PYTHON=OFF \
    "../${_realname}-${pkgver}"

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

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
