# -*- 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 cmake     1.1
PortGroup compilers 1.0
if {[variant_isset qt5]} {
    PortGroup qt5   1.0
}

name                magicspp
version             4.16.0
revision            0
maintainers         {takeshi @tenomoto}
license             Apache-2
categories          science
description         ECMWF's Meteorological plotting software
homepage            https://confluence.ecmwf.int/display/MAGP/Magics
master_sites        https://confluence.ecmwf.int/download/attachments/3473464/
distname            Magics-${version}-Source
checksums           rmd160  f73520974f9d72e0daeb7e3eef8d2b8ec280b2b6 \
                    sha256  b5cf365e10e43abbb2e0b14db8e8d8db90486031f6c0de24b0b01c17a0197cf5 \
                    size    31620942
long_description \
    Magics++ is the latest generation of the ECMWF's Meteorological plotting \
    software MAGICS (Meteorological Applications Graphics Integrated Colour System) \
    redesigned in C++.  Magics++ offers interfaces in Fortran, C, and MagML, \
    a plot description language based on XML.  The library supports the plotting of \
    contours, wind fields, observations, satellite images, symbols, text, axis \
    and graphs (including boxplots). Input data can be in GRIB 1 and 2, BUFR and NetCDF \
    or retrieved from an ODB database. The produced meteorological plots can be saved \
    in various formats, such as PostScript, EPS, PDF, GIF, PNG and SVG.

fetch.ignore_sslcert    yes

compilers.choose    cxx fc
compilers.setup     require_fortran -g95

depends_build-append \
                    port:flex \
                    port:pkgconfig
depends_lib         port:tiff \
                    port:libgeotiff \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:ecCodes \
                    port:netcdf \
                    port:netcdf-cxx \
                    port:mesa \
                    port:xorg-libXau \
                    port:xorg-libXdmcp \
                    port:gd2 \
                    path:lib/pkgconfig/pango.pc:pango \
                    port:ghostscript \
                    port:proj9 \
                    port:libpng \
                    port:zlib \
                    port:jasper \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:openjpeg \
                    port:expat \
                    port:hdf5 \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    port:gettext \
                    port:fftw-3
require_active_variants path:lib/pkgconfig/cairo.pc:cairo x11

universal_variant   no

patchfiles-append   patch-CMakeLists.txt.diff

if {${os.platform} eq "darwin" && ${os.major} < 12} {
    known_fail      yes
    pre-fetch {
        ui_error "${name} is not supported on Lion or older."
        return -code error "unsupported platform"
    }
}

configure.args-append   -DCMAKE_BUILD_TYPE=Release \
                        -DCMAKE_Fortran_COMPILER=${configure.fc} \
                        -DENABLE_CAIRO=ON \
                        -DENABLE_FORTRAN=OFF \
                        -DENABLE_GEOTIFF=ON \
                        -DENABLE_LARGE_FILE_SUPPORT=ON \
                        -DENABLE_NETCDF=ON \
                        -DENABLE_METVIEW=OFF \
                        -DENABLE_METVIEW_NO_QT=ON \
                        -DENABLE_ODB=OFF \
                        -DENABLE_SPOT=OFF \
                        -DENABLE_EFAS=OFF \
                        -DEXPAT_INCLUDE_DIR=${prefix}/include \
                        -DEXPAT_LIBRARY=${prefix}/lib/libexpat.dylib \
                        -DECCODES_PATH=${prefix} \
                        -DGEOTIFF_PATH=${prefix} \
                        -DPKG_CONFIG_EXECUTABLE=${prefix}/bin/pkg-config \
                        -DPROJ_INCLUDE_DIR=${prefix}/lib/proj9/include \
                        -DPROJ_LIBRARY=${prefix}/lib/proj9/lib/libproj.dylib
configure.ldflags-append \
                        -ltiff

post-configure {
    file delete -force ${worksrcpath}/src/boost
}

if {[fortran_variant_isset]} {
    configure.args-delete   -DENABLE_FORTRAN=OFF
}

variant qt5 description {Add support for MetView GUI} {
    configure.args-delete   -DENABLE_METVIEW_NO_QT=ON \
                            -DENABLE_METVIEW=OFF
    configure.args-append   -DENABLE_METVIEW_NO_QT=OFF \
                            -DENABLE_METVIEW=ON
}

notes "Install Python interface from pypi e.g.
pip install --user Magics
"

livecheck.type          regex
livecheck.url           ${homepage}
livecheck.regex         {Magics-([0-9]+\.[0-9]+\.[0-9]+)-Source.tar.gz}
