@@ -160,8 +160,19 @@ if(NOT ZLIB_ROOT)
160160 set (ZLIB_ROOT "${HDF5_ROOT} ;${zlib_dir} " )
161161endif ()
162162
163+
164+ set (hdf5_prereqs true PARENT_SCOPE)
165+
163166if (hdf5_have_zlib)
164- find_package (ZLIB)
167+ if (HDF5_FIND_REQUIRED)
168+ find_package (ZLIB REQUIRED)
169+ else ()
170+ find_package (ZLIB)
171+ endif ()
172+ if (NOT ZLIB_FOUND)
173+ set (hdf5_prereqs false PARENT_SCOPE)
174+ return ()
175+ endif ()
165176
166177 if (hdf5_have_szip)
167178 # Szip even though not used by default.
@@ -170,7 +181,16 @@ if(hdf5_have_zlib)
170181 if (NOT SZIP_ROOT)
171182 set (SZIP_ROOT ${ZLIB_ROOT} )
172183 endif ()
173- find_package (SZIP)
184+ if (HDF5_FIND_REQUIRED)
185+ find_package (SZIP REQUIRED)
186+ else ()
187+ find_package (SZIP)
188+ endif ()
189+ if (NOT SZIP_FOUND)
190+ set (hdf5_prereqs false PARENT_SCOPE)
191+ return ()
192+ endif ()
193+
174194 list (APPEND CMAKE_REQUIRED_INCLUDES ${SZIP_INCLUDE_DIRS} )
175195 list (APPEND CMAKE_REQUIRED_LIBRARIES ${SZIP_LIBRARIES} )
176196 endif ()
@@ -656,7 +676,7 @@ endfunction(check_fortran_links)
656676
657677function (check_hdf5_link)
658678
659- if (NOT HDF5_C_FOUND)
679+ if (NOT (hdf5_prereqs AND HDF5_C_FOUND) )
660680 return ()
661681endif ()
662682
@@ -777,11 +797,11 @@ if(HDF5_C_FOUND)
777797 detect_config()
778798endif (HDF5_C_FOUND)
779799
780- if (HDF5_C_FOUND AND CXX IN_LIST HDF5_FIND_COMPONENTS)
800+ if (hdf5_prereqs AND HDF5_C_FOUND AND CXX IN_LIST HDF5_FIND_COMPONENTS)
781801 find_hdf5_cxx()
782802endif ()
783803
784- if (HDF5_C_FOUND AND Fortran IN_LIST HDF5_FIND_COMPONENTS)
804+ if (hdf5_prereqs AND HDF5_C_FOUND AND Fortran IN_LIST HDF5_FIND_COMPONENTS)
785805 find_hdf5_fortran()
786806endif ()
787807
@@ -795,9 +815,10 @@ set(CMAKE_REQUIRED_INCLUDES)
795815# pop off ignored paths so rest of script can find Python
796816list (REMOVE_ITEM CMAKE_IGNORE_PATH ${h5_ignore_path} )
797817
818+
798819include (FindPackageHandleStandardArgs)
799820find_package_handle_standard_args(HDF5
800- REQUIRED_VARS HDF5_C_LIBRARIES HDF5_links
821+ REQUIRED_VARS HDF5_C_LIBRARIES HDF5_links hdf5_prereqs
801822VERSION_VAR HDF5_VERSION
802823HANDLE_COMPONENTS
803824HANDLE_VERSION_RANGE
0 commit comments