From f3f8395eb64ae80a38952d3018634056a99b0f94 Mon Sep 17 00:00:00 2001
From: "Fabian.Jakub" <fabian@jakub.com>
Date: Mon, 17 Apr 2023 15:27:24 +0200
Subject: [PATCH] add variant to icon-nwp package to add debug compiler flags

---
 spack_repo/packages/icon-nwp/package.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/spack_repo/packages/icon-nwp/package.py b/spack_repo/packages/icon-nwp/package.py
index bb8acee..65c1b2d 100644
--- a/spack_repo/packages/icon-nwp/package.py
+++ b/spack_repo/packages/icon-nwp/package.py
@@ -38,6 +38,7 @@ class IconNwp(Package):
 
     variant("plexrt", default=False, description="add 3D radiation support with TenStream")
     variant("petsc", default=False, description="add PETSc support")
+    variant("debug", default=False, description="add debug flags when compiling icon")
 
     # Dependencies
     depends_on("mpi")
@@ -202,7 +203,6 @@ class IconNwp(Package):
             f"ICON_BUNDLED_CFLAGS=-O3 -mtune={mtune}",
             f"CPPFLAGS={' '.join(CPPFLAGS)}",
             "FCFLAGS=-std=legacy -fmodule-private -fimplicit-none -fmax-identifier-length=63 -Wall -Wcharacter-truncation -Wconversion -Wunderflow -Wunused-parameter -Wno-surprising -fall-intrinsics -g -mpc64 -w",
-            "ICON_FCFLAGS=-fbacktrace -fbounds-check -fstack-protector-all -finit-real=nan -finit-integer=-2147483648 -finit-character=127 -w -O2",
             f"ICON_OCEAN_FCFLAGS=-O3 -mtune={mtune}",
             f"LDFLAGS={' '.join(libs)}",
             f"LIBS={' '.join(libs)}",
@@ -210,6 +210,13 @@ class IconNwp(Package):
             f"--enable-grib2",
         ]
 
+        ICON_FCFLAGS="-std=f2008 -fallow-argument-mismatch -fmodule-private -fimplicit-none -Wall"
+        if "+debug" in self.spec:
+            options.append(f"ICON_FCFLAGS={ICON_FCFLAGS} -fbacktrace -fbounds-check -fstack-protector-all -finit-real=nan -finit-integer=-2147483648 -finit-character=127 -w -O2")
+        else:
+            options.append(f"ICON_FCFLAGS={ICON_FCFLAGS} -O3")
+
+
         # For some reason there's a problem with OpenMPI with gcc@11.3.0 which makes the configuration fail.
         if self.spec.compiler.name == "gcc" and self.spec.compiler.version == Version("11.3.0"):
             options.append("--enable-mpi-checks=no")
-- 
GitLab