File protobuf-opt.spec of Package protobuf-opt

#
# spec file for package protobuf
#
# Copyright (c) 2024 SUSE LLC
# Copyright (c) 2024 Andreas Stieger <Andreas.Stieger@gmx.de>
# Copyright (c) 2025 Dmitry Ivanov
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
#

%global sover 29_3_0
%global libver 29.3.0

# OpenSUSE Leap by default ships with gcc which is too old to build
# protobuf, so require gcc-13
%if 0%{?sle_version} == 150600 && 0%{?is_opensuse} && 0%{?gcc_version} < 13
%define with_gcc 13
%endif

# Disable generation of debuginfo package for Fedora >= 41
%if 0%{?fedora_version} >= 41
%global debug_package %{nil}
%endif

Name: protobuf-opt
Version: 29.3
Release: 0
Summary: Protocol Buffers - Google's data interchange format
License: BSD-3-Clause
Group: Development/Libraries/C and C++
URL: https://github.com/protocolbuffers/protobuf
Source0: %{name}-%{version}.tar.gz
Patch1: versionize-shlibs.patch
BuildRequires: bash
BuildRequires: binutils
BuildRequires: gcc%{?with_gcc}
BuildRequires: gcc%{?with_gcc}-c++
BuildRequires: cmake
BuildRequires: abseil-cpp-opt-devel

%if 0%{?fedora_version}
BuildRequires:  ninja-build
%else
BuildRequires:  ninja
%endif

# OpenSUSE Leap ships with gtest ang gmock which are too old to build
# protobuf tests, so require newer versions of these packages installed
# to /opt/googletest
%if 0%{?sle_version} == 150600 && 0%{?is_opensuse}
BuildRequires:  gtest-opt-devel
BuildRequires:  gmock-opt-devel
%else
BuildRequires:  gtest
BuildRequires:  gmock
%endif

%if 0%{?fedora_version}
BuildRequires: gtest-devel
BuildRequires: gmock-devel
%endif

ExclusiveArch: x86_64

%description
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package -n libprotobuf-opt-%{sover}
Summary: Protocol Buffers - Google's data interchange format
Group: System/Libraries

%description -n libprotobuf-opt-%{sover}
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package -n libprotoc-opt-%{sover}
Summary: Protocol Buffers - Google's data interchange format
Group: System/Libraries

%description -n libprotoc-opt-%{sover}
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package -n libprotobuf-lite-opt-%{sover}
Summary: Protocol Buffers - Google's data interchange format
Group: System/Libraries

%description -n libprotobuf-lite-opt-%{sover}
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package -n libutf8_range-opt-%{sover}
Summary: UTF-8 validation libraries from Protobuf
Group: System/Libraries

%description -n libutf8_range-opt-%{sover}
UTF-8 string validation library with optional SIMD acceleration (armv8a NEON,
SSE4 and AVX2).

%package devel
Summary: Header files, libraries and development documentation for %{name}
Group: Development/Libraries/C and C++
Requires: abseil-cpp-opt-devel
Requires: libprotobuf-opt-%{sover} = %{version}
Requires: libprotobuf-lite-opt-%{sover} = %{version}
Requires: libprotoc-opt-%{sover} = %{version}
Requires: libutf8_range-opt-%{sover} = %{version}
Provides: libprotobuf-opt-devel = %{version}

%description devel
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%prep
%autosetup -p1 -n %{name}-%{version}

%build

%if 0%{?with_gcc}
export CXX=g++-%{with_gcc}
export CC=gcc-%{with_gcc}
%endif

%define __builder ninja

%if 0%{?sle_version} == 150600 && 0%{?is_opensuse}
export LD_LIBRARY_PATH=/opt/abseil-cpp/%{_lib}:/opt/googletest/%{_lib} 
%cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_SKIP_INSTALL_RPATH=ON -DCMAKE_INSTALL_PREFIX=/opt/protobuf -Dprotobuf_ABSL_PROVIDER=package -Dprotobuf_BUILD_TESTS=ON -Dprotobuf_USE_EXTERNAL_GTEST=ON -DGTest_DIR=/opt/googletest/%{_lib}/cmake/GTest -Dabsl_DIR=/opt/abseil-cpp/%{_lib}/cmake/absl -Dprotobuf_BUILD_LIBUPB=OFF
%else
export LD_LIBRARY_PATH=/opt/abseil-cpp/%{_lib}
%cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_SKIP_INSTALL_RPATH=ON -DCMAKE_INSTALL_PREFIX=/opt/protobuf -Dprotobuf_ABSL_PROVIDER=package -Dprotobuf_BUILD_TESTS=ON -Dprotobuf_USE_EXTERNAL_GTEST=ON -Dabsl_DIR=/opt/abseil-cpp/%{_lib}/cmake/absl -Dprotobuf_BUILD_LIBUPB=OFF
%endif

