# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=lib3mf
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.4.1
pkgrel=2
pkgdesc='Lib3MF is the reference implementation of the 3D Manufacturing Format file standard https://3mf.io/ (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://3mf.io/'
msys2_repository_url='https://github.com/3MFConsortium/lib3mf'
msys2_references=(
  "cpe: cpe:/a:3mf:lib3mf"
)
license=('spdx:BSD-2-Clause')
depends=(
  "${MINGW_PACKAGE_PREFIX}-cc-libs"
  "${MINGW_PACKAGE_PREFIX}-libzip"
  "${MINGW_PACKAGE_PREFIX}-zlib"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf")
source=("https://github.com/3MFConsortium/lib3mf/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-lib3mf-cmake-fix-linking-function.patch"
        "0002-lib3mf-include-algorithm.patch")
sha256sums=('081dea66ddd1b958644bfac0fe9a580e63726061459efce5190a10161082f8f7'
            '4613080dd0b2004f0c80bb88260d3f9e85ecc86b7228ca4f63f389ab12cc9eff'
            'a683054fb9aea20388c2afdbc31a92f290e710016ac49a85d5d578fd92f62776')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-lib3mf-cmake-fix-linking-function.patch"
  patch -p1 -i "${srcdir}/0002-lib3mf-include-algorithm.patch"
}

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

  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 \
    -DLIB3MF_TESTS=OFF \
    -DUSE_INCLUDED_ZLIB=OFF \
    -DUSE_INCLUDED_LIBZIP=OFF \
    -DUSE_INCLUDED_SSL=OFF \
    ../${_realname}-${pkgver}

  cmake --build .
}

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