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

github.setup        gflags gflags 2.2.2 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            3

categories          devel
maintainers         nomaintainer

description         commandline flags module for C++
long_description    The gflags package contains a library that implements commandline flags processing. \
                    As such it's a replacement for getopt(). It has increased flexibility, \
                    including built-in support for C++ types like string, and \
                    the ability to define flags in the source file in which \
                    they're used.

license             BSD

checksums           rmd160  9748753d2cf4d581cd0881bd5f5c1e3dac365896 \
                    sha256  660b2cd42849d720f8b403c4e78b6e16bdd05c9af33c0fdd19860c96d7b695c0 \
                    size    98723

# While gflags builds fine with gcc-4.2, its dependent google-glog does not.
# However they both should be built by the same compiler, otherwise google-glog build fails.
# https://trac.macports.org/ticket/65645
# https://trac.macports.org/ticket/65994
compiler.blacklist-append \
                    *gcc-4.0 *gcc-4.2 *gcc-4.3 *gcc-4.4 *gcc-4.5

# Rosetta ignores blacklist and still tries to use llvm-g++-4.2.
# Prioritize newer gcc; list versions that are realistically used and confirmed to build and work.
platform darwin 10 powerpc {
    compiler.whitelist \
                    macports-gcc-12 macports-gcc-11 macports-gcc-10 macports-gcc-7 macports-gcc-6
}

configure.args-append \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_STATIC_LIBS=ON \
    -DGFLAGS_BUILD_gflags_LIB=ON \
    -DREGISTER_INSTALL_PREFIX=OFF

platform darwin {
    set port_cxxflags "${configure.cxxflags}"

    # Needed to support building dependents. See: https://kumasento.github.io/2020-06-12-glog-gflags-and-c-abi/
    if {${os.major} < 16} {
        set port_cxxflags "${port_cxxflags} -D_GLIBCXX_USE_CXX11_ABI=0"
    }

    configure.args-append \
        -DCMAKE_CXX_FLAGS="${port_cxxflags}"
}
