File qbittorrent.spec of Package qbittorrent

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


%define original_name qBittorrent

# For MAGEIA Only; This MACRO is non-existing there
%if 0%{?mageia}
%define _mandir       %{_datadir}/man/
%endif
#

# Enable Conditional NOX BUILD by Default (1)
%if 0%{?sle_version} == 150600 && 0%{?is_opensuse}
%bcond_without nox
%else
%bcond nox 1
%endif


Name:           qbittorrent
Version:        5.1.2
Release:        0
Summary:        A BitTorrent client using QT, offers a user-friendly GUI interface (+ Web UI)
License:        GPL-2.0-or-later
URL:            https://qbittorrent.org

Source0:        https://downloads.sf.net/%{name}/%{name}-%{version}.tar.xz
Source1:        https://downloads.sf.net/%{name}/%{name}-%{version}.tar.xz.asc
Source2:        https://raw.githubusercontent.com/qbittorrent/qBittorrent/release-%{version}/5B7CC9A2.asc#/%{name}.keyring
Source3:        https://raw.githubusercontent.com/%{name}/%{original_name}/refs/tags/release-%{version}/Changelog#/CHANGELOG
Patch0:         %{name}-Qt610.patch
Patch1:         SystemD_Service-Hardening.patch

# For SUSE / FEDORA / MAGEIA
%if 0%{?suse_version} && 0%{?is_opensuse} || 0%{?sle_version} && 0%{?is_opensuse} || 0%{?fedora} || 0%{?mageia}
%if 0%{?sle_version} == 150600 && 0%{?is_opensuse}
BuildRequires:  gcc13  gcc13-c++  libstdc++6-devel-gcc13
%else
BuildRequires:  gcc  gcc-c++
%endif
BuildRequires:  boost-custom-devel
BuildRequires:  cmake
BuildRequires:  fdupes
BuildRequires:  hicolor-icon-theme
BuildRequires:  libtorrent-rasterbar-custom-devel
BuildRequires:  pkgconfig
BuildRequires:  (qt6-core-private-devel  or  qt6-qtbase-private-devel  or  lib64qt6base6-devel  or  libqt6base6-devel)
BuildRequires:  (qt6-declarative-devel  or  qt6-qtdeclarative-devel  or  lib64kf6declarative-devel  or  libkf6declarative-devel)
%if 0%{?suse_version} >= 1600 && 0%{?is_opensuse}
BuildRequires:  cmake(KF6Declarative)
%endif
BuildRequires:  cmake(Qt6Core)
BuildRequires:  cmake(Qt6DBus)
BuildRequires:  cmake(Qt6LinguistTools)
BuildRequires:  cmake(Qt6Network)
BuildRequires:  cmake(Qt6Sql)
BuildRequires:  cmake(Qt6Svg)
BuildRequires:  cmake(Qt6Widgets)
BuildRequires:  cmake(Qt6Xml)
BuildRequires:  pkgconfig(openssl)
BuildRequires:  pkgconfig(systemd)
%if 0%{?fedora}
BuildRequires:  zlib-ng-compat-static
%else
BuildRequires:  pkgconfig(zlib)
%endif
%endif
#

# Extra potential REQUIREMENTS for SUSE / FEDORA / MAGEIA
# For SUSE Only
%if 0%{?suse_version} && 0%{?is_opensuse} || 0%{?sle_version} && 0%{?is_opensuse}
Requires:     (kf6-kdeclarative-imports  or  qt6-declarative-imports)
Requires:     qtdeclarative-imports-provides-qt6
%requires_ge  libQt6Svg6
%requires_ge  libtorrent-rasterbar2_0
%endif
#
# For FEDORA / MAGEIA
%if 0%{?fedora} || 0%{?mageia}
Requires:  (qt6-qtsvg  or  lib64qt6svg6  or  libqt64svg6)
%if 0%{?fedora}
Requires:  qt6-qtdeclarative
%endif
Requires:  libtorrent-rasterbar2_0
#
%endif
#

