# -*- 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           compiler_blacklist_versions 1.0
PortGroup           conflicts_build 1.0
PortGroup           github 1.0
PortGroup           cmake 1.1
PortGroup           boost 1.0

# Earlier Boost 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.81

github.setup        arvidn libtorrent 2.0.11 v
revision            1
name                libtorrent-rasterbar
license             BSD
categories          net
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  a9960a1b4b97cc34a6aaa3ddb56c877c4c8d2c9d \
                    sha256  f0db58580f4f29ade6cc40fa4ba80e2c9a70c90265cd77332d3cdec37ecf1e6d \
                    size    4635957

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

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

# Apple clang less than 900.0.39.2 fails to build
# build using C++14 for binary compatibility with C++14 dependents
compiler.cxx_standard 2014
compiler.blacklist-append *gcc-3.* *gcc-4.* {clang < 900.0.39.2}

# ensure that compiler is using C++14 mode
configure.cxxflags-append -std=c++14

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

cmake.build_type    Release

universal_variant   no

conflicts_build     ${name}


variant python39 conflicts python310 python311 python312 python313 description {Build bindings for Python 3.9} {
        require_active_variants boost[boost::version_nodot] python39
        depends_lib-append port:python39
        configure.args-append \
                -DPython3_EXECUTABLE=${prefix}/bin/python3.9 \
                -DBoost_PYTHON39_LIBRARY_RELEASE=[boost::lib_dir]/libboost_python39-mt.dylib
}

variant python310 conflicts python39 python311 python312 python313 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 python39 python310 python312 python313 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 python39 python310 python311 python313 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 python39 python310 python311 python312 description {Build bindings for Python 3.13} {
        require_active_variants boost[boost::version_nodot] python313
        depends_lib-append port:python312
        configure.args-append \
                -DPython3_EXECUTABLE=${prefix}/bin/python3.13 \
                -DBoost_PYTHON312_LIBRARY_RELEASE=[boost::lib_dir]/libboost_python313-mt.dylib
}

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

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