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

PortSystem          1.0
PortGroup           active_variants 1.1
PortGroup           conflicts_build 1.0
PortGroup           github 1.0
PortGroup           cmake 1.1
PortGroup           boost 1.0

# Boost versions earlier than 1.81 has broken intrinsics includes.
# Fixed in: https://github.com/boostorg/multiprecision/commit/28b314828ddd06b3e2e3586758b398fc29ceeb89
# See also: https://github.com/arvidn/libtorrent/issues/7042
boost.version       1.88

github.setup        arvidn libtorrent 2.1.2 v
revision            0
name                libtorrent-rasterbar
license             BSD
categories          net devel
maintainers         {devans @dbevans} {i0ntempest @i0ntempest} openmaintainer
platforms           darwin
homepage            https://libtorrent.org/

github.tarball_from releases
distname            libtorrent-rasterbar-${version}

description         A C++ bittorrent library (not the same as port libtorrent)

long_description    A C++ bittorrent library designed to run on anything from embedded systems to large scale \
                    seed servers. It comes with python bindings and detailed documentation.

checksums           rmd160  c872ff1b07d713fd97c470c75a935526eb48001c \
                    sha256  3362546d9cd71b9e49ee6cac7d3f1f914ce9cdb217c86b63d5b22cbed0334dbc \
                    size    6706453

depends_lib-append  path:lib/libssl.dylib:openssl

patchfiles          patch-python-use-the-right-compiler.diff

# libtorrent 2.1 requires C++17.
compiler.cxx_standard \
                    2017
compiler.blacklist-append \
                    *gcc-3.* *gcc-4.* *gcc-5.* *gcc-6.* {clang < 1000.11.45.2}

# Keep the compiler mode consistent with the CMake C++17 requirement.
configure.cxxflags-append \
                    -std=c++17

configure.args-append \
                    -DBoost_LIBRARY_DIR_RELEASE=[boost::lib_dir] \
                    -Dencryption=ON \
                    -DCMAKE_CXX_STANDARD=17 \
                    -Dlogging=OFF \
                    -Dpython-bindings=ON \
                    -Dpython-install-system-dir=ON \
                    -DNO_EXAMPLES=ON \
                    -DNO_TESTS=ON

cmake.build_type    Release

universal_variant   no

conflicts_build     ${name}


variant python310 conflicts python311 python312 python313 python314 description {Build bindings for Python 3.10} {
        require_active_variants boost[boost::version_nodot] python310
        depends_lib-append port:python310
        configure.args-append \
                -DPython3_EXECUTABLE=${prefix}/bin/python3.10 \
                -DBoost_PYTHON310_LIBRARY_RELEASE=[boost::lib_dir]/libboost_python310-mt.dylib
}

variant python311 conflicts python310 python312 python313 python314 description {Build bindings for Python 3.11} {
        require_active_variants boost[boost::version_nodot] python311
        depends_lib-append port:python311
        configure.args-append \
                -DPython3_EXECUTABLE=${prefix}/bin/python3.11 \
                -DBoost_PYTHON311_LIBRARY_RELEASE=[boost::lib_dir]/libboost_python311-mt.dylib
}

variant python312 conflicts python310 python311 python313 python314 description {Build bindings for Python 3.12} {
        require_active_variants boost[boost::version_nodot] python312
        depends_lib-append port:python312
        configure.args-append \
                -DPython3_EXECUTABLE=${prefix}/bin/python3.12 \
                -DBoost_PYTHON312_LIBRARY_RELEASE=[boost::lib_dir]/libboost_python312-mt.dylib
}

variant python313 conflicts python310 python311 python312 python314 description {Build bindings for Python 3.13} {
        require_active_variants boost[boost::version_nodot] python313
        depends_lib-append port:python313
        configure.args-append \
                -DPython3_EXECUTABLE=${prefix}/bin/python3.13 \
                -DBoost_PYTHON313_LIBRARY_RELEASE=[boost::lib_dir]/libboost_python313-mt.dylib
}

variant python314 conflicts python310 python311 python312 python313 description {Build bindings for Python 3.14} {
        require_active_variants boost[boost::version_nodot] python314
        depends_lib-append port:python314
        configure.args-append \
                -DPython3_EXECUTABLE=${prefix}/bin/python3.14 \
                -DBoost_PYTHON313_LIBRARY_RELEASE=[boost::lib_dir]/libboost_python314-mt.dylib
}

variant error_logging description {Enable logging of errors to disk} {
        configure.args-replace -Dlogging=OFF -Dlogging=ON
}

if {![variant_isset python310] && ![variant_isset python311] && ![variant_isset python312] && ![variant_isset python313]} {
        default_variants +python314
}
