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

_realname=liborigin
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.0.3
pkgrel=1
pkgdesc="A library for reading OriginLab OPJ project files. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://sourceforge.net/projects/liborigin/'
msys2_repository_url="https://sourceforge.net/p/liborigin/git/ci/master/tree/"
msys2_references=(
  'archlinux: liborigin'
)
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://downloads.sourceforge.net/project/liborigin/liborigin/${pkgver%.*}/liborigin-$pkgver.tar.gz")
sha256sums=('b394e3bf633888f9f4a3e1449d7c7eb39b778a2e657424177a04cde4afe6965a')

build() {
  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 \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      -DCMAKE_DLL_NAME_WITH_SOVERSION=ON \
      "${_extra_config[@]}" \
      -B build-${MSYSTEM} \
      -S ${_realname}-${pkgver}

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

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

  "${MINGW_PREFIX}"/bin/ctest
}

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

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