# Maintainer: Bruno Pagani <archange@archlinux.org>
# Maintainer: Carl Smedstad <carsme@archlinux.org>

_pkgname=CGNS
pkgname=cgns
pkgver=4.5.1
pkgrel=1
pkgdesc="Standard for recording and recovering computer data associated with the numerical solution of fluid dynamics equations"
arch=(x86_64 aarch64)
url="https://cgns.github.io/"
license=(Zlib)
depends=(
  gcc-libs
  glibc
  glu
  hdf5
  libglvnd
  libx11
  libxmu
  tcl
  tk
)
makedepends=(
  cmake
  gcc-fortran
)
source=("https://github.com/$_pkgname/$_pkgname/archive/v$pkgver/$pkgname-$pkgver.tar.gz"
        "4b930bd00e83d2ff5404748dc04cb75f420f99e9.patch"
        "7031287c2a5adb9b5cdc8e4be23aba79c487db28.patch")
sha512sums=('f0a3f82824d81e2db4c992fc41e91c53158898fbf0b342c0c857e5e3f02d081df3822035b9eb558fe12c48ce36e4123810adc11f9b85e60e76e7de7f35a56162'
            'SKIP'
            'SKIP')

prepare() {
  cd ${_pkgname}-${pkgver}
  patch -Np1 -i "${srcdir}/4b930bd00e83d2ff5404748dc04cb75f420f99e9.patch"
  patch -Np1 -i "${srcdir}/7031287c2a5adb9b5cdc8e4be23aba79c487db28.patch"
}

build() {
  cmake -B build -S ${_pkgname}-${pkgver} \
    -DCMAKE_BUILD_TYPE=None \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -Wno-dev \
    -DCGNS_BUILD_CGNSTOOLS=ON \
    -DCGNS_BUILD_SHARED=ON \
    -DCGNS_ENABLE_64BIT=ON \
    -DCGNS_ENABLE_FORTRAN=ON \
    -DCGNS_ENABLE_HDF5=ON \
    -DCGNS_ENABLE_LEGACY=ON \
    -DCGNS_ENABLE_SCOPING=OFF \
    -DCGNS_ENABLE_TESTS=ON \
    -DCMAKE_SKIP_RPATH=ON
  cmake --build build
}

check() {
  LD_LIBRARY_PATH="$srcdir/build/src" \
    ctest --test-dir build --output-on-failure
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" $_pkgname-$pkgver/license.txt
  # Remove broken .desktop files
  rm "$pkgdir/usr/bin/"*.desktop
}
