From b0c86f86216c7d28bc7c322b3d7af826c6583a14 Mon Sep 17 00:00:00 2001
From: Florent Pruvost <florent.pruvost@inria.fr>
Date: Mon, 28 May 2018 15:48:33 +0200
Subject: [PATCH] update FindHYPRE and add hypre and pampa tests

---
 modules/find/FindHYPRE.cmake      | 58 +++++++++++++++++++++++++++----
 modules/find/tests/CMakeLists.txt |  4 +--
 2 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/modules/find/FindHYPRE.cmake b/modules/find/FindHYPRE.cmake
index b83794f..2beb94d 100644
--- a/modules/find/FindHYPRE.cmake
+++ b/modules/find/FindHYPRE.cmake
@@ -6,7 +6,7 @@
 # @copyright (c) 2009-2014 The University of Tennessee and The University
 #                          of Tennessee Research Foundation.
 #                          All rights reserved.
-# @copyright (c) 2012-2016 Inria. All rights reserved.
+# @copyright (c) 2012-2018 Inria. All rights reserved.
 # @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
 #
 ###
@@ -16,12 +16,18 @@
 #  find_package(HYPRE
 #               [REQUIRED]) # Fail with error if hypre is not found
 #
+#  HYPRE depends on the following libraries:
+#   - MPI
+#
 # This module finds headers and hypre library.
 # Results are reported in variables:
-#  HYPRE_FOUND           - True if headers and requested libraries were found
-#  HYPRE_INCLUDE_DIRS    - hypre include directories
-#  HYPRE_LIBRARY_DIRS    - Link directories for hypre libraries
-#  HYPRE_LIBRARIES       - hypre component libraries to be linked
+#  HYPRE_FOUND             - True if headers and requested libraries were found
+#  HYPRE_INCLUDE_DIRS      - hypre include directories
+#  HYPRE_LIBRARY_DIRS      - Link directories for hypre libraries
+#  HYPRE_LIBRARIES         - hypre component libraries to be linked
+#  HYPRE_INCLUDE_DIRS_DEP  - hypre + dependencies include directories
+#  HYPRE_LIBRARY_DIRS_DEP  - hypre + dependencies link directories
+#  HYPRE_LIBRARIES_DEP     - hypre + dependencies libraries
 #
 # The user can give specific paths where to find the libraries adding cmake
 # options at configure (ex: cmake path/to/project -DHYPRE_DIR=path/to/hypre):
@@ -32,8 +38,8 @@
 # are not given as cmake variable: HYPRE_DIR, HYPRE_INCDIR, HYPRE_LIBDIR
 
 #=============================================================================
-# Copyright 2016 Inria
-# Copyright 2016 Florent Pruvost
+# Copyright 2016-2018 Inria
+# Copyright 2016-2018 Florent Pruvost
 #
 # Distributed under the OSI-approved BSD License (the "License");
 # see accompanying file MORSE-Copyright.txt for details.
@@ -63,6 +69,13 @@ if ( HYPRE_DIR OR ( HYPRE_INCDIR AND HYPRE_LIBDIR) OR ENV_HYPRE_DIR OR (ENV_HYPR
   set(HYPRE_GIVEN_BY_USER "TRUE")
 endif()
 
+# HYPRE depends on MPI, try to find it
+if (HYPRE_FIND_REQUIRED)
+  find_package(MPI REQUIRED)
+else()
+  find_package(MPI)
+endif()
+
 # Looking for include
 # -------------------
 
@@ -223,6 +236,33 @@ if(HYPRE_LIBRARIES)
     set(REQUIRED_LIBDIRS "${HYPRE_LIBRARY_DIRS}")
   endif()
   set(REQUIRED_LIBS "${HYPRE_LIBRARIES}")
+  # MPI
+  if (MPI_FOUND)
+    if (MPI_C_INCLUDE_PATH)
+      list(APPEND REQUIRED_INCDIRS "${MPI_C_INCLUDE_PATH}")
+    endif()
+    if (MPI_C_LINK_FLAGS)
+      if (${MPI_C_LINK_FLAGS} MATCHES "  -")
+        string(REGEX REPLACE " -" "-" MPI_C_LINK_FLAGS ${MPI_C_LINK_FLAGS})
+      endif()
+      list(APPEND REQUIRED_LDFLAGS "${MPI_C_LINK_FLAGS}")
+    endif()
+    list(APPEND REQUIRED_LIBS "${MPI_C_LIBRARIES}")
+  endif()
+  # libm
+  set(M_LIBRARY "M_LIBRARY-NOTFOUND")
+  find_library(M_LIBRARY NAMES m)
+  mark_as_advanced(M_LIBRARY)
+  if(M_LIBRARY)
+    list(APPEND REQUIRED_LIBS "${M_LIBRARY}")
+  endif()
+  # libstdc++
+  set(stdcpp_LIBRARY "stdcpp_LIBRARY-NOTFOUND")
+  find_library(stdcpp_LIBRARY NAMES stdc++)
+  mark_as_advanced(stdcpp_LIBRARY)
+  if(stdcpp_LIBRARY)
+    list(APPEND REQUIRED_LIBS "${stdcpp_LIBRARY}")
+  endif()
 
   # set required libraries for link
   finds_remove_duplicates()
@@ -241,6 +281,10 @@ if(HYPRE_LIBRARIES)
   mark_as_advanced(HYPRE_WORKS)
 
   if(NOT HYPRE_WORKS)
+    # save link with dependencies
+    set(HYPRE_LIBRARIES_DEP "${REQUIRED_LIBS}")
+    set(HYPRE_LIBRARY_DIRS_DEP "${REQUIRED_LIBDIRS}")
+    set(HYPRE_INCLUDE_DIRS_DEP "${REQUIRED_INCDIRS}")
     if(NOT HYPRE_FIND_QUIETLY)
       message(STATUS "Looking for HYPRE : test of HYPRE_StructGridCreate with HYPRE library fails")
       message(STATUS "CMAKE_REQUIRED_LIBRARIES: ${CMAKE_REQUIRED_LIBRARIES}")
diff --git a/modules/find/tests/CMakeLists.txt b/modules/find/tests/CMakeLists.txt
index abccab8..2e4ab31 100644
--- a/modules/find/tests/CMakeLists.txt
+++ b/modules/find/tests/CMakeLists.txt
@@ -89,14 +89,14 @@ if (ENABLE_CTEST)
       GTG
       HQR
       HWLOC
-      #HYPRE module not ready TODO: complete it
+      HYPRE
       LAPACK
       LAPACKE
       LAPACKEXT
       METIS
       MPIEXT
       MUMPS
-      #PAMPA not able to install it, link problem with ptscotch
+      PAMPA
       PAPI
       PARMETIS
       PARSEC
-- 
GitLab