From 3987604b8910f8d90d4696e1c0b7e4c0dd0a3308 Mon Sep 17 00:00:00 2001
From: Sergio Alexis Paz <alexis.paz@gmail.com>
Date: Wed, 29 Nov 2023 17:16:27 -0300
Subject: Add gipaw when building quantum-espresso with cmake (#41142)

* gipaw.x installed by cmake if version >= 5c4a4ce.

gipaw.x will only be installed with cmake if the qe-gipaw version
is >= 5c4a4ce. Currently, QE source uses the older f5823521 one.
Here a patch to the submodule_commit_hash_records to use a newer
qe-gipaw version.
---
 .../packages/quantum-espresso/gipaw-eccee44.patch   |  8 ++++++++
 .../builtin/packages/quantum-espresso/package.py    | 21 ++++++++++++++++-----
 2 files changed, 24 insertions(+), 5 deletions(-)
 create mode 100644 var/spack/repos/builtin/packages/quantum-espresso/gipaw-eccee44.patch

(limited to 'var')

diff --git a/var/spack/repos/builtin/packages/quantum-espresso/gipaw-eccee44.patch b/var/spack/repos/builtin/packages/quantum-espresso/gipaw-eccee44.patch
new file mode 100644
index 0000000000..e2d8179010
--- /dev/null
+++ b/var/spack/repos/builtin/packages/quantum-espresso/gipaw-eccee44.patch
@@ -0,0 +1,8 @@
+--- spack-src/external/submodule_commit_hash_records.org	2023-11-15 18:38:47.485317449 -0300
++++ spack-src/external/submodule_commit_hash_records	2023-11-15 18:39:02.661861757 -0300
+@@ -5,4 +5,4 @@
+ 82005cbb65bdf5d32ca021848eec8f19da956a77 mbd
+ f72ab25fa4ea755c1b4b230ae8074b47d5509c70 pw2qmcpack
+ 1d6b187374a2d50b509e5e79e2cab01a79ff7ce1 wannier90
+-f5823521ad8fdd8b8e9e29197eedb354f9b9146d qe-gipaw
++eccee44d3caf1c930fb72ad9c741fbb743eabf45 qe-gipaw
diff --git a/var/spack/repos/builtin/packages/quantum-espresso/package.py b/var/spack/repos/builtin/packages/quantum-espresso/package.py
index 40c036320d..dacf771f60 100644
--- a/var/spack/repos/builtin/packages/quantum-espresso/package.py
+++ b/var/spack/repos/builtin/packages/quantum-espresso/package.py
@@ -227,13 +227,8 @@ class QuantumEspresso(CMakePackage, Package):
     variant(
         "gipaw",
         default=False,
-        when="build_system=generic",
         description="Builds Gauge-Including Projector Augmented-Waves executable",
     )
-    with when("+gipaw"):
-        conflicts(
-            "@:6.3", msg="gipaw standard support available for QE 6.3 or grater version only"
-        )
 
     # Dependencies not affected by variants
     depends_on("blas")
@@ -260,6 +255,15 @@ class QuantumEspresso(CMakePackage, Package):
     # NOTE: *SOME* third-party patches will require deactivation of
     # upstream patches using `~patch` variant
 
+    # gipaw
+    conflicts(
+        "@:6.2",
+        when="+gipaw",
+        msg="gipaw standard support available for QE 6.3 or grater version only",
+    )
+
+    conflicts("+gipaw build_system=cmake", when="@:7.1")
+
     # Only CMake will work for @6.8: %aocc
     conflicts(
         "build_system=generic", when="@6.8: %aocc", msg="Please use CMake to build with AOCC"
@@ -400,6 +404,9 @@ class QuantumEspresso(CMakePackage, Package):
     # extlibs_makefile updated to work with fujitsu compilers
     patch("fj-fox.patch", when="+patch %fj")
 
+    # gipaw.x will only be installed with cmake if the qe-gipaw version is >= 5c4a4ce.
+    patch("gipaw-eccee44.patch", when="@7.2+gipaw build_system=cmake")
+
 
 class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder):
     def cmake_args(self):
@@ -416,6 +423,10 @@ class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder):
             self.define_from_variant("QE_ENABLE_MPI_GPU_AWARE", "mpigpu"),
         ]
 
+        if "+gipaw" in spec:
+            cmake_args.append(self.define("QE_ENABLE_PLUGINS", "gipaw"))
+            cmake_args.append(self.define("QE_ENABLE_FOX", True))
+
         if "+cuda" in self.spec:
             cmake_args.append(self.define("QE_ENABLE_OPENACC", True))
 
-- 
cgit v1.2.3-70-g09d2