From ccb3939d3a381fe38b4962f76e098575b055c2ea Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Thu, 30 Sep 2021 14:38:29 +0200
Subject: [PATCH] [cmake] Check for hdf5 mpi config at cmake time.

---
 scripts/cmake/Dependencies.cmake | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/scripts/cmake/Dependencies.cmake b/scripts/cmake/Dependencies.cmake
index 2860138b9d2..045050fbfc0 100644
--- a/scripts/cmake/Dependencies.cmake
+++ b/scripts/cmake/Dependencies.cmake
@@ -212,19 +212,31 @@ else()
         EXCLUDE_FROM_ALL YES
     )
     if(HDF5_ADDED)
-        target_include_directories(hdf5-static INTERFACE ${HDF5_BINARY_DIR})
         list(APPEND DISABLE_WARNINGS_TARGETS hdf5-static)
         set(HDF5_LIBRARIES hdf5-static)
         if(ZLIB_ADDED)
             list(APPEND HDF5_LIBRARIES zlibstatic)
         endif()
-        set(HDF5_C_INCLUDE_DIR ${HDF5_SOURCE_DIR})
-        set(HDF5_INCLUDE_DIR ${HDF5_SOURCE_DIR})
+        set(HDF5_C_INCLUDE_DIR ${HDF5_SOURCE_DIR}/src)
+        set(HDF5_INCLUDE_DIR ${HDF5_SOURCE_DIR}/src)
+        target_include_directories(hdf5-static INTERFACE ${HDF5_BINARY_DIR} ${HDF5_INCLUDE_DIR})
     else()
         find_package(HDF5 REQUIRED)
     endif()
 endif()
 
+if(OGS_USE_PETSC)
+    include(CheckCXXSymbolExists)
+    set(CMAKE_REQUIRED_INCLUDES "${HDF5_INCLUDE_DIR}" "${HDF5_BINARY_DIR}")
+    set(CMAKE_REQUIRED_LIBRARIES "${HDF5_LIBRARIES}")
+    check_cxx_symbol_exists(H5Pset_fapl_mpio hdf5.h HAVE_H5Pset_fapl_mpio)
+    unset(CMAKE_REQUIRED_INCLUDES)
+    if(NOT HAVE_H5Pset_fapl_mpio)
+        message(FATAL_ERROR "HDF5 was not build with MPI support! "
+            "(Enable with HDF5_ENABLE_PARALLEL)")
+    endif()
+endif()
+
 # Does not compile in Debug-mode, see #3175.
 if(CMAKE_BUILD_TYPE STREQUAL "Release" AND OGS_BUILD_TESTING)
     set(XDMF_LIBNAME OgsXdmf CACHE STRING "")
-- 
GitLab