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

github.setup    google googletest 1.15.2 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  149354ba0981d3f90165d9ea3c8727d085f51e2f \
                sha256  7b42b4d6ed48810c5362c265a17faebe90dc2373c885e5216439d37927f02926 \
                size    872667

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   2014
cmake.set_cxx_standard  yes

# Avoid Xcode Clang 7/8: error: initialization of const type without user-provided default constructor
# See: https://trac.macports.org/ticket/68029
compiler.blacklist-append \
                        {clang < 900}

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  {([^"-]+)}