# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           cmake 1.1

name                evolution-data-server
version             3.36.5
revision            8

categories          gnome
license             LGPL-2+
maintainers         {mascguy @mascguy} openmaintainer

description         Addressbook and calender libs for GNOME.
long_description    Evolution Data Server provides a central location for \
                    addressbook and calendar in the GNOME Desktop.
homepage            https://wiki.gnome.org/Apps/Evolution

set branch          [join [lrange [split ${version} .] 0 1] .]
master_sites        gnome:sources/${name}/${branch}/
use_xz              yes

checksums           rmd160  37f0434b0d89dbbae40343718b347d3788753373 \
                    sha256  c555528c546d457be0dc0eaca5d766d4dfef7c408276cb05f9724c463bfe7fd9 \
                    size    4636800

set bdb_ver         53

depends_build-append \
                    port:gettext \
                    port:gperf \
                    port:intltool \
                    path:bin/pkg-config:pkgconfig

depends_lib-append \
                    port:db${bdb_ver} \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:gettext-runtime \
                    port:gcr \
                    port:gnome-online-accounts \
                    path:lib/pkgconfig/icu-uc.pc:icu \
                    port:kerberos5 \
                    port:libcanberra \
                    port:libgdata \
                    port:libgweather \
                    port:libical \
                    port:libiconv \
                    port:libsecret \
                    path:lib/pkgconfig/libsoup-2.4.pc:libsoup \
                    port:libxml2 \
                    port:nss \
                    port:nspr \
                    path:lib/libldap.dylib:openldap \
                    port:sqlite3

depends_run-append \
                    port:perl5

patchfiles-append   patch-cmake-find-our-build-tools.diff
patchfiles-append   patch-remove-linker-flag-no-undefined.diff

# libphonenumber-cpp uses C++11 extensions but evolution-data-server doesn't assert -std=c++11
# this causes configuration failures when testing for libphonenumber on at least Mojave/Xcode 10
compiler.cxx_standard \
                    2011
configure.cxxflags-append \
                    -std=c++11

configure.args-append \
                    -DENABLE_EXAMPLES=OFF \
                    -DENABLE_GOA=ON \
                    -DENABLE_GOOGLE=ON \
                    -DENABLE_GTK=ON \
                    -DENABLE_GTK_DOC=OFF \
                    -DENABLE_INSTALLED_TESTS=OFF \
                    -DENABLE_INTROSPECTION=OFF \
                    -DENABLE_IPV6=ON \
                    -DENABLE_OAUTH2=OFF \
                    -DENABLE_SCHEMAS_COMPILE=OFF \
                    -DENABLE_SMIME=ON \
                    -DENABLE_VALA_BINDINGS=OFF \
                    -DENABLE_WEATHER=ON \
                    -DLIBEXEC_INSTALL_DIR=${prefix}/libexec/${name} \
                    -DWITH_LIBDB_CFLAGS="-I${prefix}/include/db${bdb_ver}" \
                    -DWITH_LIBDB_LIBS="-L${prefix}/lib/db${bdb_ver} -ldb" \
                    -DWITH_OPENLDAP=${prefix}

# port nss is not universal
universal_variant   no

# TODO: Need to fix CMake detection for 'libphonenumber-cpp', before we can enable
# See: https://trac.macports.org/ticket/63788
#default_variants    +phonenumber

post-destroot {
    ln -s ${prefix}/lib/evolution-data-server/libedbus-private.dylib ${destroot}${prefix}/lib
}

post-activate    {
    system "${prefix}/bin/glib-compile-schemas ${prefix}/share/glib-2.0/schemas"
}

variant oauth2 description {Enable OAuth2 authentication} {
    depends_lib-append \
                    path:lib/pkgconfig/webkit2gtk-4.0.pc:webkit2-gtk \
                    port:json-glib
    configure.args-replace \
                    -DENABLE_OAUTH2=OFF \
                    -DENABLE_OAUTH2=ON
}

variant phonenumber description {Phone number parsing/validation using libphonenumber} {
    depends_lib-append \
                    port:libphonenumber-cpp
    configure.cxxflags-append \
                    -DI18N_PHONENUMBERS_USE_BOOST
    configure.args-append \
                    -DWITH_PHONENUMBER=${prefix}/lib
}

platform darwin {
    if {${configure.cxx_stdlib} eq "libstdc++"} {
        # google auth requires webkit2gtk-4.0 >= 2.11.91 json-glib >= 1.0.4
        if {[variant_isset oauth2]} {
            ui_error "Variant 'oauth2' not available for this macOS release"
        }
    }
}

livecheck.type      gnome
