## START: Set by rpmautospec
## (rpmautospec version 0.3.5)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 1;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

%bcond_with toolchain_clang

%if %{with toolchain_clang}
%global toolchain clang
%endif

%bcond_without build_tests
# tests not discoverable by ctest yet
%bcond_with check

%global forgeurl https://github.com/facebook/CacheLib
%global tag 2023.09.11.00
%global date %(echo %{tag} | sed -e 's|.00$||' | sed -e 's|\\.||g')
# disable forge macro snapinfo generation
# https://pagure.io/fedora-infra/rpmautospec/issue/240
%global distprefix %{nil}
%forgemeta

# see cachelib/allocator/CacheVersion.h's kCachelibVersion
%global major_ver 17

Name:           cachelib
Version:        %{major_ver}^%{date}
Release:        %autorelease
Summary:        Pluggable caching engine for scale high performance cache services

License:        Apache-2.0
URL:            %forgeurl
Source0:        %{url}/archive/v%{tag}/%{name}-%{tag}.tar.gz
# needed on EL8; its gtest does not come with cmake files
Patch100:       %{name}-find-gtest.patch
# Workaround for gcc issue (still needed on epel9 x86_64)
# https://bugzilla.redhat.com/show_bug.cgi?id=2108665
Patch200:         %{name}-workaround-gcc-epel9-x86_64-bz2108665.patch

ExclusiveArch:  x86_64 aarch64 ppc64le

BuildRequires:  cmake
%if %{with toolchain_clang}
BuildRequires:  clang
%else
BuildRequires:  gcc-c++
%endif
BuildRequires:  fbthrift-devel
BuildRequires:  fizz-devel
BuildRequires:  folly-devel
%if %{with build_tests}
BuildRequires:  gmock-devel
%endif
# this is actually needed, because of
# cachelib/navy/admission_policy/DynamicRandomAP.h
BuildRequires:  gtest-devel
BuildRequires:  libdwarf-devel
BuildRequires:  libzstd-devel
BuildRequires:  mvfst-devel
BuildRequires:  numactl-devel
BuildRequires:  wangle-devel
BuildRequires:  zlib-devel
BuildRequires:  tsl-sparse-map-devel
# BuildRequires:  libatomic


%global _description %{expand:
CacheLib is a C++ library providing in-process high performance caching
mechanism. CacheLib provides a thread safe API to build high throughput, low
overhead caching services, with built-in ability to leverage DRAM and SSD
caching transparently.}

%description %{_description}

%package devel
Summary:        %{summary}
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:       cmake

%description devel %{_description}

The %{name}-devel package contains libraries and header files for developing
applications that use %{name}.


%prep
%autosetup -n CacheLib-%{tag} -N
%autopatch -p1 -M 99
%if 0%{?el8}
%autopatch -p1 -m 100 -M 199
%endif
%ifarch x86_64
%if 0%{?el9}
%autopatch -p1 -m 200 -M 209
%endif
%endif


%build
pushd %{name}
%cmake \
%if %{with build_tests}
  -DBUILD_TESTS:BOOL=ON \
%else
  -DBUILD_TESTS:BOOL=OFF \
%endif
  -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=FALSE \
  -DCMAKE_INSTALL_DIR:PATH=%{_libdir}/cmake/%{name} \
  -DCONFIGS_INSTALL_DIR:STRING=%{_datadir}/%{name}/test_configs \
  -DINCLUDE_INSTALL_DIR:PATH=%{_includedir}/%{name} \
  -DCACHELIB_MAJOR_VERSION:STRING=%{major_ver} \
  -DPACKAGE_VERSION:STRING=%{major_ver}.%{date}
%cmake_build


%install
pushd %{name}
%cmake_install
%if %{with build_tests}
# TODO: prevent tests being installed
rm -rf %{buildroot}%{_prefix}/tests
%endif


%if %{with check}
%check
pushd %{name}
%ctest
%endif


%files
%license LICENSE
%doc BENCHMARKS.md CHANGELOG.md README.md examples
%{_bindir}/cachebench
%{_datadir}/%{name}
%{_libdir}/*.so.*

%files devel
%{_includedir}/%{name}
%{_libdir}/*.so
%{_libdir}/cmake/%{name}


%changelog
* Tue Sep 12 2023 Michel Lind <salimma@fedoraproject.org> - 17^20230911-1
- Update to 2023.09.11.00

* Fri Jul 07 2023 Michel Alexandre Salim <salimma@fedoraproject.org> - 17^20230703-1
- Update to 17^2023.07.03.00
- Properly bump major version
- Patch to support fmt 10 (fixes: rhbz#2219451)
- Use SPDX license identifier

* Wed Jun 28 2023 Vitaly Zaitsev <vitaly@easycoding.org> - 16^20230424-3
- Rebuilt due to fmt 10 update.

* Thu Apr 27 2023 Michel Alexandre Salim <salimma@fedoraproject.org> - 16^20230424-2
- Reapply GCC workaround for epel9 x86_64

* Tue Apr 25 2023 Michel Alexandre Salim <salimma@fedoraproject.org> - 16^20230424-1
- Update to 2023.04.24.00

* Wed Jan 18 2023 Fedora Release Engineering <releng@fedoraproject.org> - 16^20220314gitbd22b0e-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Sun Aug 28 2022 Mamoru TASAKA <mtasaka@fedoraproject.org> - 16^20220314gitbd22b0e-6
- drop patches no longer needed - fixed in gcc side

* Mon Aug 15 2022 Mamoru TASAKA <mtasaka@fedoraproject.org> - 16^20220314gitbd22b0e-5
- Add upstream gcc bugzilla reference, and remove the patch on F-38

* Thu Jul 21 2022 Michel Alexandre Salim <michel@michel-slm.name> - 16^20220314gitbd22b0e-4
- Rebuild for folly 2022.07.11.00

* Wed Jul 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 16^20220314gitbd22b0e-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Wed Jul 20 2022 Mamoru TASAKA <mtasaka@fedoraproject.org> - 16^20220314gitbd22b0e-2
- Workaround for gcc ICE with -Wclass-memaccess, enable ppc64le again, pull
  in upstream patch

* Tue Mar 15 2022 Michel Alexandre Salim <salimma@fedoraproject.org> - 16^20220314gitbd22b0e-1
- Update to snapshot from 20220314; remove patch working around thrift
  issue; enable aarch64 (resolves: rhbz#2036121); build tests

* Wed Mar 09 2022 Michel Alexandre Salim <salimma@fedoraproject.org> - 16^20220228git03dcb9b-3
- Use clang on releases with GCC 12

* Mon Feb 28 2022 Michel Alexandre Salim <salimma@fedoraproject.org> - 16^20220228git03dcb9b-2
- Add new patch and retire old merged patches

* Mon Feb 28 2022 Michel Alexandre Salim <salimma@fedoraproject.org> - 16^20220228git03dcb9b-1
- Update to snapshot from 20220228; use new-style versioning

* Fri Feb 25 2022 Michel Alexandre Salim <salimma@fedoraproject.org> - 16-4.20211220gitc4904ef
- Fix for finding gtest on EL8; exclude aarch64 instead of %%%%arm64

* Wed Jan 19 2022 Fedora Release Engineering <releng@fedoraproject.org> - 16-3.20211220gitc4904ef
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Wed Dec 29 2021 Michel Alexandre Salim <salimma@fedoraproject.org> - 16-2.20211220gitc4904ef
- Update to snapshot from 2021.12.20

* Wed Dec 29 2021 Michel Alexandre Salim <salimma@fedoraproject.org> - 16-1
- Initial Fedora package