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

_pkgname=CGNS
pkgname=cgns
pkgver=4.5.1
pkgrel=2
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=(
  glibc
  glu
  hdf5
  libgcc
  libgfortran
  libglvnd
  libx11
  libxmu
  tcl
  tk
)
makedepends=(
  cmake
  gcc-fortran
)
source=("https://github.com/$_pkgname/$_pkgname/archive/v$pkgver/$pkgname-$pkgver.tar.gz")
sha512sums=('f0a3f82824d81e2db4c992fc41e91c53158898fbf0b342c0c857e5e3f02d081df3822035b9eb558fe12c48ce36e4123810adc11f9b85e60e76e7de7f35a56162')

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
}
