From 011bc9fc7137540e479889650d105e832855366a Mon Sep 17 00:00:00 2001
From: Yen-Chen Chen <yen-chen.chen@kit.edu>
Date: Mon, 8 Apr 2024 12:54:54 +0000
Subject: [PATCH] Fix OpenACC configuration for LUMI
 (icon-libraries/libfortran-support!84)

<!--
ICON
## What is the bug
LUMI does not have `OpenACC_C` and the BB fails because we are checking `OpenACC` for both `C` and `Fortran`. This MR fixes `lumi_gpu` BB.
## How do you fix it
Only check if `OpenACC_Fortran` is found.

Approved-by: Jonas Jucker <jonas.jucker@env.ethz.ch>
Merged-by: Jonas Jucker <jonas.jucker@env.ethz.ch>
Changelog: bugfix
---
 CMakeLists.txt     | 2 --
 src/CMakeLists.txt | 9 +++++++--
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fb396fe..1d088f0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -13,8 +13,6 @@ cmake_minimum_required(VERSION 3.18)
 
 project(fortran-support VERSION 0.1.0 LANGUAGES Fortran C)
 
-find_package(OpenACC QUIET)
-
 option(BUILD_SHARED_LIBS "Build shared libraries" ON)
 option(BUILD_TESTING "Build tests" ON)
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0941b2c..7db2325 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -84,8 +84,13 @@ check_macro_defined(HAS_OPENACC_MACRO _OPENACC QUIET)
 if (FS_ENABLE_OPENACC)
   # If _OPENACC is defined, assume that the required compiler flags are already
   # provided, e.g. in CMAKE_Fortran_FLAGS:
-  if(NOT HAS_OPENACC_MACRO)
-    find_package(OpenACC REQUIRED)
+  if (NOT HAS_OPENACC_MACRO)
+    # On LUMI, we only have OpenACC_Fortran, but no OpenACC_C
+    find_package(OpenACC QUIET)
+    if (NOT OpenACC_Fortran_FOUND)
+      message(FATAL_ERROR
+        "Could NOT find OpenACC_Fortran.")
+    endif ()
     target_compile_options(fortran-support PRIVATE ${OpenACC_Fortran_OPTIONS})
     # This make sures that unit tests (FortUTF) compiles without the need of
     # passing OpenACC compile option.
-- 
GitLab