# Maintainer: Rafal Brzegowy <rafal.brzegowy@yahoo.com>

_realname=precice
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.2.1
pkgrel=1
pkgdesc='Fully Parallel Library for Multi-Physics Surface Coupling (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
	 "${MINGW_PACKAGE_PREFIX}-eigen3"
	 "${MINGW_PACKAGE_PREFIX}-msmpi")
makedepends=("${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-libxml2"
             "${MINGW_PACKAGE_PREFIX}-eigen3"
	     "${MINGW_PACKAGE_PREFIX}-msmpi"
	     "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cmake")
license=('LGPL')
url='https://www.precice.org'
source=(https://github.com/precice/precice/archive/v${pkgver}.tar.gz)
sha256sums=('BCA8CEDFB5C86656E4FDFACA5CB982B861F9ABA926538FA4411BC0D015E09C1F')

build() {
  #Static Build
  [[ -d "${srcdir}/build-${MINGW_CHOST}-static" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}-static"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}-static" && cd "${srcdir}/build-${MINGW_CHOST}-static"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_CXX_STANDARD_LIBRARIES=-lws2_32 \
      -DBUILD_SHARED_LIBS=OFF \
      -DCMAKE_BUILD_TYPE=Release \
      -DPRECICE_MPICommunication=ON \
      -DPRECICE_PETScMapping=OFF \
      -DPRECICE_PythonActions=OFF \
      ../${_realname}-${pkgver}

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

  #Shared Build
  [[ -d "${srcdir}/build-${MINGW_CHOST}-shared" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}-shared"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}-shared" && cd "${srcdir}/build-${MINGW_CHOST}-shared"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_CXX_STANDARD_LIBRARIES=-lws2_32 \
      -DBUILD_SHARED_LIBS=ON \
      -DCMAKE_BUILD_TYPE=Release \
      -DPRECICE_MPICommunication=ON \
      -DPRECICE_PETScMapping=OFF \
      -DPRECICE_PythonActions=OFF \
      ../${_realname}-${pkgver}

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

package() {
  #Static Install
  cd "${srcdir}/build-${MINGW_CHOST}-static"
  DESTDIR=${pkgdir} cmake --build . --target install	

  #Shared Install
  cd "${srcdir}/build-${MINGW_CHOST}-shared"
  DESTDIR=${pkgdir} cmake --build . --target install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}

# vim: ts=2 sw=2 et:
