summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/magics/package.py
blob: 3bb6ff1b3c708f816b88ca04b007f4eeabe1ef85 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import glob
import os

from spack.package import *


class Magics(CMakePackage):
    """Magics is the latest generation of the ECMWF's Meteorological plotting
    software MAGICS. Although completely redesigned in C++, it is intended
    to be as backwards-compatible as possible with the Fortran interface."""

    homepage = "https://software.ecmwf.int/wiki/display/MAGP/Magics"
    url = "https://confluence.ecmwf.int/download/attachments/3473464/Magics-4.2.4-Source.tar.gz?api=v2"
    list_url = "https://software.ecmwf.int/wiki/display/MAGP/Releases"

    license("Apache-2.0")

    # The policy on which minor releases remain available and which get deleted
    # after a newer version becomes available is unclear.
    version("4.9.3", sha256="c01ee7c4b05c5512e93e573748d2766d299fa1a60c226f2a0d0989f3d7c5239b")
    version("4.4.0", sha256="544058cd334f3e28a16d00ea7811e13cdf282f9c1ebec2ad7868171d925abd24")
    version("4.3.3", sha256="27d3de71cf41f3d557fd85dabaea2baaab34c4c6422a5b5b15071a6a53387601")
    version("4.3.1", sha256="b1995e2f5bf24943715446d1302cc5d7de4cacfe4cee7c3cfd1037ac183cd181")
    version("4.3.0", sha256="f6c0d32c243913e53320dd94ce8e1e6a64bd9a44af77d5ac32c062bc18355b8a")
    version("4.2.6", sha256="9b34a375d9125ab6e8a715b970da2e479f96370bac6a5bb8a015a079ed9e027c")
    version("4.2.4", sha256="920c7dbb1aaabe65a31c6c18010829210f8b2f8d614b6c405dc5a4530e346f07")
    version("4.1.0", sha256="da626c31f53716990754dd72ab7b2f3902a8ad924b23ef3309bd14900d170541")

    conflicts("%gcc@11:", when="@:4.4", msg="missing #include <limits>")

    variant(
        "grib",
        default="eccodes",
        values=("eccodes", "grib-api"),
        description="Specify GRIB backend",
    )
    variant("netcdf", default=False, description="Enable NetCDF support")
    variant("cairo", default=False, description="Enable cairo support[png/jpeg]")
    variant("fortran", default=False, description="Enable Fortran interface")
    variant("metview", default=False, description="Enable metview support")
    variant("qt", default=False, description="Enable metview support with qt")
    variant("bufr", default=False, description="Enable BUFR support")

    variant(
        "build_type",
        default="RelWithDebInfo",
        description="The build type to build",
        values=("Debug", "Release", "RelWithDebInfo", "Production"),
    )

    # Build dependencies
    depends_on("cmake@2.8.11:", type="build")
    depends_on("pkgconfig", type="build")
    depends_on("python", type="build")
    depends_on("perl", type="build")
    depends_on("perl-xml-parser", type="build")

    # Non-optional dependencies
    # change of proj4 api starting from version 4.3.0
    # https://github.com/OSGeo/PROJ/wiki/proj.h-adoption-status
    depends_on("proj@:5", when="@:4.2.6")
    depends_on("proj@6:", when="@4.3:")
    depends_on("boost+exception")
    depends_on("expat")

    # Magics (at least up to version 2.34.3) should directly and
    # unconditionally depend on zlib, which is not reflected neither in the
    # installation instructions nor explicitly stated in the cmake script:
    # zlib is pulled as a dependency of png. The dependency on png is formally
    # optional and depends on an unofficial flag ENABLE_PNG, which is
    # redundant, because png is used only when ENABLE_CAIRO=ON. The problem is
    # that files that make calls to png library get compiled and linked
    # unconditionally, which makes png a non-optional dependency (and
    # ENABLE_PNG always has to be set to ON).
    depends_on("zlib-api")
    depends_on("libpng")

    # GRIB support is non-optional, regardless of what the instruction says.
    depends_on("eccodes", when="grib=eccodes")
    depends_on("grib-api", when="grib=grib-api")

    # Even if netcdf is disabled and -DENABLE_NETCDF=OFF is set, building
    # magics still requires legacy netcdf-cxx
    depends_on("netcdf-cxx", when="@4.1.0:4.3.1")

    # Optional dependencies
    depends_on("netcdf-cxx", when="+netcdf")
    depends_on("pango", when="+cairo")
    depends_on("libemos grib=eccodes", when="+bufr grib=eccodes")
    depends_on("libemos grib=grib-api", when="+bufr grib=grib-api")
    depends_on("qt", when="+metview+qt")

    depends_on("python", type=("build"))
    depends_on("py-jinja2", type=("build"))

    # Replace system python and perl by spack versions:
    def patch(self):
        for plfile in glob.glob("*/*.pl"):
            filter_file("#!/usr/bin/perl", "#!/usr/bin/env perl", plfile)
        for pyfile in glob.glob("*/*.py"):
            filter_file(
                "#!/usr/bin/python",
                "#!/usr/bin/env {0}".format(os.path.basename(self.spec["python"].command.path)),
                pyfile,
            )
        filter_file("HAVE_GRIB", "SKIP_REQUIRED_FILE_WASREMOVED", "test/CMakeLists.txt")

    def cmake_args(self):
        args = ["-DENABLE_ODB=OFF", "-DENABLE_SPOT=OFF"]

        if self.spec.variants["grib"].value == "eccodes":
            args.append("-DENABLE_ECCODES=ON")
        else:
            if self.spec.satisfies("@2.29.1:"):
                args.append("-DENABLE_ECCODES=OFF")

        # magics@4.2.4:4.3.1 cannot be built without netcdf
        if "+netcdf" in self.spec or self.spec.satisfies("@4.1.0:4.3.1"):
            args.append("-DENABLE_NETCDF=ON")
        else:
            args.append("-DENABLE_NETCDF=OFF")

        if "+cairo" in self.spec:
            args.append("-DENABLE_CAIRO=ON")
        else:
            args.append("-DENABLE_CAIRO=OFF")

        if "+fortran" in self.spec:
            args.append("-DENABLE_FORTRAN=ON")
        else:
            args.append("-DENABLE_FORTRAN=OFF")

        if "+bufr" in self.spec:
            args.append("-DENABLE_BUFR=ON")
        else:
            args.append("-DENABLE_BUFR=OFF")

        if "+metview" in self.spec:
            if "+qt" in self.spec:
                args.append("-DENABLE_METVIEW=ON")
                if self.spec["qt"].satisfies("@5:"):
                    args.append("-DENABLE_QT5=ON")
            else:
                args.append("-DENABLE_METVIEW_NO_QT=ON")
        else:
            args.append("-DENABLE_METVIEW=OFF")

        return args