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

name                    capnproto
version                 1.2.0
revision                0
checksums               rmd160  e7d3a5f47b17019f89dce7dd8f3e459d19aa1f9b \
                        sha256  ed00e44ecbbda5186bc78a41ba64a8dc4a861b5f8d4e822959b0144ae6fd42ef \
                        size    1769091

maintainers             {cal @neverpanic} openmaintainer
categories              devel

homepage                https://capnproto.org/
description             \
    Cap’n Proto is an insanely fast data interchange format and \
    capability-based RPC system. Think JSON, except binary. Or think Protocol \
    Buffers, except faster.
long_description        {*}${description}
license                 BSD

master_sites            ${homepage}
distname                ${name}-c++-${version}

use_autoreconf          yes

compiler.cxx_standard   2014

# clang 3.2 - clang-3.5 and all clangs from Xcode < 5 crash while compiling this.
# see http://llvm.org/bugs/show_bug.cgi?id=18340
# clang prior to 1000 also fails.
# ./src/kj/time.h:48:31: error: invalid operands to binary expression ('int' and 'const Duration' (aka 'const Quantity<int64_t, _::NanosecondLabel>'))
# constexpr Duration HOURS = 60 * MINUTES;
#                            ~~ ^ ~~~~~~~
compiler.blacklist-append \
                        {clang < 1000} \
                        macports-clang-3.3 \
                        macports-clang-3.4

configure.cppflags-replace \
                        -I${prefix}/include "-isystem${prefix}/include"

if {[string match *clang* ${configure.compiler}]} {
    configure.cxx_stdlib        libc++
    configure.ldflags-append    -stdlib=libc++
} elseif {[string match *gcc* ${configure.compiler}]} {
    configure.cxxflags-append   -std=gnu++17
    # ___atomic_load_8
    # https://github.com/capnproto/capnproto/issues/1713
    configure.ldflags-append    -latomic
}

default_variants            +openssl

variant openssl description {Support TLS using the OpenSSL library} {
    configure.args-append   --with-openssl=${prefix}
    depends_lib-append      path:lib/libssl.dylib:openssl
}

test.run                    yes
test.target                 check

livecheck.type              regex
livecheck.url               https://capnproto.org/install.html
livecheck.regex             "[quotemeta ${name}]-c\\+\\+-(\\d+(\\.\\d+)*)[quotemeta ${extract.suffix}]"
