# -*- 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       compiler_blacklist_versions 1.0
PortGroup       boost 1.0
PortGroup       legacysupport 1.1

github.setup    qbittorrent qBittorrent 4.6.7 release-
revision        0
conflicts       qBittorrent-qt5
categories      net
maintainers     {i0ntempest @i0ntempest} openmaintainer
platforms       darwin
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  cbef8ea1e0a248a2b98088cc04aa38bf84a4abc2 \
                sha256  a3691d6acfaf31cfdc583d5d8029b67e5c8099cffe3ab73eadf89085611b3956 \
                size    9097754

qt6.blacklist   {< 6.2}

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

post-patch {
         # fix the deployment target setting to the MacPorts setting
         reinplace "s|QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.15|QMAKE_MACOSX_DEPLOYMENT_TARGET = ${macosx_deployment_target}|g" \
             ${worksrcpath}/macxconf.pri
}

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}
    if {![variant_isset gui]} {
        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
