# -*- 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           active_variants 1.1
PortGroup           cmake 1.1
PortGroup           github 1.0
PortGroup           legacysupport 1.1
PortGroup           openssl 1.0

github.setup        google s2geometry 0.11.1 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            5
categories          math science
license             Apache-2
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
description         Computational geometry and spatial indexing on the sphere
long_description    {*}${description}
homepage            https://s2geometry.io
checksums           rmd160  cd62ef9c3318960abc1e5c8b1b20e6f8e078824b \
                    sha256  c1ceec31e6258688c72b243e48b040b650cdb71c59d4bc36231822ef6bd63655 \
                    size    1180916

# clock_gettime needed for abseil
# https://github.com/macports/macports-ports/pull/19905#issuecomment-1680281240
legacysupport.newest_darwin_requires_legacy 15

depends_lib-append  port:abseil

# https://github.com/google/s2geometry/issues/315
patchfiles          patch-fix-build.diff

# The following is correct, i.e. not only for Darwin.
# https://github.com/google/s2geometry/issues/279
platform powerpc {
    patchfiles-append \
                    patch-ppc-constexpr.diff
}

# C++ standard should match that of abseil port:
compiler.cxx_standard  \
                    2017

configure.args-append \
                    -DBUILD_SHARED_LIBS=ON \
                    -DBUILD_EXAMPLES=OFF \
                    -DBUILD_TESTS=OFF

if {[string match *gcc* ${configure.compiler}]} {
    configure.ldflags-append \
                    -latomic
}

# FIXME: Big-endian platforms are partly supported.
# A number of tests fail on ppc.
# https://github.com/google/s2geometry/issues/316
variant tests description "Enable testing" {
    depends_build-append \
                    port:gtest
    require_active_variants gtest shared_libs

    configure.args-replace \
                    -DBUILD_TESTS=OFF -DBUILD_TESTS=ON

    configure.args-append \
                    -DGOOGLETEST_ROOT=${prefix}/src

    test.env-append DYLD_LIBRARY_PATH=${cmake.build_dir}:${prefix}/lib

    test.run        yes
}
