# Maintainer: Anatol Pomozov
# Maintainer: Carl Smedstad <carsme@archlinux.org>
# Contributor: Dave Reisner <dreisner@archlinux.org>
# Contributor: Antony Male <antony dot male at geemail dot com>>

pkgname=snappy
pkgver=1.2.2
pkgrel=2.2
pkgdesc='A fast compressor/decompressor library'
arch=('x86_64' 'aarch64')
url="https://github.com/google/snappy"
license=('BSD-3-Clause')
depends=(
  'gcc-libs'
  'glibc'
)
makedepends=(
  'clang'
  'cmake'
  'git'
  'gtest'
)
checkdepends=('zlib')
provides=('libsnappy.so')
source=(
  "git+https://github.com/google/snappy.git#tag=${pkgver}"
  "snappy.pc.in"
  "$pkgname-cmake_add_pkgconfig.patch"
  "$pkgname-use_system_gtest.patch"
  "$pkgname-reenable_rtti.patch"
)
sha256sums=('6cc4304fc850b9878709c6da48490c8929929aa5befda2966981cea78059ba6d'
            '134f06ca0584a1026538d0fb972fc141c008390ecae1806184b721eca1abbc75'
            '2a204d7d35509ffc290d80c641fcb7e8488c67ca550aa1695493cff12c53156b'
            '50b31b45511e8907f1319305c102f37631b0fbe509f862b612e70073383658e4'
            '6ff6970d2a1961aed375a8e5098bf3b7340ff86fe60aff4483dec3400f273372')

prepare() {
  cd $pkgname
  cp ../snappy.pc.in .
  patch -Np1 < ../$pkgname-cmake_add_pkgconfig.patch # https://bugs.archlinux.org/task/71246
  patch -Np1 < ../$pkgname-use_system_gtest.patch
  patch -Np1 < ../$pkgname-reenable_rtti.patch
}

build() {
  cmake -S $pkgname -B build \
    -D CMAKE_BUILD_TYPE=None \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -W no-dev \
    -DCMAKE_CXX_STANDARD=23 \
    -DBUILD_SHARED_LIBS=ON \
    -DSNAPPY_BUILD_BENCHMARKS=OFF
  cmake --build build
}

check() {
  cmake --build build --target test
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" $pkgname/COPYING
}
