From 57bca577a1c6112dd71cd6f0dc98aa55c82038ff Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Mon, 19 Oct 2020 00:07:13 +0200
Subject: [PATCH] Add a dirty trick to find/test PETSc

---
 CMakeLists.txt                         | 9 +++++++++
 packages/cmake-modules/FindPETSc.cmake | 9 ++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index dc0f69398..4b010de5a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -135,6 +135,10 @@ if(${MPI_FOUND})
       message(FATAL_ERROR "MPI support requires ParMETIS which cannot be found!")
     endif()
   endif()
+else()
+  if(PUGS_ENABLE_MPI MATCHES "^ON$")
+    message(FATAL_ERROR "Cannot find MPI!")
+  endif()
 endif()
 
 #------------------------------------------------------
@@ -144,6 +148,7 @@ set(PUGS_ENABLE_PETSC AUTO CACHE STRING
   "Choose one of: AUTO ON OFF")
 
 if (PUGS_ENABLE_PETSC MATCHES "^(AUTO|ON)$")
+  cmake_policy(SET CMP0075 OLD)
   find_package(PETSc)
   set(PUGS_HAS_PETSC ${PETSC_FOUND})
 else()
@@ -152,6 +157,10 @@ endif()
 
 if (${PETSC_FOUND})
   include_directories(SYSTEM ${PETSC_INCLUDES})
+else()
+  if (PUGS_ENABLE_PETSC MATCHES "^ON$")
+    message(FATAL_ERROR "Could not find PETSc!")
+  endif()
 endif()
 
 
diff --git a/packages/cmake-modules/FindPETSc.cmake b/packages/cmake-modules/FindPETSc.cmake
index 41e02d979..b6aa2ee42 100644
--- a/packages/cmake-modules/FindPETSc.cmake
+++ b/packages/cmake-modules/FindPETSc.cmake
@@ -278,7 +278,14 @@ int main(int argc,char *argv[]) {
   return 0;
 }
 ")
-    multipass_source_runs ("${includes}" "${libraries}" "${_PETSC_TEST_SOURCE}" ${runs} "${PETSC_LANGUAGE_BINDINGS}")
+    multipass_source_runs(
+      "${includes} ${MPI_CXX_INCLUDE_DIRS} ${MPI_CXX_COMPILER_INCLUDE_DIRS}"
+      "${libraries}"
+      "${_PETSC_TEST_SOURCE}"
+      ${runs}
+      "${PETSC_LANGUAGE_BINDINGS}"
+      )
+
     if (${${runs}})
       set (PETSC_EXECUTABLE_RUNS "YES" CACHE BOOL
         "Can the system successfully run a PETSc executable?  This variable can be manually set to \"YES\" to force CMake to accept a given PETSc configuration, but this will almost always result in a broken build.  If you change PETSC_DIR, PETSC_ARCH, or PETSC_CURRENT you would have to reset this variable." FORCE)
-- 
GitLab