# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
# Maintainer: Christian Heusel <gromit@archlinux.org>
# Contributor: Aleksandar Trifunović <akstrfn at gmail dot com>

pkgname=abseil-cpp
pkgver=20240722.1
pkgrel=1
pkgdesc="Collection of C++ library code designed to augment the C++ standard library"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url='https://abseil.io'
license=('Apache-2.0')
depends=('gcc-libs' 'glibc' 'gtest')
makedepends=('cmake')
source=("https://github.com/abseil/abseil-cpp/archive/$pkgver/$pkgname-$pkgver.tar.gz"
         scoped-mock-log.patch)
sha256sums=('40cee67604060a7c8794d931538cb55f4d444073e556980c88b6c49bb9b19bb7'
            'a6cbc612a2b96fcbd52d081e03e8581107ceb4827edb19d96510a31c568e1396')

prepare() {
  cd "$srcdir/$pkgname-$pkgver"
  patch -p1 -i ../scoped-mock-log.patch # Install target needed by protobuf
}

build() {
  cd "$srcdir/$pkgname-$pkgver"

  case "${CARCH}" in
    powerpc) CXXFLAGS+=' -latomic' ;;
  esac

  cmake -Bbuild \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DCMAKE_CXX_FLAGS="${CXXFLAGS} -DNDEBUG" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_CXX_STANDARD=17 \
    -DBUILD_SHARED_LIBS=ON \
    -DABSL_BUILD_TEST_HELPERS=ON \
    -DABSL_USE_EXTERNAL_GOOGLETEST=ON \
    -DABSL_FIND_GOOGLETEST=ON \
    -DABSL_BUILD_TESTING=ON
  cd build
  cmake --build . --target all
}

check() {
  cd "$srcdir/$pkgname-$pkgver/build"
  ctest
}

package() {
  cd "$srcdir/$pkgname-$pkgver/build"
  DESTDIR="$pkgdir" cmake --install .
}
