# -*- 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           boost 1.0
PortGroup           cmake 1.1
PortGroup           github 1.0
PortGroup           qt5 1.0

github.setup        pcraster pcraster 4.4.1 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            4

categories          gis
license             GPL
maintainers         {yahoo.com:n_larsson @nilason} openmaintainer
description         PCRaster - Environmental modelling software
long_description    PCRaster is a collection of tools and software libraries   \
                    tailored to the construction of spatio-temporal            \
                    environmental models. Application domains are amongst      \
                    others hydrology (rainfall-runoff, global water balance,   \
                    groundwater (with Modflow)), ecology, or land use change.

homepage            https://pcraster.geo.uu.nl

checksums           rmd160  ed65c46146cffb85922d77b33c065ec11014a031 \
                    sha256  76782c9b01d5c14a46a0f2ddf141dc436e2082aa09e93bbccdc428e7580823f6 \
                    size    24894109

patchfiles-append   patch-configure_python_extension.diff

compiler.cxx_standard \
                    2017

configure.args-append \
                    -DPCRASTER_BUILD_MLDD=ON \
                    -DPCRASTER_BUILD_MOC=ON \
                    -DPCRASTER_BUILD_MULTICORE=OFF \
                    -DPCRASTER_WITH_FLAGS_IPO=OFF

if {[variant_isset debug]} {
    configure.cflags-append   -DDEBUG_BUILD -DDEBUG_DEVELOP
    configure.cxxflags-append -DDEBUG_BUILD -DDEBUG_DEVELOP
}

depends_lib-append  port:gdal \
                    port:ncurses \
                    port:xercesc3

qt5.depends_component qtcharts

# Python variants
set python_suffixes {310 311 312 313}
set python_variants {}
set plugin_variants {}
foreach pyver ${python_suffixes} {
    lappend python_variants python${pyver}
    lappend plugin_variants plugin_support${pyver}
}
foreach pyver ${python_suffixes} {
    set vrt python${pyver}
    set pyversion [string index ${pyver} 0].[string range ${pyver} 1 end]
    set index [lsearch -exact ${python_variants} ${vrt}]
    set conf [lreplace ${python_variants} ${index} ${index}]
    set pydir ${frameworks_dir}/Python.framework/Versions/${pyversion}
    variant ${vrt} description "Use Python ${pyversion} bindings" conflicts {*}${conf} "
        depends_lib-append      port:python${pyver} \
                                port:py${pyver}-pybind11 \
                                port:py${pyver}-pyqt5-chart \
                                port:py${pyver}-matplotlib \
                                port:py${pyver}-numpy

        configure.args-append   -DPython3_EXECUTABLE=${pydir}/bin/python${pyversion} \
                                -DPCRASTER_PYTHON_INSTALL_DIR=${pydir}/lib/python${pyversion}/site-packages
    "
}
# Python default (keep in sync with QGIS' default Python variant)
set python_default "if {"
foreach pyver ${python_suffixes} {
    set python_default "${python_default}!\[variant_isset python${pyver}\] && "
}
set python_default [string range ${python_default} 0 end-4]
set python_default "${python_default}} { default_variants +python312}"
eval ${python_default}

post-destroot {
    move ${destroot}${prefix}/bin/legend ${destroot}${prefix}/bin/pcrlegend
}

notes "The utility 'legend' is renamed to 'pcrlegend' due to conflict with mapserver."
