# -*- 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           boost 1.0
PortGroup           cmake 1.1
PortGroup           conflicts_build 1.0
PortGroup           github 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.12 v
revision            0
name                libtorrent-rasterbar
license             BSD
categories          net
maintainers         {devans @dbevans} {i0ntempest @i0ntempest} openmaintainer
homepage            https://libtorrent.org

description         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.

distname            libtorrent-rasterbar-${version}

checksums           rmd160  8e5103c20713df37fe725a9c22b62ae6ba0a51ae \
                    sha256  25b898d02e02e43ee9a8ea5480c20007f129091b5754d0283f94e4d51d11a19e \
                    size    4689934
github.tarball_from releases

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

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

# Enable this on 10.6:
patchfiles-append   patch-config.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   {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:python313
        configure.args-append \
                -DPython3_EXECUTABLE=${prefix}/bin/python3.13 \
                -DBoost_PYTHON313_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
}
