# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=pdal
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.9.2
pkgrel=1
pkgdesc="A C++ library for translating and manipulating point cloud data (mingw-w64)"
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.pdal.io"
msys2_repository_url="https://github.com/PDAL/PDAL"
msys2_references=(
  'anitya: 138228'
  'archlinux: pdal'
  'gentoo: sci-libs/pdal'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-gdal"
         "${MINGW_PACKAGE_PREFIX}-libgeotiff"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-proj"
         "${MINGW_PACKAGE_PREFIX}-xz"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-zstd")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-draco"
             "${MINGW_PACKAGE_PREFIX}-hdf5"
             "${MINGW_PACKAGE_PREFIX}-postgresql"
             "${MINGW_PACKAGE_PREFIX}-tiledb")
optdepends=("${MINGW_PACKAGE_PREFIX}-draco: Draco plugin, Read data in the draco format"
            "${MINGW_PACKAGE_PREFIX}-hdf5: HDF plugin, read data in the HDF format"
            "${MINGW_PACKAGE_PREFIX}-postgresql: PostgreSQL PointCloud plugin, read/write PostgreSQL PointCloud objects"
            "${MINGW_PACKAGE_PREFIX}-tiledb: TileDB plugin, read/write data from TileDB")
source=("https://github.com/PDAL/PDAL/releases/download/${pkgver}/PDAL-${pkgver}-src.tar.bz2")
sha256sums=('a74bbc7f4e4f709ed589dbbb851926a63c391c974e3fc40a4c3ff34f7923021b')

build() {
  mkdir -p "${srcdir}"/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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  "${MINGW_PREFIX}"/bin/cmake.exe \
    -Wno-dev \
    -GNinja \
    "${_extra_config[@]}" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DBUILD_SHARED_LIBS=ON \
    -DCMAKE_DLL_NAME_WITH_SOVERSION=ON \
    -DWITH_TESTS=OFF \
    -DBUILD_PLUGIN_DRACO=ON \
    -DBUILD_PLUGIN_HDF=ON \
    -DBUILD_PLUGIN_ICEBRIDGE=ON \
    -DBUILD_PLUGIN_PGPOINTCLOUD=ON \
    -DBUILD_PLUGIN_TILEDB=ON \
    -DWITH_BACKTRACE=OFF \
    -DWITH_LZMA=ON \
    ../PDAL-${pkgver}-src

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

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

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