# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4

PortSystem      1.0
PortGroup       github 1.0
PortGroup       cmake 1.1
PortGroup       qt6 1.0
PortGroup       boost 1.0
PortGroup       legacysupport 1.1

github.setup    qbittorrent qBittorrent 5.1.2 release-
github.tarball_from \
                archive
revision        0
conflicts       qBittorrent-qt5
categories      net
maintainers     {i0ntempest @i0ntempest} openmaintainer
license         {GPL-2+ OpenSSLException}

description     The qBittorrent project aims to provide an open-source software alternative to µTorrent.
long_description \
                qBittorrent is a bittorrent client programmed in C++ / Qt that uses \
                libtorrent (sometimes called libtorrent-rasterbar) by Arvid Norberg. \
                It aims to be a good alternative to all other bittorrent clients out \
                there. qBittorrent is fast, stable and provides unicode support as well \
                as many features.

homepage        https://www.qbittorrent.org

checksums       rmd160  b0f46cfaabf262dd3ec4c81f013d0e41f280102d \
                sha256  a35448f3c8cb57d033bd3c4bd66c63417b0ca793ae7e9c5c5053960e2229ad9e \
                size    9517374

qt6.blacklist   {< 6.5}

configure.args-append \
                -DQT6=ON \
                -DVERBOSE_CONFIGURE=ON \
                -DWEBUI=OFF \
                -DGUI=OFF

qt6.depends_build \
                qttools

qt6.depends_lib qttranslations

depends_build-append \
                port:pkgconfig

depends_lib-append \
                port:libtorrent-rasterbar \
                path:lib/libssl.dylib:openssl \
                port:zlib

boost.depends_type  \
                build
boost.version   1.81

configure.cxxflags-append \
                -std=c++20
compiler.cxx_standard \
                2020
compiler.blacklist-append \
                {clang < 1600} {*gcc-[4-9]*} {*clang-[3-9]*}

# undefined symbols for std::filesystem on 10.14
legacysupport.newest_darwin_requires_legacy \
                18
legacysupport.use_mp_libcxx \
                yes

destroot {
    if {[variant_isset gui]} {
        set appname "qbittorrent"
    } else {
        set appname "qbittorrent-nox"
    }
    reinplace "s|Plugins = PlugIns|Plugins = ${qt6.dir}/plugins|g" ${build.dir}/${appname}.app/Contents/Resources/qt.conf
    system -W ${build.dir} "/usr/bin/codesign --sign - ${appname}.app"
    copy ${build.dir}/${appname}.app ${destroot}${applications_dir}
    ln -s ${applications_dir}/${appname}.app/Contents/MacOS/${appname} ${destroot}${prefix}/bin
}

variant gui description {Enable GUI} {
                configure.args-replace -DGUI=OFF -DGUI=ON
                qt6.depends_lib-append qtsvg
}

variant webui description {Enable WebUI} {
                configure.args-replace -DWEBUI=OFF -DWEBUI=ON
}

default_variants \
                +gui +webui
