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

# MAP_ANONYMOUS and clock_gettime
legacysupport.newest_darwin_requires_legacy 15

# Ports that depend on this port must be revbump after update.
github.setup        abseil abseil-cpp 20260526.0
revision            0
name                abseil
categories          devel
maintainers         {judaew @judaew} openmaintainer
license             Apache-2

description         Abseil - C++ Common Libraries
long_description    Abseil is an open-source collection of C++ library \
                    code designed to augment the C++ standard \
                    library. The Abseil library code is collected from \
                    Google's own C++ code base, has been extensively \
                    tested and used in production.

checksums           rmd160  91fadb3d22c3cdeee301491deec1c95219139b79 \
                    sha256  6e1aee535473414164bf83e4ebc40240dec71a4701f8a642d906e95bea1aea0c \
                    size    2391476
github.tarball_from archive

patchfiles          patch-remove-Xarch-from-pkg-config.diff

# Abseil broken for 10.4-10.5, it's the pthread issue.
# See https://github.com/macports/macports-ports/pull/19905#issuecomment-1679652939
patchfiles-append   patch-pthread.diff

platform darwin 8 {
    patchfiles-append tiger-execinfo.patch
}

platform darwin {
    if {${build_arch} in [list ppc ppc64]} {
        patchfiles-append patch-darwin-ppc.diff
    }
    if {[string match *gcc* ${configure.compiler}]} {
        configure.ldflags-append \
                    -latomic
    }
}

platform darwin {
    if {${os.major} >= 11 && ${os.major} <= 12} {
        # some functions in xlocale.h are hidden without this define
        # https://trac.macports.org/ticket/67988
        configure.cxxflags-append -D_DARWIN_C_SOURCE
    }
}

# ignore pre releases
github.livecheck.regex  {([0-9.]+)}

compiler.cxx_standard   2014

# https://trac.macports.org/ticket/67553
# error: default initialization of an object of const type 'const absl::lts_20230125::Condition'
#   without a user-provided default constructo
compiler.blacklist-append \
                    {clang < 900}

configure.args-append \
                    -DBUILD_SHARED_LIBS=ON \
                    -DABSL_PROPAGATE_CXX_STD=ON

variant cxx17 conflicts cxx20 description "Use C++17" {
    compiler.cxx_standard   2017
    configure.args-append   -DCMAKE_CXX_STANDARD=17
}

variant cxx20 conflicts cxx17 description "Use C++20" {
    compiler.cxx_standard   2020
    configure.args-append   -DCMAKE_CXX_STANDARD=20
}

if ![variant_isset cxx17] {
    default_variants +cxx20
}

variant test description "Provide testing" {
    configure.args-append \
                    -DBUILD_SHARED_LIBS=OFF \
                    -DABSL_BUILD_TESTING=ON \
                    -DABSL_USE_EXTERNAL_GOOGLETEST=ON \
                    -DABSL_LOCAL_GOOGLETEST_DIR=${prefix}/src/googletest

    depends_test    port:gtest

    test.run        yes
    test.target     test
}
