# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Baptiste Jonglez <baptiste--aur at jonglez dot org>

pkgname=opendht
epoch=1
pkgver=3.5.1
pkgrel=3
pkgdesc="C++17 Distributed Hash Table (DHT) implementation"
arch=(x86_64)
url="https://github.com/savoirfairelinux/opendht"
license=(GPL3)
depends=(glibc gnutls nettle readline argon2 jsoncpp libjsoncpp.so fmt openssl llhttp)
makedepends=(git cmake msgpack-cxx restinio asio cython python-setuptools gcc14)
checkdepends=(cppunit)
optdepends=('python: to use the Python bindings'
            'msgpack-cxx: linking against opendht')
source=(git+${url}#tag=v$pkgver)
sha256sums=('fd1c6349b61e4d95ba7904d8c41603a516c5f631b6dbf527166217b73a494cb3')

prepare() {
  cd $pkgname
  git cherry-pick -n daf2f8edafc82e031deedbf8e0ed3e66a551fb60 # Fix build of jami-daemon
}

build() {
  cmake -B build -S ${pkgname} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DOPENDHT_DOCUMENTATION=OFF \
    -DOPENDHT_TESTS=ON \
    -DOPENDHT_SYSTEMD=ON \
    -DOPENDHT_SYSTEMD_UNIT_FILE_LOCATION=/usr/lib/systemd/system/ \
    -DOPENDHT_INDEX=ON \
    -DOPENDHT_PYTHON=ON \
    -DOPENDHT_HTTP=ON \
    -DOPENDHT_PROXY_SERVER=ON \
    -DOPENDHT_PROXY_CLIENT=ON \
    -DOPENDHT_PUSH_NOTIFICATIONS=ON \
    -DCMAKE_CXX_COMPILER=g++-14 # Segfaults with GCC 15 https://github.com/savoirfairelinux/opendht/issues/752
  make -C build
}

check() {
  # https://github.com/savoirfairelinux/opendht/issues/568
  make -C build test || echo "Tests failed"
}

package() {
  make -C build DESTDIR="${pkgdir}" install
}
