wgrib2: add cmake builder (#48447)
* wgrib2: add cmake builder * wgrib2 add maintainer * [@spackbot] updating style on behalf of AlexanderRichert-NOAA * style fixes; add tar.gz for old vers * license update * wgrib2: don't restrict openjpeg variant by version * Update var/spack/repos/builtin/packages/wgrib2/package.py Co-authored-by: Massimiliano Culpo <massimiliano.culpo@gmail.com> * [@spackbot] updating style on behalf of AlexanderRichert-NOAA * Update package.py * Update package.py * Update var/spack/repos/builtin/packages/wgrib2/package.py Co-authored-by: Wouter Deconinck <wdconinc@gmail.com> --------- Co-authored-by: Massimiliano Culpo <massimiliano.culpo@gmail.com> Co-authored-by: Wouter Deconinck <wdconinc@gmail.com>
This commit is contained in:
parent
68517389a0
commit
9c5b3ccb4e
@ -2,20 +2,65 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import spack.build_systems.cmake
|
||||||
|
import spack.build_systems.makefile
|
||||||
from spack.package import *
|
from spack.package import *
|
||||||
|
|
||||||
|
variant_map_common = {
|
||||||
|
"netcdf3": "USE_NETCDF3",
|
||||||
|
"netcdf4": "USE_NETCDF4",
|
||||||
|
"mysql": "USE_MYSQL",
|
||||||
|
"udf": "USE_UDF",
|
||||||
|
"regex": "USE_REGEX",
|
||||||
|
"tigge": "USE_TIGGE",
|
||||||
|
"proj4": "USE_PROJ4",
|
||||||
|
"aec": "USE_AEC",
|
||||||
|
"g2c": "USE_G2CLIB",
|
||||||
|
"png": "USE_PNG",
|
||||||
|
"jasper": "USE_JASPER",
|
||||||
|
"openmp": "USE_OPENMP",
|
||||||
|
"wmo_validation": "USE_WMO_VALIDATION",
|
||||||
|
"ipolates": "USE_IPOLATES",
|
||||||
|
"disable_alarm": "DISABLE_ALARM",
|
||||||
|
"fortran_api": "MAKE_FTN_API",
|
||||||
|
"disable_stat": "DISABLE_STAT",
|
||||||
|
"openjpeg": "USE_OPENJPEG",
|
||||||
|
}
|
||||||
|
|
||||||
class Wgrib2(MakefilePackage):
|
variant_map_makefile = {"spectral": "USE_SPECTRAL"}
|
||||||
|
|
||||||
|
variant_map_cmake = {
|
||||||
|
"netcdf": "USE_NETCDF",
|
||||||
|
"disable_timezone": "DISABLE_TIMEZONE",
|
||||||
|
"enable_docs": "ENABLE_DOCS",
|
||||||
|
}
|
||||||
|
|
||||||
|
variant_map_makefile.update(variant_map_common)
|
||||||
|
variant_map_cmake.update(variant_map_common)
|
||||||
|
|
||||||
|
|
||||||
|
class Wgrib2(MakefilePackage, CMakePackage):
|
||||||
"""Utility for interacting with GRIB2 files"""
|
"""Utility for interacting with GRIB2 files"""
|
||||||
|
|
||||||
homepage = "https://www.cpc.ncep.noaa.gov/products/wesley/wgrib2"
|
homepage = "https://www.cpc.ncep.noaa.gov/products/wesley/wgrib2"
|
||||||
url = "https://www.ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz.v2.0.8"
|
url = "https://github.com/NOAA-EMC/wgrib2/archive/refs/tags/v3.5.0.tar.gz"
|
||||||
|
git = "https://github.com/NOAA-EMC/wgrib2.git"
|
||||||
|
|
||||||
maintainers("t-brown", "AlexanderRichert-NOAA", "Hang-Lei-NOAA", "edwardhartnett")
|
maintainers(
|
||||||
|
"AlysonStahl-NOAA", "t-brown", "AlexanderRichert-NOAA", "Hang-Lei-NOAA", "edwardhartnett"
|
||||||
|
)
|
||||||
|
|
||||||
|
build_system(
|
||||||
|
conditional("cmake", when="@3.2:"), conditional("makefile", when="@:3.1"), default="cmake"
|
||||||
|
)
|
||||||
|
|
||||||
|
version("develop", branch="develop")
|
||||||
|
version("3.5.0", sha256="b27b48228442a08bddc3d511d0c6335afca47252ae9f0e41ef6948f804afa3a1")
|
||||||
|
version("3.4.0", sha256="ecbce2209c09bd63f1bca824f58a60aa89db6762603bda7d7d3fa2148b4a0536")
|
||||||
|
version("3.3.0", sha256="010827fba9c31f05807e02375240950927e9e51379e1444388153284f08f58e2")
|
||||||
|
version("3.2.0", sha256="ac3ace77a32c2809cbc4538608ad64aabda2c9c1e44e7851da79764a6eb3c369")
|
||||||
version(
|
version(
|
||||||
"3.1.1",
|
"3.1.1",
|
||||||
sha256="9236f6afddad76d868c2cfdf5c4227f5bdda5e85ae40c18bafb37218e49bc04a",
|
sha256="9236f6afddad76d868c2cfdf5c4227f5bdda5e85ae40c18bafb37218e49bc04a",
|
||||||
@ -37,27 +82,51 @@ class Wgrib2(MakefilePackage):
|
|||||||
extension="tar.gz",
|
extension="tar.gz",
|
||||||
)
|
)
|
||||||
|
|
||||||
depends_on("c", type="build") # generated
|
depends_on("c", type="build")
|
||||||
depends_on("fortran", type="build") # generated
|
depends_on("fortran", type="build")
|
||||||
|
|
||||||
|
def url_for_version(self, version):
|
||||||
|
if version >= Version("3.2.0"):
|
||||||
|
url_fmt = "https://github.com/NOAA-EMC/wgrib2/archive/refs/tags/v{0}.tar.gz"
|
||||||
|
else:
|
||||||
|
url_fmt = "https://www.ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz.v{0}"
|
||||||
|
return url_fmt.format(version)
|
||||||
|
|
||||||
variant("netcdf3", default=True, description="Link in netcdf3 library to write netcdf3 files")
|
|
||||||
variant(
|
variant(
|
||||||
"netcdf4", default=False, description="Link in netcdf4 library to write netcdf3/4 files"
|
"netcdf3",
|
||||||
|
default=True,
|
||||||
|
description="Link in netcdf3 library to write netcdf3 files",
|
||||||
|
when="@:3.1",
|
||||||
)
|
)
|
||||||
variant(
|
variant(
|
||||||
"ipolates",
|
"netcdf4",
|
||||||
default="3",
|
default=False,
|
||||||
description="Use to interpolate to new grids (0 = OFF, 1 = ip, 3 = ip2)",
|
description="Link in netcdf4 library to write netcdf3/4 files",
|
||||||
values=("0", "1", "3"),
|
when="@:3.3",
|
||||||
)
|
)
|
||||||
variant("spectral", default=False, description="Spectral interpolation in -new_grid")
|
variant(
|
||||||
|
"netcdf",
|
||||||
|
default=False,
|
||||||
|
description="Link in netcdf4 library to write netcdf3/4 files",
|
||||||
|
when="@3.4:",
|
||||||
|
)
|
||||||
|
variant("ipolates", default=False, description="Use to interpolate to new grids")
|
||||||
|
variant(
|
||||||
|
"spectral", default=False, description="Spectral interpolation in -new_grid", when="@:3.1"
|
||||||
|
)
|
||||||
|
# Not currently working for @3.2:
|
||||||
variant(
|
variant(
|
||||||
"fortran_api",
|
"fortran_api",
|
||||||
default=True,
|
default=True,
|
||||||
description="Make wgrib2api which allows fortran code to read/write grib2",
|
description="Make wgrib2api which allows fortran code to read/write grib2",
|
||||||
)
|
)
|
||||||
|
# Not currently working for @3.2:
|
||||||
|
# variant("lib", default=True, description="Build library", when="@3.2:")
|
||||||
variant(
|
variant(
|
||||||
"mysql", default=False, description="Link in interface to MySQL to write to mysql database"
|
"mysql",
|
||||||
|
default=False,
|
||||||
|
description="Link in interface to MySQL to write to mysql database",
|
||||||
|
when="@:3.1",
|
||||||
)
|
)
|
||||||
variant(
|
variant(
|
||||||
"udf",
|
"udf",
|
||||||
@ -66,11 +135,21 @@ class Wgrib2(MakefilePackage):
|
|||||||
)
|
)
|
||||||
variant("regex", default=True, description="Use regular expression library (POSIX-2)")
|
variant("regex", default=True, description="Use regular expression library (POSIX-2)")
|
||||||
variant("tigge", default=True, description="Ability for TIGGE-like variable names")
|
variant("tigge", default=True, description="Ability for TIGGE-like variable names")
|
||||||
variant("proj4", default=False, description="The proj4 library is used to verify gctpc.")
|
variant(
|
||||||
|
"proj4",
|
||||||
|
default=False,
|
||||||
|
description="The proj4 library is used to verify gctpc.",
|
||||||
|
when="@:3.1",
|
||||||
|
)
|
||||||
variant(
|
variant(
|
||||||
"aec", default=True, description="Use the libaec library for packing with GRIB2 template"
|
"aec", default=True, description="Use the libaec library for packing with GRIB2 template"
|
||||||
)
|
)
|
||||||
variant("g2c", default=False, description="Include NCEP g2clib (mainly for testing purposes)")
|
variant(
|
||||||
|
"g2c",
|
||||||
|
default=False,
|
||||||
|
description="Include NCEP g2clib (mainly for testing purposes)",
|
||||||
|
when="@:3.1",
|
||||||
|
)
|
||||||
variant(
|
variant(
|
||||||
"disable_timezone", default=False, description="Some machines do not support timezones"
|
"disable_timezone", default=False, description="Some machines do not support timezones"
|
||||||
)
|
)
|
||||||
@ -83,46 +162,42 @@ class Wgrib2(MakefilePackage):
|
|||||||
variant("jasper", default=True, description="JPEG compression using Jasper")
|
variant("jasper", default=True, description="JPEG compression using Jasper")
|
||||||
variant("openmp", default=True, description="OpenMP parallelization")
|
variant("openmp", default=True, description="OpenMP parallelization")
|
||||||
variant("wmo_validation", default=False, description="WMO validation")
|
variant("wmo_validation", default=False, description="WMO validation")
|
||||||
|
# variant("shared", default=False, description="Enable shared library", when="+lib")
|
||||||
|
variant("disable_stat", default=False, description="Disable POSIX feature", when="@:3.1")
|
||||||
|
variant("openjpeg", default=False, description="Enable OpenJPEG")
|
||||||
|
variant(
|
||||||
|
"enable_docs", default=False, description="Build doxygen documentation", when="@3.4.0:"
|
||||||
|
)
|
||||||
|
|
||||||
conflicts("+netcdf3", when="+netcdf4")
|
conflicts("+netcdf3", when="+netcdf4")
|
||||||
|
conflicts("+netcdf3", when="+netcdf")
|
||||||
conflicts("+openmp", when="%apple-clang")
|
conflicts("+openmp", when="%apple-clang")
|
||||||
|
|
||||||
depends_on("wget", type=("build"), when="+netcdf4")
|
depends_on("ip@5.1:", when="@3.5: +ipolates")
|
||||||
|
depends_on("lapack", when="@3.5: +ipolates")
|
||||||
|
depends_on("libaec@1.0.6:", when="@3.2: +aec")
|
||||||
|
depends_on("netcdf-c", when="@3.2: +netcdf4")
|
||||||
|
depends_on("jasper@:2", when="@3.2:3.4 +jasper")
|
||||||
|
depends_on("g2c", when="@3.5: +jasper")
|
||||||
|
depends_on("zlib-api", when="@3.2: +png")
|
||||||
|
depends_on("libpng", when="@3.2: +png")
|
||||||
|
depends_on("openjpeg", when="@3.2:3.4 +openjpeg")
|
||||||
|
depends_on("g2c +openjpeg", when="@3.5: +openjpeg")
|
||||||
|
requires("^g2c@1.9:", when="@3.5: ^g2c")
|
||||||
|
|
||||||
variant_map = {
|
@when("@:2 ^gmake@4.2:")
|
||||||
"netcdf3": "USE_NETCDF3",
|
def patch(self):
|
||||||
"netcdf4": "USE_NETCDF4",
|
filter_file(r"\\#define", "#define", "makefile")
|
||||||
"spectral": "USE_SPECTRAL",
|
|
||||||
"mysql": "USE_MYSQL",
|
|
||||||
"udf": "USE_UDF",
|
|
||||||
"regex": "USE_REGEX",
|
|
||||||
"tigge": "USE_TIGGE",
|
|
||||||
"proj4": "USE_PROJ4",
|
|
||||||
"aec": "USE_AEC",
|
|
||||||
"g2c": "USE_G2CLIB",
|
|
||||||
"png": "USE_PNG",
|
|
||||||
"jasper": "USE_JASPER",
|
|
||||||
"openmp": "USE_OPENMP",
|
|
||||||
"wmo_validation": "USE_WMO_VALIDATION",
|
|
||||||
"ipolates": "USE_IPOLATES",
|
|
||||||
"disable_timezone": "DISABLE_TIMEZONE",
|
|
||||||
"disable_alarm": "DISABLE_ALARM",
|
|
||||||
"fortran_api": "MAKE_FTN_API",
|
|
||||||
}
|
|
||||||
|
|
||||||
# Disable parallel build
|
|
||||||
parallel = False
|
|
||||||
|
|
||||||
# Use Spack compiler wrapper flags
|
# Use Spack compiler wrapper flags
|
||||||
def inject_flags(self, name, flags):
|
def inject_flags(self, name, flags):
|
||||||
spec = self.spec
|
|
||||||
if name == "cflags":
|
if name == "cflags":
|
||||||
if spec.satisfies("%apple-clang"):
|
if self.spec.compiler.name == "apple-clang":
|
||||||
flags.append("-Wno-error=implicit-function-declaration")
|
flags.append("-Wno-error=implicit-function-declaration")
|
||||||
|
|
||||||
# When mixing Clang/gfortran need to link to -lgfortran
|
# When mixing Clang/gfortran need to link to -lgfortran
|
||||||
# Find this by searching for gfortran/../lib
|
# Find this by searching for gfortran/../lib
|
||||||
if spec.satisfies("%apple-clang") or spec.satisfies("%clang"):
|
if self.spec.compiler.name in ["apple-clang", "clang"]:
|
||||||
if "gfortran" in self.compiler.fc:
|
if "gfortran" in self.compiler.fc:
|
||||||
output = Executable(self.compiler.fc)("-###", output=str, error=str)
|
output = Executable(self.compiler.fc)("-###", output=str, error=str)
|
||||||
libdir = re.search("--libdir=(.+?) ", output).group(1)
|
libdir = re.search("--libdir=(.+?) ", output).group(1)
|
||||||
@ -130,13 +205,30 @@ def inject_flags(self, name, flags):
|
|||||||
|
|
||||||
return (flags, None, None)
|
return (flags, None, None)
|
||||||
|
|
||||||
|
|
||||||
|
class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder):
|
||||||
|
# Disable parallel build
|
||||||
|
parallel = False
|
||||||
|
|
||||||
|
def cmake_args(self):
|
||||||
|
args = [self.define_from_variant(variant_map_cmake[k], k) for k in variant_map_cmake]
|
||||||
|
# args.append(self.define_from_variant("BUILD_LIB", "lib"))
|
||||||
|
# args.append(self.define_from_variant("BUILD_SHARED_LIB", "shared"))
|
||||||
|
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
class MakefileBuilder(spack.build_systems.makefile.MakefileBuilder):
|
||||||
|
# Disable parallel build
|
||||||
|
parallel = False
|
||||||
|
|
||||||
flag_handler = inject_flags
|
flag_handler = inject_flags
|
||||||
|
|
||||||
def url_for_version(self, version):
|
def url_for_version(self, version):
|
||||||
url = "https://www.ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz.v{}"
|
url = "https://www.ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz.v{}"
|
||||||
return url.format(version)
|
return url.format(version)
|
||||||
|
|
||||||
def edit(self, spec, prefix):
|
def edit(self, pkg, spec, prefix):
|
||||||
makefile = FileFilter("makefile")
|
makefile = FileFilter("makefile")
|
||||||
|
|
||||||
# ifort no longer accepts -openmp
|
# ifort no longer accepts -openmp
|
||||||
@ -148,31 +240,20 @@ def edit(self, spec, prefix):
|
|||||||
if spec.satisfies("%clang") or spec.satisfies("%apple-clang"):
|
if spec.satisfies("%clang") or spec.satisfies("%apple-clang"):
|
||||||
makefile.filter(r"--fast-math", "-ffast-math")
|
makefile.filter(r"--fast-math", "-ffast-math")
|
||||||
|
|
||||||
for variant_name, makefile_option in self.variant_map.items():
|
for variant_name, makefile_option in variant_map_makefile.items():
|
||||||
value = int(spec.variants[variant_name].value)
|
value = int(spec.variants[variant_name].value)
|
||||||
makefile.filter(r"^%s=.*" % makefile_option, "{}={}".format(makefile_option, value))
|
makefile.filter(r"^%s=.*" % makefile_option, "{}={}".format(makefile_option, value))
|
||||||
|
|
||||||
def setup_build_environment(self, env):
|
def setup_build_environment(self, env):
|
||||||
spec = self.spec
|
if self.spec.compiler.name in ["oneapi", "intel"]:
|
||||||
if spec.satisfies("%oneapi") or spec.satisfies("%intel"):
|
|
||||||
comp_sys = "intel_linux"
|
comp_sys = "intel_linux"
|
||||||
elif spec.satisfies("%gcc") or spec.satisfies("%clang") or spec.satisfies("%apple-clang"):
|
elif self.spec.compiler.name in ["gcc", "clang", "apple-clang"]:
|
||||||
comp_sys = "gnu_linux"
|
comp_sys = "gnu_linux"
|
||||||
|
|
||||||
env.set("COMP_SYS", comp_sys)
|
env.set("COMP_SYS", comp_sys)
|
||||||
|
|
||||||
def build(self, spec, prefix):
|
def build(self, pkg, spec, prefix):
|
||||||
# Get source files for netCDF4 builds
|
make("-j1")
|
||||||
if self.spec.satisfies("+netcdf4"):
|
|
||||||
with working_dir(self.build_directory):
|
|
||||||
os.system(
|
|
||||||
"wget https://downloads.unidata.ucar.edu/netcdf-c/4.8.1/netcdf-c-4.8.1.tar.gz"
|
|
||||||
)
|
|
||||||
os.system(
|
|
||||||
"wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.1/src/hdf5-1.12.1.tar.gz"
|
|
||||||
)
|
|
||||||
|
|
||||||
make()
|
|
||||||
|
|
||||||
# Move wgrib2 executable to a tempoary directory
|
# Move wgrib2 executable to a tempoary directory
|
||||||
mkdir("install")
|
mkdir("install")
|
||||||
@ -187,7 +268,7 @@ def build(self, spec, prefix):
|
|||||||
makefile = FileFilter("makefile")
|
makefile = FileFilter("makefile")
|
||||||
|
|
||||||
# Disable all options
|
# Disable all options
|
||||||
for variant_name, makefile_option in self.variant_map.items():
|
for variant_name, makefile_option in variant_map_makefile.items():
|
||||||
value = 0
|
value = 0
|
||||||
makefile.filter(
|
makefile.filter(
|
||||||
r"^%s=.*" % makefile_option, "{}={}".format(makefile_option, value)
|
r"^%s=.*" % makefile_option, "{}={}".format(makefile_option, value)
|
||||||
@ -196,7 +277,7 @@ def build(self, spec, prefix):
|
|||||||
# Need USE_REGEX in addition to MAKE_FTN_API to build lib
|
# Need USE_REGEX in addition to MAKE_FTN_API to build lib
|
||||||
makefile.filter(r"^MAKE_FTN_API=.*", "MAKE_FTN_API=1")
|
makefile.filter(r"^MAKE_FTN_API=.*", "MAKE_FTN_API=1")
|
||||||
makefile.filter(r"^USE_REGEX=.*", "USE_REGEX=1")
|
makefile.filter(r"^USE_REGEX=.*", "USE_REGEX=1")
|
||||||
make("lib")
|
make("lib", "-j1")
|
||||||
mkdir(join_path("install", "lib"))
|
mkdir(join_path("install", "lib"))
|
||||||
mkdir(join_path("install", "include"))
|
mkdir(join_path("install", "include"))
|
||||||
|
|
||||||
@ -204,5 +285,5 @@ def build(self, spec, prefix):
|
|||||||
move(join_path("lib", "wgrib2api.mod"), join_path("install", "include"))
|
move(join_path("lib", "wgrib2api.mod"), join_path("install", "include"))
|
||||||
move(join_path("lib", "wgrib2lowapi.mod"), join_path("install", "include"))
|
move(join_path("lib", "wgrib2lowapi.mod"), join_path("install", "include"))
|
||||||
|
|
||||||
def install(self, spec, prefix):
|
def install(self, pkg, spec, prefix):
|
||||||
install_tree("install/", prefix)
|
install_tree("install/", prefix)
|
||||||
|
Loading…
Reference in New Issue
Block a user