# -*- 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.12.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  18adbee69fbc8d446c2c31d4bf48922cd97aed83 \
                    sha256  50b7264bd8f0901f7ebdf3ec7c48f4e23dd689bbe7b2917d9d8fad58ffd09e5c \
                    size    771967
github.tarball_from archive

conflicts           nanomq

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}

if {${os.platform} eq "darwin" && ${os.major} < 10} {
    # posix_pollq_kqueue.c:183:46: error: 'EV_DISPATCH' undeclared (first use in this function)
    patchfiles-append \
                    patch-EV_DISPATCH.diff
}

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
}
