# -*- 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.12.4 poco- -release
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
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

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

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

    revision            1
    checksums           rmd160  474a8ae863281d93b4714a6940cf0357c81f9c6e \
                        sha256  4e6ccc0df904596478414ef56a992cf885eb4b0ee695b23d307eb2ff91c36626 \
                        size    5990710

    use_bzip2           yes

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

    conflicts           arc

    patchfiles          DYLD_LIBRARY_PATH.patch

    compiler.c_standard 1999
    compiler.cxx_standard \
                        2014

    configure.args      -DBUILD_SHARED_LIBS=ON \
                        -DENABLE_APACHECONNECTOR=OFF \
                        -DENABLE_CRYPTO=ON \
                        -DENABLE_DATA_MYSQL=OFF \
                        -DENABLE_DATA_ODBC=OFF \
                        -DENABLE_DATA_POSTGRESQL=OFF \
                        -DENABLE_DATA_SQLITE=OFF \
                        -DENABLE_MONGODB=OFF \
                        -DENABLE_TESTS=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:
    test.env-append     DYLD_LIBRARY_PATH=${cmake.build_dir}/lib:${prefix}/lib

    post-destroot {
        xinstall -d ${destroot}${docdir}/html
        xinstall -m 0644 -W ${worksrcpath} CHANGELOG CONTRIBUTORS LICENSE NEWS 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 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  fbfcd0d480c48e7c3bc1009089451bc0d6670866 \
                        sha256  ce4b7e34f3fd61f965fe5f3ae1f0280bc9d28872b6ddd3513ea9e1fcf03d3bb3 \
                        size    1569791

    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
}
