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

github.setup        pocoproject poco 1.15.2 poco- -release

categories          devel
maintainers         {gmail.com:vandervelde.ag @arjanvandervelde} openmaintainer

license             Boost-1

description         POCO C++ Libraries

long_description \
    POCO aims to be for network-centric, cross-platform C++ software development \
    what Apple’s Cocoa is for Mac development, or Ruby on Rails is for Web \
    development – a powerful, yet easy to use platform to build your applications upon.

homepage            https://pocoproject.org
master_sites        ${homepage}/releases/poco-[strsed ${version} {s/[^0-9.].*$//}]/
distname            ${name}-${version}-all
github.tarball_from archive

set docdir          ${prefix}/share/doc/${name}

if {${subport} eq ${name}} {
    PortGroup           cmake 1.1
    PortGroup           legacysupport 1.1
    PortGroup           openssl 1.0

    # strnlen
    legacysupport.newest_darwin_requires_legacy 10

    revision            0
    checksums           rmd160  d60c696f63ad89c21e500cac9710cd4ff9875d60 \
                        sha256  ca56eb58f0b8f44940c1901b8cff0fad2ac95e5b646850efbdd3d76ce8013225 \
                        size    7427487

    use_bzip2           yes

    depends_lib-append  port:expat \
                        port:libpng \
                        port:libutf8proc \
                        port:pcre2 \
                        port:zlib

    conflicts           arc

    compiler.c_standard 1999
    compiler.cxx_standard \
                        2017

    # TODO: patch CMakeLists to prevent opportunistic usage of libs.
    configure.args-append \
                        -DBUILD_SHARED_LIBS=ON \
                        -DENABLE_APACHECONNECTOR=OFF \
                        -DENABLE_CPPPARSER=OFF \
                        -DENABLE_CRYPTO=ON \
                        -DENABLE_DATA_MYSQL=OFF \
                        -DENABLE_DATA_ODBC=OFF \
                        -DENABLE_DATA_POSTGRESQL=OFF \
                        -DENABLE_DATA_SQLITE=OFF \
                        -DENABLE_DNSSD=OFF \
                        -DENABLE_DNSSD_AVAHI=OFF \
                        -DENABLE_DNSSD_BONJOUR=OFF \
                        -DENABLE_DNSSD_DEFAULT=OFF \
                        -DENABLE_FASTLOGGER=ON \
                        -DENABLE_JWT=ON \
                        -DENABLE_MONGODB=OFF \
                        -DENABLE_NETSSL=ON \
                        -DENABLE_PDF=ON \
                        -DENABLE_REDIS=OFF \
                        -DENABLE_SEVENZIP=OFF \
                        -DENABLE_TESTS=ON \
                        -DENABLE_XML=ON \
                        -DPOCO_UNBUNDLED=ON

    if {(${configure.build_arch} in [list i386 ppc]) && [string match *gcc* ${configure.compiler}]} {
        # ___atomic_load_8
        configure.ldflags-append \
                        -latomic
    }

    test.run            yes
    # Make sure the built libraries are found:
    if {${configure.cxx_stdlib} eq "libc++"} {
        test.env-append DYLD_LIBRARY_PATH=${cmake.build_dir}/lib:${prefix}/lib
    } else {
        test.env-append DYLD_LIBRARY_PATH=${cmake.build_dir}/lib:${prefix}/lib/libgcc:${prefix}/lib
    }

    post-destroot {
        xinstall -d ${destroot}${docdir}/html
        xinstall -m 0644 -W ${worksrcpath} CHANGELOG CONTRIBUTORS LICENSE README VERSION \
            ${destroot}${docdir}
        xinstall -m 0644 -W ${worksrcpath}/doc Acknowledgements.html ${destroot}${docdir}/html
        copy ${worksrcpath}/CppUnit/doc ${destroot}${docdir}/html/CppUnit
    }

    variant odbc description "Build ODBC backend for Data library" {
        depends_lib-append      port:libiodbc
        configure.args-replace  -DENABLE_DATA_ODBC=OFF \
                                -DENABLE_DATA_ODBC=ON
        configure.args-append   -DODBC_INCLUDE_DIR=${prefix}/include/libiodbc \
                                -DODBC_LIBRARY=${prefix}/lib/libiodbc.dylib
    }

    variant mongodb description "Build MongoDB backend for Data library" {
        depends_lib-append      port:mongodb
        configure.args-replace  -DENABLE_MONGODB=OFF \
                                -DENABLE_MONGODB=ON
    }

    variant mysql description "Build MySQL backend for Data library" {
        depends_lib-append      path:bin/mysql_config5:mysql5
        configure.args-replace  -DENABLE_DATA_MYSQL=OFF \
                                -DENABLE_DATA_MYSQL=ON
        configure.args-append   -DMYSQL_INCLUDE_DIR=${prefix}/include/mysql5/mysql \
                                -DMYSQL_LIBRARY=${prefix}/lib/mysql5/mysql/libmysqlclient.dylib
    }

    variant redis description "Build Redis backend for Data library" {
        depends_lib-append      port:redis
        configure.args-replace  -DENABLE_REDIS=OFF \
                                -DENABLE_REDIS=ON
    }

    variant sqlite description "Build SQLite backend for Data library" {
        depends_lib-append      port:sqlite3
        configure.args-replace  -DENABLE_DATA_SQLITE=OFF \
                                -DENABLE_DATA_SQLITE=ON
    }

    default_variants    +sqlite
}

subport ${name}-docs {
    revision            0
    checksums           rmd160  93e2d9a8048112833b005f16a45d9903b1d6f7b3 \
                        sha256  cbba83770de143c8b811e32cb58e54e7c20a94eecc9aac3788757c5c09dffe8b \
                        size    1827607

    supported_archs     noarch
    platforms           any
    description         Documentation for POCO
    long_description    This port contains an offline copy of the POCO documentation.
    homepage            ${homepage}/documentation
    distname            ${distname}-doc

    use_configure       no

    build               {}

    destroot {
        xinstall -d ${destroot}${docdir}
        copy ${worksrcpath} ${destroot}${docdir}/html
    }
}

if {${subport} ne ${name}} {
    livecheck.type  none
}
