File qcustomplot.spec of Package qcustomplot

#
# spec file for package qcustomplot
#
# Copyright (c) 2025 SUSE LLC and contributors
#
# 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/
#


%global lib_ver 2.0.0
%define sover   2

%global qcustomplot_flavor @BUILD_FLAVOR@%{nil}
%if "%{qcustomplot_flavor}" == ""
ExclusiveArch:  do_not_build
%endif
%if "%{qcustomplot_flavor}" == "qt6"
%define qt6 1
%define qt_major 6
%define qt_descr Qt6
%endif
%if "%{qcustomplot_flavor}" == "qt5"
%define qt5 1
%define qt_major 5
%define qt_descr Qt5
%endif

%define libname libqcustomplot-qt%{qt_major}-%{sover}

Name:           qcustomplot
Version:        2.1.1
Release:        0
Summary:        %{qt_descr} widget for plotting and data visualization
License:        GPL-3.0-or-later
URL:            https://www.qcustomplot.com/
Group:          Development/Libraries/C and C++
Source0:        https://www.qcustomplot.com/release/%{version}/QCustomPlot.tar.gz
Source1:        CMakeLists.txt
BuildRequires:  cmake
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  pkg-config
%if 0%{?qt5}
BuildRequires:  pkgconfig(Qt5Core)
BuildRequires:  pkgconfig(Qt5Gui)
BuildRequires:  pkgconfig(Qt5PrintSupport)
BuildRequires:  pkgconfig(Qt5Widgets)
%endif
%if 0%{?qt6}
BuildRequires:  pkgconfig(Qt6Core)
BuildRequires:  pkgconfig(Qt6Gui)
BuildRequires:  pkgconfig(Qt6PrintSupport)
BuildRequires:  pkgconfig(Qt6Widgets)
%endif

%description
QCustomPlot is a %{qt_descr} C++ widget for plotting and data visualization.
This plotting library focuses on making good looking, publication quality 2D
plots, graphs and charts, as well as offering high performance for realtime
visualization applications.

%package     -n %{libname}
Summary:        %{qt_descr} widget for plotting and data visualization
Group:          System/Libraries
%if 0%{?qt5}
Provides:       %{name} = %{version}
Provides:       lib%{name} = %{version}
Obsoletes:      %{name} < %{version}
Provides:       %{name}-qt5 = %{version}
Obsoletes:      %{name}-qt5 < %{version}
# Earlier misnamed packages
Provides:       lib%{name}-%{sover} = %{version}
Obsoletes:      lib%{name}-%{sover} < %{version}
%endif

%description -n %{libname}
QCustomPlot is a %{qt_descr} C++ widget for plotting and data visualization.
This plotting library focuses on making good looking, publication quality 2D
plots, graphs and charts, as well as offering high performance for realtime
visualization applications.

%package        qt%{qt_major}-devel
Summary:        Development files for QCustomPlot - %{qt_descr}
Group:          Development/Libraries/C and C++
Requires:       %{libname} = %{version}
%if 0%{?qt5}
Requires:       pkgconfig(Qt5PrintSupport)
# Last used 2018 with version 2.0.0
Provides:       %{name}-qt5-devel = %{version}
Obsoletes:      %{name}-qt5-devel < %{version}
%endif
%if 0%{?qt6}
Requires:       pkgconfig(Qt6PrintSupport)
%endif

%description    qt%{qt_major}-devel
This package contains libraries and header files for
developing applications that use QCustomPlot - %{qt_descr}.

%package        doc
Summary:        Documentation and examples for QCustomPlot
Group:          Documentation/Other
BuildArch:      noarch

%description    doc
This package contains the documentation and examples for QCustomPlot.

%prep
%autosetup -p1 -n %{name}
cp %{SOURCE1} .
chmod -x GPL.txt
find ./examples/ -name "*.cpp" -o -name "*.h" | xargs sed -i 's/\r$//'

%build
%cmake -DQT_VER=%{qt_major} -DLIB_VER=%{lib_ver}
%cmake_build

%install
%cmake_install
install -Dm 644 qcustomplot.h %{buildroot}%{_includedir}/qcustomplot.h

# pkg-config files
install -d %{buildroot}%{_libdir}/pkgconfig/

cat > %{buildroot}%{_libdir}/pkgconfig/%{name}-qt%{qt_major}.pc <<EOF
libdir=%{_libdir}
includedir=%{_includedir}

Name:           %{name}
Version:        %{version}
Description: %{summary}
Cflags: -I\${includedir}
Libs: -L\${libdir} -lqcustomplot-qt%{qt_major}
EOF

install -Dm 0644 -t %{buildroot}%{_docdir}/%{name}/ changelog.txt documentation/qcustomplot.qch
cp -r documentation/html/ %{buildroot}%{_docdir}/%{name}/
cp -r examples %{buildroot}%{_docdir}/%{name}/
find %{buildroot}%{_docdir}/%{name}/ -type f -exec chmod 0644 \{\} +
%fdupes %{buildroot}/%{_prefix}

%ldconfig_scriptlets -n %{libname}

%files -n %{libname}
%license GPL.txt
%{_libdir}/libqcustomplot-qt%{qt_major}.so.%{sover}*

%files qt%{qt_major}-devel
%{_includedir}/qcustomplot.h
%{_libdir}/libqcustomplot-qt%{qt_major}.so
%{_libdir}/pkgconfig/%{name}-qt%{qt_major}.pc

%files doc
%dir %{_docdir}/%{name}/
%{_docdir}/%{name}/qcustomplot.qch
%{_docdir}/%{name}/changelog.txt
%{_docdir}/%{name}/html/
%{_docdir}/%{name}/examples/

%changelog
openSUSE Build Service is sponsored by