# -*- 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

name                ixwebsocket
github.setup        machinezone IXWebSocket 11.4.5 v
revision            0
categories          net devel
license             BSD
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         C++ library for WebSocket client and server development
long_description    IXWebSocket is a websocket and http client and server library, \
                    with TLS support and very few dependencies.
checksums           rmd160  db01c6fb57807afda00a8b01802e08ed455b44c7 \
                    sha256  c5fc225edec32bf7d583e55347ef2c9c4940d005c13ef5e848354a85602f5fd6 \
                    size    637715
github.tarball_from archive

# https://github.com/machinezone/IXWebSocket/pull/512
patchfiles-append   0001-IXSocket.h-add-missing-sys-types.h-for-macOS.patch

depends_build-append \
                    port:pkgconfig
depends_lib-append  port:zlib

compiler.cxx_standard   2011

configure.args-append \
                    -DBUILD_SHARED_LIBS=ON \
                    -DUSE_MBED_TLS=OFF \
                    -DUSE_OPEN_SSL=OFF \
                    -DUSE_SECURE_TRANSPORT=OFF \
                    -DUSE_TLS=OFF \
                    -DUSE_ZLIB=ON

# https://github.com/machinezone/IXWebSocket/issues/513
if {[string match *gcc* ${configure.compiler}] && \
    ${configure.build_arch} in [list arm i386 ppc]} {
    configure.ldflags-append \
                    -latomic
}

variant mbedtls conflicts openssl description "Use mbedtls for TLS" {
    depends_lib-append \
                    port:mbedtls3

    configure.args-replace \
                    -DUSE_MBED_TLS=OFF -DUSE_MBED_TLS=ON \
                    -DUSE_TLS=OFF -DUSE_TLS=ON
}

variant openssl conflicts mbedtls description "Use OpenSSL for TLS" {
    PortGroup       openssl 1.0

    configure.args-replace \
                    -DUSE_OPEN_SSL=OFF -DUSE_OPEN_SSL=ON \
                    -DUSE_TLS=OFF -DUSE_TLS=ON
}

if {![variant_isset mbedtls]} {
    default_variants    +openssl
}
