From 0fdac73e3f5ec02e0b318b59add9639f67fa0b5f Mon Sep 17 00:00:00 2001
From: Sebastian Achilles <s.achilles@fz-juelich.de>
Date: Thu, 8 Sep 2022 15:31:37 +0200
Subject: [PATCH] update NVHPC easyblock for NVHPC 22.7+

---
 Custom_EasyBlocks/nvhpc.py | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/Custom_EasyBlocks/nvhpc.py b/Custom_EasyBlocks/nvhpc.py
index 43853ebf9..002c15715 100644
--- a/Custom_EasyBlocks/nvhpc.py
+++ b/Custom_EasyBlocks/nvhpc.py
@@ -326,10 +326,16 @@ class EB_NVHPC(PackedBinary):
         """Add environment variable for NVHPC location"""
         txt = super(EB_NVHPC, self).make_module_extra()
         txt += self.module_generator.set_environment('NVHPC', self.installdir)
+        # NVHPC 22.7+ requires the variable NVHPC_CUDA_HOME for external CUDA. CUDA_HOME has been deprecated.
         if LooseVersion(self.version) >= LooseVersion('22.7'):
-            # NVHPC 22.7+ requires the variable NVHPC_CUDA_HOME for external CUDA. CUDA_HOME has been deprecated.
-            cuda = get_software_root('CUDA')
-            if not self.cfg['module_add_cuda'] and cuda:
-                txt += self.module_generator.set_environment(
-                    'NVHPC_CUDA_HOME', cuda)
+            # If CUDA is not available then avoid setting NVHPC_CUDA_HOME altogether
+            # and rely on the internal one
+            if not self.cfg['module_add_cuda']:
+                cuda = get_software_root('CUDA')
+                if cuda:
+                    txt += self.module_generator.set_environment(
+                        'NVHPC_CUDA_HOME', cuda)
+                else:
+                    raise EasyBuildError(
+                        "No external CUDA available and opting-out of internal CUDA. Don't know what to do")
         return txt
-- 
GitLab