# -*- 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           cmake 1.1
PortGroup           github 1.0
PortGroup           legacysupport 1.1

# Not strictly necessary, but seems to improve tests performance marginally.
legacysupport.newest_darwin_requires_legacy 10

github.setup        nanomsg nng 1.9.0 v
revision            0
license             MIT
categories          devel
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Light-weight brokerless messaging
long_description    {*}${description}
homepage            https://nng.nanomsg.org
checksums           rmd160  cf29c45b88403ce25a452abef6676b16399bccb9 \
                    sha256  ff882bda0a854abd184a7c1eb33329e526928ef98e80ef0457dd9a708bb5b0b1 \
                    size    767473
github.tarball_from archive

cmake.generator     Ninja

depends_lib-append  port:mbedtls3

# https://github.com/nanomsg/nng/issues/1647
patchfiles          patch-tests.diff

# https://github.com/nanomsg/nng/issues/1900
patchfiles-append   patch-u_int32_t.diff

configure.args-append \
                    -DBUILD_SHARED_LIBS=OFF \
                    -DNNG_ENABLE_COVERAGE=OFF \
                    -DNNG_ENABLE_TLS=ON \
                    -DNNG_TESTS=ON

compiler.c_standard 1999
compiler.blacklist-append \
                    *gcc-4.* {clang < 400}

pre-test {
    # Testing infrastructure uses /bin/ps, which is forbidden by sandboxing.
    append portsandbox_profile " (allow process-exec (literal \"/bin/ps\") (with no-profile))"
}

# Not making a default due to: https://github.com/nanomsg/nng/issues/1648#issuecomment-1455046886
variant dylib description "Build dynamic library" {
    configure.args-replace \
                    -DBUILD_SHARED_LIBS=OFF -DBUILD_SHARED_LIBS=ON
}

# FIXME: There are a few failures on PPC: https://github.com/nanomsg/nng/issues/1648
variant tests description "Enable testing" {
    if {[variant_isset dylib]} {
        configure.pre_args-replace \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
                    -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=OFF
    }
    configure.args-replace \
                    -DNNG_TESTS=OFF -DNNG_TESTS=ON
    test.run        yes
}
