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

github.setup        PDAL PDAL 2.5.6
revision            0
categories          gis
license             BSD

maintainers         {vince @Veence} {yahoo.com:n_larsson @nilason} openmaintainer

description         PDAL - Point Cloud Manipulation Library

long_description    PDAL is a C++ BSD library for translating and\
                    manipulating point cloud data. It is very much\
                    like the GDAL library which handles raster and\
                    vector data.

homepage            https://www.pdal.io
distname            PDAL-${version}-src

# Enable use of 'macports-libcxx' for macOS 10.14 and earlier, as port uses
# libcxx features normally only available on 10.15 and later.
legacysupport.use_mp_libcxx \
                        yes
legacysupport.newest_darwin_requires_legacy \
                        18

compiler.cxx_standard  2017

checksums           rmd160  7173a396becdbd24989ca74d923c003340630f2b \
                    sha256  10cb0c8cad970cb23b774470921562332870c350d999308fb108742c4b4ee287 \
                    size    92538105

depends_build-append \
                    port:pkgconfig \

depends_lib-append  port:geos \
                    port:gdal \
                    port:libgeotiff \
                    port:zlib \
                    port:zstd \
                    port:libxml2 \
                    port:curl \
                    port:libunwind

patchfiles-append   patch-powerpc.diff

configure.args      -DWITH_ZSTD=ON \
                    -DWITH_ZLIB=ON \
                    -DWITH_LZMA=OFF \
                    -DWITH_TESTS=OFF \
                    -DBUILD_TOOLS_NITFWRAP=OFF \
                    -DWITH_COMPLETION=OFF

configure.args-append \
                    -DBUILD_PLUGIN_CPD=OFF \
                    -DBUILD_PLUGIN_DRACO=OFF \
                    -DBUILD_PLUGIN_I3S=OFF \
                    -DBUILD_PLUGIN_ICEBRIDGE=OFF \
                    -DBUILD_PLUGIN_HDF=OFF \
                    -DBUILD_PLUGIN_MATLAB=OFF \
                    -DBUILD_PLUGIN_NITF=OFF \
                    -DBUILD_PLUGIN_OPENSCENEGRAPH=OFF \
                    -DBUILD_PLUGIN_PGPOINTCLOUD=OFF \
                    -DBUILD_PLUGIN_RIVLIB=OFF \
                    -DBUILD_PLUGIN_RDBLIB=OFF \
                    -DBUILD_PLUGIN_MBIO=OFF \
                    -DBUILD_PLUGIN_FBX=OFF \
                    -DBUILD_PLUGIN_TEASER=OFF \
                    -DBUILD_PLUGIN_TILEDB=OFF \
                    -DBUILD_PLUGIN_TRAJECTORY=OFF \
                    -DBUILD_PLUGIN_E57=OFF

# PostgreSQL variants
set postgresql_suffixes {15 14 13 12 11 10 95 96}
set def_psql_var "if {"

set postgresql_variants {}
foreach suffix ${postgresql_suffixes} {
    lappend postgresql_variants postgresql${suffix}
    set def_psql_var "${def_psql_var}![variant_isset postgresql${suffix}] && "
}

# Set default variant
set def_psql_var [string range ${def_psql_var} 0 end-4]
set def_psql_var "${def_psql_var}} {default_variants +postgresql15}"
eval ${def_psql_var}

foreach suffix ${postgresql_suffixes} {
    set vrt postgresql${suffix}
    set pgversion [string index ${suffix} 0].[string index ${suffix} 1]
    set index [lsearch -exact ${postgresql_variants} ${vrt}]
    set conf [lreplace ${postgresql_variants} ${index} ${index}]

    variant ${vrt} description "Use PostgreSQL ${pgversion}" conflicts {*}${conf} "
        depends_lib-append      port:${vrt}
        configure.args-append   -DPostgreSQL_ROOT=${prefix}/lib/${vrt} \
                                -DPostgreSQL_INCLUDE_DIR=${prefix}/include/${vrt}
        configure.env-append    PostgreSQL_ADDITIONAL_VERSIONS=15
    "
}

# Kludge: needs proper fixing
configure.cppflags-append   -g
configure.ldflags-append   -g
post-configure {
    reinplace "s|-isysroot\[^ \]*||" ${workpath}/build/bin/pdal-config
}
