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

github.setup    google googletest 1.17.0 v
github.tarball_from archive
revision        0

name            gtest
categories      devel
maintainers     {judaew @judaew} openmaintainer
license         BSD
description     Google's framework for writing C++ tests

long_description \
                Google's framework for writing C++ tests on a variety \
                of platforms (Linux, Mac OS X, Windows, Windows CE, \
                Symbian, etc).  Based on the xUnit architecture. \
                Supports automatic test discovery, a rich set of \
                assertions, user-defined assertions, death tests, \
                fatal and non-fatal failures, various options for \
                running the tests, and XML test report generation.

checksums       rmd160  6502a77c143be780deaf09b13ed187c75464cd70 \
                sha256  65fab701d9829d38cb77c14acdc431d2108bfdbf8979e40eb8ae567edf10b27c \
                size    885595

patchfiles      patch-add-gtest-version.diff

post-patch {
    reinplace "s,@@GOOGLETEST_VERSION@@,${version},g" \
        ${worksrcpath}/googlemock/CMakeLists.txt \
        ${worksrcpath}/googletest/CMakeLists.txt
}

legacysupport.newest_darwin_requires_legacy 14
legacysupport.use_mp_libcxx yes

compiler.cxx_standard   2017
cmake.set_cxx_standard  yes

# Avoid Xcode Clang < 11 (macOS 10.14):
# - Clang 7/8: error: initialization of const type without user-provided
#   default constructor (https://trac.macports.org/ticket/68029)
# - Clang 10 (10.14): std::function CTAD not supported, breaks test build
#   (https://trac.macports.org/ticket/73747)
compiler.blacklist-append \
                        {clang < 1100}

configure.optflags      -g
configure.args-append   -Dgtest_build_tests=ON \
                        -DBUILD_SHARED_LIBS=OFF

# Tests are broken for shared libs, see
# https://github.com/google/googletest/issues/3442
variant shared_libs description "Build dynamic library" {
configure.args-replace  -DBUILD_SHARED_LIBS=OFF \
                        -DBUILD_SHARED_LIBS=ON
}

# Prevent MacPorts headers from being used. They're not needed since
# googletest has no dependencies, and if a different version of googletest
# was already installed, its headers could cause the build to fail.
configure.cppflags-delete -I${prefix}/include
compiler.cpath

post-destroot {
    xinstall -d ${destroot}${prefix}/src/
    file copy ${worksrcpath}/googlemock ${destroot}${prefix}/src/
    file copy ${worksrcpath}/googletest ${destroot}${prefix}/src/
}

test.run    yes
test.cmd    "ulimit -c 0; make"
test.target test

# Ignore prerelease versions
github.livecheck.regex  {([^"-]+)}
