@@ -38,6 +38,78 @@ Targets
3838 HDF5 Imported Target
3939#]=======================================================================]
4040
41+ function (detect_config)
42+
43+ set (CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIR} )
44+
45+ foreach (f H5pubconf.h H5pubconf-64.h)
46+ if (EXISTS ${HDF5_INCLUDE_DIR} /${f} )
47+ set (_conf ${HDF5_INCLUDE_DIR} /${f} )
48+ break ()
49+ endif ()
50+ endforeach ()
51+
52+ if (NOT _conf)
53+ message (WARNING "Could not find HDF5 config header H5pubconf.h, therefore cannot detect HDF5 configuration." )
54+ set (HDF5_C_FOUND false PARENT_SCOPE)
55+ return ()
56+ endif ()
57+
58+ # get version
59+ # from CMake/Modules/FindHDF5.cmake
60+ include (CheckSymbolExists)
61+ check_symbol_exists(H5_HAVE_FILTER_SZIP ${_conf} _szip)
62+ check_symbol_exists(H5_HAVE_FILTER_DEFLATE ${_conf} _zlib)
63+
64+ file (STRINGS ${_conf} _def
65+ REGEX "^[ \t ]*#[ \t ]*define[ \t ]+H5_VERSION[ \t ]+" )
66+ if ( "${_def} " MATCHES
67+ "H5_VERSION[ \t ]+\" ([0-9]+\\ .[0-9]+\\ .[0-9]+)(-patch([0-9]+))?\" " )
68+ set (HDF5_VERSION "${CMAKE_MATCH_1} " )
69+ if ( CMAKE_MATCH_3 )
70+ set (HDF5_VERSION ${HDF5_VERSION} .${CMAKE_MATCH_3} )
71+ endif ()
72+
73+ set (HDF5_VERSION ${HDF5_VERSION} PARENT_SCOPE)
74+ endif ()
75+
76+ # otherwise can pickup miniconda zlib
77+ get_filename_component (_hint ${HDF5_C_LIBRARY} DIRECTORY )
78+ if (NOT ZLIB_ROOT)
79+ set (ZLIB_ROOT "${_hint} /..;${_hint} /../..;${pc_zlib_LIBRARY_DIRS} ;${pc_zlib_LIBDIR} " )
80+ endif ()
81+ if (NOT SZIP_ROOT)
82+ set (SZIP_ROOT "${ZLIB_ROOT} " )
83+ endif ()
84+
85+ if (_zlib)
86+ find_package (ZLIB REQUIRED)
87+
88+ if (_szip)
89+ # Szip even though not directly used because if system static links libhdf5 with szip,
90+ # our builds will fail if we don't also link szip.
91+ find_package (SZIP REQUIRED)
92+ set (CMAKE_REQUIRED_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${HDF5_C_LIBRARIES} SZIP::SZIP ZLIB::ZLIB ${CMAKE_DL_LIBS} )
93+ else ()
94+ set (CMAKE_REQUIRED_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${HDF5_C_LIBRARIES} ZLIB::ZLIB ${CMAKE_DL_LIBS} )
95+ endif ()
96+ else ()
97+ set (CMAKE_REQUIRED_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${HDF5_C_LIBRARIES} ${CMAKE_DL_LIBS} )
98+ endif ()
99+
100+ set (THREADS_PREFER_PTHREAD_FLAG true )
101+ find_package (Threads)
102+ if (Threads_FOUND)
103+ list (APPEND CMAKE_REQUIRED_LIBRARIES Threads::Threads)
104+ endif ()
105+
106+ set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} PARENT_SCOPE)
107+
108+ endfunction (detect_config)
109+
110+
111+ # === main program
112+
41113set (_lsuf hdf5 hdf5/serial)
42114set (_psuf static ${_lsuf} )
43115
@@ -147,64 +219,7 @@ endif()
147219
148220# required libraries
149221if (HDF5_C_FOUND)
150-
151- set (CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIR} )
152-
153- set (_conf)
154- foreach (f H5pubconf.h H5pubconf-64.h)
155- if (EXISTS ${HDF5_INCLUDE_DIR} /${f} )
156- set (_conf ${HDF5_INCLUDE_DIR} /${f} )
157- break ()
158- endif ()
159- endforeach ()
160-
161- include (CheckSymbolExists)
162- check_symbol_exists(H5_HAVE_FILTER_SZIP ${_conf} _szip)
163- check_symbol_exists(H5_HAVE_FILTER_DEFLATE ${_conf} _zlib)
164-
165- # get version
166- # from CMake/Modules/FindHDF5.cmake
167- if (_conf)
168- file (STRINGS ${_conf} _def
169- REGEX "^[ \t ]*#[ \t ]*define[ \t ]+H5_VERSION[ \t ]+" )
170- if ( "${_def} " MATCHES
171- "H5_VERSION[ \t ]+\" ([0-9]+\\ .[0-9]+\\ .[0-9]+)(-patch([0-9]+))?\" " )
172- set (HDF5_VERSION "${CMAKE_MATCH_1} " )
173- if ( CMAKE_MATCH_3 )
174- set (HDF5_VERSION ${HDF5_VERSION} .${CMAKE_MATCH_3} )
175- endif ()
176- endif ()
177- endif (_conf)
178- # otherwise can pickup miniconda zlib
179- get_filename_component (_hint ${HDF5_C_LIBRARY} DIRECTORY )
180- if (NOT ZLIB_ROOT)
181- set (ZLIB_ROOT "${_hint} /..;${_hint} /../..;${pc_zlib_LIBRARY_DIRS} ;${pc_zlib_LIBDIR} " )
182- endif ()
183- if (NOT SZIP_ROOT)
184- set (SZIP_ROOT "${ZLIB_ROOT} " )
185- endif ()
186-
187- if (_zlib)
188- find_package (ZLIB REQUIRED)
189-
190- if (_szip)
191- # Szip even though not directly used because if system static links libhdf5 with szip,
192- # our builds will fail if we don't also link szip.
193- find_package (SZIP REQUIRED)
194- set (CMAKE_REQUIRED_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${HDF5_C_LIBRARIES} SZIP::SZIP ZLIB::ZLIB ${CMAKE_DL_LIBS} )
195- else ()
196- set (CMAKE_REQUIRED_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${HDF5_C_LIBRARIES} ZLIB::ZLIB ${CMAKE_DL_LIBS} )
197- endif ()
198- else ()
199- set (CMAKE_REQUIRED_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${HDF5_C_LIBRARIES} ${CMAKE_DL_LIBS} )
200- endif ()
201-
202- set (THREADS_PREFER_PTHREAD_FLAG true )
203- find_package (Threads)
204- if (Threads_FOUND)
205- list (APPEND CMAKE_REQUIRED_LIBRARIES Threads::Threads)
206- endif ()
207-
222+ detect_config()
208223endif (HDF5_C_FOUND)
209224
210225# --- configure time checks
0 commit comments