@@ -42,6 +42,7 @@ include(ReplaceIdefixSource)
4242include (AddIdefixSource )
4343include (SetIdefixProperty )
4444include (SetRequiredBuildSettingsForGCC8 )
45+ include (CheckHdf5ParallelSupport )
4546
4647#Idefix requires Cuda Lambdas (experimental)
4748if (Kokkos_ENABLE_CUDA)
@@ -130,55 +131,8 @@ if(Idefix_HDF5)
130131 message (STATUS "Found HDF5 include directories: ${HDF5_INCLUDE_DIRS} " )
131132 target_include_directories (idefix PUBLIC "${HDF5_INCLUDE_DIRS} " )
132133 if (Idefix_MPI)
133- include (CheckCSourceCompiles )
134-
135- # Some CMake/HDF5 combinations do not reliably set HDF5_IS_PARALLEL
136- # (e.g. when HDF5 is found via its CMake config package rather than the
137- # FindHDF5 module). Combine metadata checks with a compile+link probe for
138- # the MPI-IO symbols to reliably detect parallel HDF5.
139- set (_idefix_hdf5_is_parallel FALSE )
140- if (HDF5_IS_PARALLEL OR HDF5_C_IS_PARALLEL)
141- set (_idefix_hdf5_is_parallel TRUE )
142- endif ()
143-
144- if (NOT _idefix_hdf5_is_parallel AND DEFINED HDF5_C_COMPILER_EXECUTABLE)
145- execute_process (
146- COMMAND "${HDF5_C_COMPILER_EXECUTABLE} " -showconfig
147- OUTPUT_VARIABLE _idefix_hdf5_showconfig
148- ERROR_QUIET
149- )
150- if (_idefix_hdf5_showconfig MATCHES "Parallel HDF5:[ \t ]*yes" )
151- set (_idefix_hdf5_is_parallel TRUE )
152- endif ()
153- endif ()
154-
155- set (_idefix_saved_required_includes "${CMAKE_REQUIRED_INCLUDES} " )
156- set (_idefix_saved_required_libraries "${CMAKE_REQUIRED_LIBRARIES} " )
157-
158- set (CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIRS} ${MPI_C_INCLUDE_DIRS} )
159- set (CMAKE_REQUIRED_LIBRARIES ${_idefix_hdf5_link_items} MPI::MPI_C)
160- check_c_source_compiles (
161- "#include <mpi.h>
162- #include <hdf5.h>
163- int main(void) {
164- hid_t plist = H5Pcreate(H5P_FILE_ACCESS);
165- H5Pset_fapl_mpio(plist, MPI_COMM_WORLD, MPI_INFO_NULL);
166- H5Pclose(plist);
167- return 0;
168- }"
169- IDEFIX_HDF5_HAS_MPI_IO
170- )
171-
172- set (CMAKE_REQUIRED_INCLUDES "${_idefix_saved_required_includes} " )
173- set (CMAKE_REQUIRED_LIBRARIES "${_idefix_saved_required_libraries} " )
174- unset (_idefix_saved_required_includes)
175- unset (_idefix_saved_required_libraries)
176-
177- if (IDEFIX_HDF5_HAS_MPI_IO)
178- set (_idefix_hdf5_is_parallel TRUE )
179- endif ()
180-
181- if (NOT _idefix_hdf5_is_parallel)
134+ CheckHdf5ParallelSupport ("${_idefix_hdf5_link_items} " )
135+ if (NOT IDEFIX_HDF5_IS_PARALLEL)
182136 message (FATAL_ERROR "Parallel HDF5 required for Idefix_MPI but the found HDF5 library does not support it" )
183137 endif ()
184138 endif ()
0 commit comments