%cmake_build

%check

# Skipping some tests which fail for unknown reason
export GTEST_FILTER="-FileDescriptorSetSource/EncodeDecodeTest*"

%if 0%{?sle_version} == 150600 && 0%{?is_opensuse}
export LD_LIBRARY_PATH=/opt/abseil-cpp/%{_lib}:/opt/googletest/%{_lib}
%else
export LD_LIBRARY_PATH=/opt/abseil-cpp/%{_lib}
%endif

%ctest

%install
%cmake_install

# manual ln that we could not manage to get into versionize-shlibs.patch
ln -s libutf8_range-%{libver}.so %{buildroot}/opt/protobuf/%{_lib}/libutf8_range.so
ln -s libutf8_validity-%{libver}.so %{buildroot}/opt/protobuf/%{_lib}/libutf8_validity.so

strip %{buildroot}/opt/protobuf/%{_lib}/libprotobuf-lite.so.%{libver}
strip %{buildroot}/opt/protobuf/%{_lib}/libprotobuf.so.%{libver}
strip %{buildroot}/opt/protobuf/%{_lib}/libprotoc.so.%{libver}
strip %{buildroot}/opt/protobuf/%{_lib}/libutf8_range-%{libver}.so
strip %{buildroot}/opt/protobuf/%{_lib}/libutf8_validity-%{libver}.so
strip %{buildroot}/opt/protobuf/bin/protoc-%{libver}

# SLE12 does not define this macro
%if %{undefined ldconfig_scriptlets}
%post -n libprotobuf-opt-%{sover} -p /sbin/ldconfig
%postun -n libprotobuf-opt-%{sover} -p /sbin/ldconfig
%post -n libprotoc-opt-%{sover} -p /sbin/ldconfig
%postun -n libprotoc-opt-%{sover} -p /sbin/ldconfig
%post -n libprotobuf-lite-opt-%{sover} -p /sbin/ldconfig
%postun -n libprotobuf-lite-opt-%{sover} -p /sbin/ldconfig
%post -n libutf8_range-opt-%{sover} -p /sbin/ldconfig
%postun -n libutf8_range-opt-%{sover} -p /sbin/ldconfig
%else
%ldconfig_scriptlets -n libprotobuf-opt-%{sover}
%ldconfig_scriptlets -n libprotoc-opt-%{sover}
%ldconfig_scriptlets -n libprotobuf-lite-opt-%{sover}
%ldconfig_scriptlets -n libutf8_range-opt-%{sover}
%endif

%files -n libprotobuf-opt-%{sover}
%defattr(-,root,root)
%dir /opt/protobuf
%dir /opt/protobuf/%{_lib}
/opt/protobuf/%{_lib}/libprotobuf.so.%{libver}

%files -n libprotoc-opt-%{sover}
/opt/protobuf/%{_lib}/libprotoc.so.%{libver}

%files -n libprotobuf-lite-opt-%{sover}
/opt/protobuf/%{_lib}/libprotobuf-lite.so.%{libver}

%files -n libutf8_range-opt-%{sover}
/opt/protobuf/%{_lib}/libutf8_range-%{libver}.so
/opt/protobuf/%{_lib}/libutf8_validity-%{libver}.so