# For qBitTorrent search engines plugins
Recommends:     (python3 or python3.13 or python313 or python312)
#
# For a More Appropriate Integration of QT Theming into GTK
Recommends:     (qgnomeplatform-qt6  if  cinnamon)
Recommends:     (qgnomeplatform-qt6  if  gnome-shell)
Recommends:     (qgnomeplatform-qt6  if  mate-desktop)
Recommends:     (qgnomeplatform-qt6  if  xfce4-session)
#

%description
A BitTorrent client developed in C++ using the QT framework, leveraging
libtorrent-rasterbar for robust peer-to-peer file sharing. It offers a
feature-rich interface with support for torrent streaming, Unicode, and
bandwidth scheduling. Additional capabilities include external plugin search
engines (requiring Python 3), remote web interface access, and advanced
torrent management tools such as queuing, prioritization, and IP filtering.

This the primary and default qBitTorrent variant.

%if %{with nox}
%package nox
Summary:        Headless CLI qBitTorrent client with QT-based web UI for server management

%{?systemd_requires}

%description nox
A headless BitTorrent client developed in C++ using the Qt framework and
libtorrent-rasterbar, designed for command-line and remote management. It
supports torrent streaming, Unicode, bandwidth scheduling, and external
plugin search engines (requiring Python 3). Ideal for server environments,
it provides a web interface for efficient torrent management, including
queuing, prioritization, and IP filtering.

This sub-package contains CLI + Web UI.
%endif

%prep
%autosetup -p1

# Rename Changelog to CHANGELOG
mv -f Changelog -T CHANGELOG
#

%build
# Set GCC Version 13 Instead of GCC Version 7 (Default) for SUSE Leap 15.6
%if 0%{?sle_version} == 150600 && 0%{?is_opensuse}
export  CC="%{_bindir}/gcc-13"
export CXX="%{_bindir}/g++-13"
%endif
#
# Build Instructions for SUSE Only
%if 0%{?suse_version} && 0%{?is_opensuse} || 0%{?sle_version} && 0%{?is_opensuse}

# Without NOX (With GUI)
%cmake -S "../" -B "build_gui/" \
    -DQT6="ON"                  \
    -DSYSTEMD="OFF"             \
    -Wno-dev

cmake --build "build_gui/" -j${RPM_BUILD_NCPUS} --verbose
#
# With NOX (Without GUI)
%if %{with nox}
%cmake -S "../../" -B "../build_nox/"          \
    -DQT6="ON"                                 \
    -DSYSTEMD="ON"                             \
    -DSystemd_SERVICES_INSTALL_DIR=%{_unitdir} \
    -DGUI="OFF"                                \
    -Wno-dev

cmake --build "../build_nox/" -j${RPM_BUILD_NCPUS} --verbose
%endif
#
%endif
#

# Build Instructions for FEDORA / MAGEIA
%if 0%{?fedora} || 0%{?mageia}
# Without NOX (With GUI)
%cmake -B "build_gui/" \
    -DQT6="ON"         \
    -DSYSTEMD="OFF"    \
    -Wno-dev

cmake --build "build_gui/" -j${RPM_BUILD_NCPUS} --verbose
#
# With NOX (Without GUI)
%if %{with nox}
%cmake -B "build_nox/"                         \
    -DQT6="ON"                                 \
    -DSYSTEMD="ON"                             \
    -DSystemd_SERVICES_INSTALL_DIR=%{_unitdir} \
    -DGUI="OFF"                                \
    -Wno-dev

cmake --build "build_nox/" -j${RPM_BUILD_NCPUS} --verbose
%endif
#
%endif
#

%install
# Install Instructions for SUSE Only
%if 0%{?suse_version} && 0%{?is_opensuse} || 0%{?sle_version} && 0%{?is_opensuse}

