File googletest-opt.spec of Package googletest-opt

#
# spec file for package googletest-opt
#
# 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.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

# OpenSUSE Leap by default ships with gcc which is too old to build
# googletest, 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

%global libver 1.15.2

Name:           googletest-opt
Version:        1.15.2
Release:        0
Summary:        Google C++ Testing Framework
License:        BSD-3-Clause
Group:          Development/Libraries/C and C++
URL:            https://github.com/google/googletest
Source0:        %{name}-%{version}.tar.gz
BuildRequires:  bash
BuildRequires:  binutils
BuildRequires:  gcc%{?with_gcc}
BuildRequires:  gcc%{?with_gcc}-c++
BuildRequires:  cmake

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

%description
Google's framework for writing C++ tests on a variety of platforms
(Linux, Mac OS X, Windows, Cygwin, Windows CE, and Symbian).
Based on the xUnit architecture. Supports automatic test discovery,
a rich set of assertions, user-defined assertions, death tests,
fatal and non-fatal failures, value- and type-parameterized tests,
various options for running the tests, and XML test report generation.

%package -n     gtest-opt
Summary:        Google C++ Testing Framework libraries
Group:          Development/Libraries/C and C++
Recommends:     gmock-opt = %{version}

%description -n gtest-opt
Google's framework for writing C++ tests on a variety of platforms
(Linux, Mac OS X, Windows, Cygwin, Windows CE, and Symbian).
Based on the xUnit architecture. Supports automatic test discovery,
a rich set of assertions, user-defined assertions, death tests,
fatal and non-fatal failures, value- and type-parameterized tests,
various options for running the tests, and XML test report generation.

This package provides shared libraries and header files for development
with googletest.

%package -n		gtest-opt-devel
Summary:       	Development files for gtest-opt
Requires:      	gtest-opt = %{version}-%{release}

%description -n gtest-opt-devel
Development files for gtest-opt.

%package -n     gmock-opt
Summary:        Google C++ Mocking Framework
Group:          Development/Libraries/C and C++
Requires:       gtest-opt = %{version}

%description -n gmock-opt
Inspired by jMock, EasyMock, and Hamcrest, and designed with C++'s specifics in
mind, Google C++ Mocking Framework (or Google Mock for short) is a library for
writing and using C++ mock classes.

This package provides shared libraries and header files for development
with googlemock.

%package -n		gmock-opt-devel
Summary:       	Development files for gmock-opt
Requires:      	gmock-opt = %{version}-%{release}

%description -n gmock-opt-devel
Development files for gmock-opt.

%prep
%autosetup

%build

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

%define __builder ninja
%cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/opt/googletest -DBUILD_GMOCK=ON
%cmake_build

%check
%ctest

%install
%cmake_install

strip %{buildroot}/opt/googletest/%{_lib}/libgmock_main.so
strip %{buildroot}/opt/googletest/%{_lib}/libgmock.so
strip %{buildroot}/opt/googletest/%{_lib}/libgtest_main.so
strip %{buildroot}/opt/googletest/%{_lib}/libgtest.so

# SLE12 does not define this macro
%if %{undefined ldconfig_scriptlets}
%post -n gtest-opt -p /sbin/ldconfig
%postun -n gtest-opt -p /sbin/ldconfig
%post -n gmock-opt -p /sbin/ldconfig
%postun -n gmock-opt -p /sbin/ldconfig
%else
%ldconfig_scriptlets -n gtest-opt
%ldconfig_scriptlets -n gmock-opt
%endif

%files -n gtest-opt
%license LICENSE
%doc README.md
%dir /opt/googletest
%dir /opt/googletest/%{_lib}
/opt/googletest/%{_lib}/libgtest.so.%{libver}
/opt/googletest/%{_lib}/libgtest_main.so.%{libver}

%files -n gtest-opt-devel
%license LICENSE
%doc README.md
%dir /opt/googletest/include
%dir /opt/googletest/include/gtest
%dir /opt/googletest/%{_lib}/cmake
%dir /opt/googletest/%{_lib}/cmake/GTest
%dir /opt/googletest/%{_lib}/pkgconfig
/opt/googletest/%{_lib}/libgtest.so
/opt/googletest/%{_lib}/libgtest_main.so
/opt/googletest/%{_lib}/cmake/GTest/*
/opt/googletest/%{_lib}/pkgconfig/gtest*
/opt/googletest/include/gtest/*

%files -n gmock-opt
%license LICENSE
%doc README.md
/opt/googletest/%{_lib}/libgmock.so.%{libver}
/opt/googletest/%{_lib}/libgmock_main.so.%{libver}

%files -n gmock-opt-devel
%license LICENSE
%doc README.md
%dir /opt/googletest/include/gmock
/opt/googletest/%{_lib}/libgmock.so
/opt/googletest/%{_lib}/libgmock_main.so
/opt/googletest/%{_lib}/pkgconfig/gmock*.pc
/opt/googletest/include/gmock/*

%changelog
* Tue Feb 4 2025 Dmitry Ivanov dm.vl.ivanov@gmail.com
- Initial version
openSUSE Build Service is sponsored by