%files devel
/opt/protobuf/bin/protoc*
%dir /opt/protobuf/bin
%dir /opt/protobuf/include
%dir /opt/protobuf/include/google
%dir /opt/protobuf/include/google/protobuf
%dir /opt/protobuf/include/google/protobuf/compiler
%dir /opt/protobuf/include/google/protobuf/compiler/cpp
%dir /opt/protobuf/include/google/protobuf/compiler/cpp/field_generators
%dir /opt/protobuf/include/google/protobuf/compiler/csharp
%dir /opt/protobuf/include/google/protobuf/compiler/java
%dir /opt/protobuf/include/google/protobuf/compiler/java/full
%dir /opt/protobuf/include/google/protobuf/compiler/java/lite
%dir /opt/protobuf/include/google/protobuf/compiler/kotlin
%dir /opt/protobuf/include/google/protobuf/compiler/objectivec
%dir /opt/protobuf/include/google/protobuf/compiler/php
%dir /opt/protobuf/include/google/protobuf/compiler/python
%dir /opt/protobuf/include/google/protobuf/compiler/ruby
%dir /opt/protobuf/include/google/protobuf/compiler/rust
%dir /opt/protobuf/include/google/protobuf/compiler/rust/accessors
%dir /opt/protobuf/include/google/protobuf/io
%dir /opt/protobuf/include/google/protobuf/json
%dir /opt/protobuf/include/google/protobuf/json/internal
%dir /opt/protobuf/include/google/protobuf/stubs
%dir /opt/protobuf/include/google/protobuf/testing
%dir /opt/protobuf/include/google/protobuf/util
%dir /opt/protobuf/include/upb
%dir /opt/protobuf/include/upb/port
%dir /opt/protobuf/include/upb_generator
%dir /opt/protobuf/include/upb_generator/common
%dir /opt/protobuf/include/upb_generator/minitable
%dir /opt/protobuf/%{_lib}/cmake
%dir /opt/protobuf/%{_lib}/cmake/protobuf
%dir /opt/protobuf/%{_lib}/cmake/utf8_range
%dir /opt/protobuf/%{_lib}/pkgconfig
/opt/protobuf/include/*.h
/opt/protobuf/include/google/protobuf/*.h
/opt/protobuf/include/google/protobuf/*.proto
/opt/protobuf/include/google/protobuf/*.inc
/opt/protobuf/include/google/protobuf/compiler/*.h
/opt/protobuf/include/google/protobuf/compiler/*.proto
/opt/protobuf/include/google/protobuf/compiler/cpp/*.h
/opt/protobuf/include/google/protobuf/compiler/cpp/field_generators/*.h
/opt/protobuf/include/google/protobuf/compiler/csharp/*.h
/opt/protobuf/include/google/protobuf/compiler/java/*.h
/opt/protobuf/include/google/protobuf/compiler/java/full/*.h
/opt/protobuf/include/google/protobuf/compiler/java/lite/*.h
/opt/protobuf/include/google/protobuf/compiler/kotlin/*.h
/opt/protobuf/include/google/protobuf/compiler/objectivec/*.h
/opt/protobuf/include/google/protobuf/compiler/php/*.h
/opt/protobuf/include/google/protobuf/compiler/python/*.h
/opt/protobuf/include/google/protobuf/compiler/ruby/*.h
/opt/protobuf/include/google/protobuf/compiler/rust/*.h
/opt/protobuf/include/google/protobuf/compiler/rust/accessors/*.h
/opt/protobuf/include/google/protobuf/io/*.h
/opt/protobuf/include/google/protobuf/json/*.h
/opt/protobuf/include/google/protobuf/json/internal/*.h
/opt/protobuf/include/google/protobuf/stubs/*.h
/opt/protobuf/include/google/protobuf/testing/*.h
/opt/protobuf/include/google/protobuf/util/*.h
/opt/protobuf/include/upb/port/*.h
/opt/protobuf/include/upb/port/*.inc
/opt/protobuf/include/upb_generator/common/*.h
/opt/protobuf/include/upb_generator/minitable/*.h
/opt/protobuf/%{_lib}/libprotobuf-lite.so
/opt/protobuf/%{_lib}/libprotobuf.so
/opt/protobuf/%{_lib}/libprotoc.so
/opt/protobuf/%{_lib}/libutf8_range.so
/opt/protobuf/%{_lib}/libutf8_validity.so
/opt/protobuf/%{_lib}/cmake/protobuf/*.cmake
/opt/protobuf/%{_lib}/cmake/utf8_range/*.cmake
/opt/protobuf/%{_lib}/pkgconfig/*.pc

%changelog
* Sat Jan 25 2025 Dmitry Ivanov dm.vl.ivanov@gmail.com
- Initial version
openSUSE Build Service is sponsored by