# Install GUI variant of qBitTorrent - Without NOX (With GUI)
DESTDIR="%{buildroot}" cmake --install "build/build_gui/"
#
# Install NOX (Web UI) Variant of qBitTorrent - With NOX (Without GUI)
%if %{with nox}
DESTDIR="%{buildroot}" cmake --install "build/build_nox/"
%endif
#
%endif
#

# Install Instructions For FEDORA / MAGEIA
%if 0%{?fedora} || 0%{?mageia}
# Install GUI variant of qBitTorrent - Without NOX (With GUI)
DESTDIR="%{buildroot}" cmake --install "build_gui/"
#
# Install NOX (Web UI) Variant of qBitTorrent - With Nox (Without GUI)
%if %{with nox}
DESTDIR="%{buildroot}" cmake --install "build_nox/"
%endif
#
%endif
#

# Link SystemD Service with Legacy RC Service
%if %{with nox}
mkdir -p   %{buildroot}/%{_sbindir}/
ln    -fs "%{_sbindir}/service" -T "%{buildroot}/%{_sbindir}/rc%{name}-nox"
%endif
#
# Add Multilingual Support
%find_lang  %{name}      --with-man
%if %{with nox}
%find_lang "%{name}-nox" --with-man
%endif
#

%check
# Check and Merge Duplicated Files
%fdupes %{buildroot}/%{_datadir}/
#

# For NOX Variant Only
%if %{with nox}
%preun nox
# For SUSE Only
%if 0%{?suse_version} && 0%{?is_opensuse} || 0%{?sle_version} && 0%{?is_opensuse}

%service_del_preun "%{name}-nox@.service"
#
# For FEDORA Only
%else
%systemd_preun     "%{name}-nox@.service"
#
%endif

%pre nox
# For SUSE Only
%if 0%{?suse_version} && 0%{?is_opensuse} || 0%{?sle_version} && 0%{?is_opensuse}

%service_add_pre "%{name}-nox@.service"
%endif
#

%postun nox
# For SUSE Only
%if 0%{?suse_version} && 0%{?is_opensuse} || 0%{?sle_version} && 0%{?is_opensuse}

%service_del_postun          "%{name}-nox@.service"
#
# For FEDORA Only
%else
%systemd_postun_with_restart "%{name}-nox@.service"
#
%endif

%post nox
# For SUSE Only
%if 0%{?suse_version} && 0%{?is_opensuse} || 0%{?sle_version} && 0%{?is_opensuse}
%service_add_post "%{name}-nox@.service"
#
# For FEDORA Only
%else
%systemd_post     "%{name}-nox@.service"
#
%endif

%endif
#

# Without NOX (With GUI)
%files -f "%{name}.lang"
%license COPYING

%doc     AUTHORS CHANGELOG "README.md"

 %{_bindir}/%{name}

"%{_datadir}/applications/org.%{name}.%{original_name}.desktop"
 %{_datadir}/icons/hicolor/*/apps/%{name}.*
 %{_datadir}/icons/hicolor/*/status/%{name}-tray.png
 %{_datadir}/icons/hicolor/scalable/status/%{name}-tray*.svg
"%{_datadir}/metainfo/org.%{name}.%{original_name}.metainfo.xml"

 %{_mandir}/man*/%{name}.*%{?ext_man}
 %{_mandir}/ru/man*/%{name}.*%{?ext_man}
#
# For NOX Variant Only
%if %{with nox}
%files nox -f "%{name}-nox.lang"
%license COPYING

%doc     AUTHORS CHANGELOG "README.md"

"%{_bindir}/%{name}-nox"
"%{_sbindir}/rc%{name}-nox"

 %{_mandir}/man*/%{name}-nox.*%{?ext_man}
 %{_mandir}/ru/man*/%{name}-nox.*%{?ext_man}

"%{_unitdir}/%{name}-nox@.service"
%endif
#

%changelog
openSUSE Build Service is sponsored by