@@ -74,29 +74,21 @@ if(NOT h5_conf)
7474 return ()
7575endif ()
7676
77- # get version
78- # from CMake/Modules/FindHDF5.cmake
79- check_symbol_exists(H5_HAVE_FILTER_SZIP ${h5_conf} have_szip)
80- check_symbol_exists(H5_HAVE_FILTER_DEFLATE ${h5_conf} have_zlib)
81-
82- if (parallel IN_LIST HDF5_FIND_COMPONENTS)
83- check_symbol_exists(H5_HAVE_PARALLEL ${h5_conf} _h5_parallel)
84- if (_h5_parallel)
85- if (NOT TARGET MPI::MPI_C)
86- find_package (MPI COMPONENTS C)
87- endif ()
88- if (MPI_C_FOUND)
89- set (HDF5_parallel_FOUND true PARENT_SCOPE)
90- set (HDF5_IS_PARALLEL true CACHE BOOL "HDF5 library compiled with parallel IO support" )
91- endif ()
92- endif ()
77+ # check HDF5 features that require link of external libraries.
78+ check_symbol_exists(H5_HAVE_FILTER_SZIP ${h5_conf} hdf5_have_szip)
79+ check_symbol_exists(H5_HAVE_FILTER_DEFLATE ${h5_conf} hdf5_have_zlib)
9380
94- if (NOT HDF5_IS_PARALLEL)
95- set (HDF5_parallel_FOUND false PARENT_SCOPE)
96- return ()
97- endif ()
81+ # Always check for HDF5 MPI support because HDF5 link fails if MPI is linked into HDF5.
82+ check_symbol_exists(H5_HAVE_PARALLEL ${h5_conf} HDF5_IS_PARALLEL)
83+
84+ if (HDF5_IS_PARALLEL)
85+ set (HDF5_parallel_FOUND true PARENT_SCOPE)
86+ else ()
87+ set (HDF5_parallel_FOUND false PARENT_SCOPE)
9888endif ()
9989
90+ # get version
91+ # from CMake/Modules/FindHDF5.cmake
10092file (STRINGS ${h5_conf} _def
10193REGEX "^[ \t ]*#[ \t ]*define[ \t ]+H5_VERSION[ \t ]+" )
10294if ( "${_def} " MATCHES
@@ -118,10 +110,10 @@ if(NOT SZIP_ROOT)
118110 set (SZIP_ROOT "${ZLIB_ROOT} " )
119111endif ()
120112
121- if (have_zlib )
113+ if (hdf5_have_zlib )
122114 find_package (ZLIB)
123115
124- if (have_szip )
116+ if (hdf5_have_szip )
125117 # Szip even though not used by default.
126118 # If system HDF5 dynamically links libhdf5 with szip, our builds will fail if we don't also link szip.
127119 # however, we don't require SZIP for this case as other HDF5 libraries may statically link SZIP.
@@ -144,7 +136,8 @@ if(UNIX)
144136 list (APPEND CMAKE_REQUIRED_LIBRARIES m)
145137endif ()
146138
147- if (MPI_C_FOUND)
139+ if (HDF5_IS_PARALLEL)
140+ find_package (MPI COMPONENTS C)
148141 list (APPEND CMAKE_REQUIRED_LIBRARIES MPI::MPI_C)
149142endif ()
150143
@@ -380,10 +373,10 @@ if(HDF5_FOUND)
380373 set_target_properties (HDF5::HDF5 PROPERTIES
381374 INTERFACE_LINK_LIBRARIES "${HDF5_LIBRARIES} "
382375 INTERFACE_INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIRS} " )
383- if (have_zlib )
376+ if (hdf5_have_zlib )
384377 target_link_libraries (HDF5::HDF5 INTERFACE ZLIB::ZLIB)
385378 endif ()
386- if (have_szip )
379+ if (hdf5_have_szip )
387380 target_link_libraries (HDF5::HDF5 INTERFACE SZIP::SZIP)
388381 endif ()
389382
0 commit comments