Skip to content

Commit 5b3b7e3

Browse files
committed
handle missing H5pubconf.h correctly
1 parent fa95c81 commit 5b3b7e3

File tree

4 files changed

+78
-62
lines changed

4 files changed

+78
-62
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if(NOT HDF5_FOUND)
2727
endif()
2828

2929
if(HDF5_VERSION VERSION_LESS 1.8.7)
30-
message(STATUS "H5Fortran requires HDF5 >= 1.8.7")
30+
message(WARNING "H5Fortran requires HDF5 >= 1.8.7")
3131
endif()
3232

3333
# --- h5fortran library
@@ -54,7 +54,7 @@ endif()
5454

5555
include(FeatureSummary)
5656
set_package_properties(Threads PROPERTIES DESCRIPTION "the system threads library")
57-
set_package_properties(HDF5 PROPERTIES URL "https://hdfgroup.org/" DESCRIPTION "fast, versatile file I/O format" TYPE REQUIRED)
57+
set_package_properties(HDF5 PROPERTIES URL "https://hdfgroup.org/" DESCRIPTION "versatile file format" TYPE REQUIRED)
5858
set_package_properties(ZLIB PROPERTIES URL "https://www.zlib.net/" DESCRIPTION "patent-free compression library")
5959
set_package_properties(SZIP PROPERTIES URL "http://www.compressconsult.com/szip/" DESCRIPTION "compression library")
6060

cmake/Modules/FindHDF5.cmake

Lines changed: 73 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
41113
set(_lsuf hdf5 hdf5/serial)
42114
set(_psuf static ${_lsuf})
43115

@@ -147,64 +219,7 @@ endif()
147219

148220
# required libraries
149221
if(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()
208223
endif(HDF5_C_FOUND)
209224

210225
# --- configure time checks

cmake/win32_hdf5.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# NOTE: this isn't used anymore. I may delete in the future. I think it's better to just build your own HDF5 rather than use the shaky download for Windows.
2+
13
function(win32_hdf5_env)
24
# Windows with HDF5 needs this interesting workaround of
35
# copying HDF5 dlls to the CMAKE_BINARY_DIR.

setup.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ if(NOT DEFINED CTEST_CMAKE_GENERATOR AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.1
2626
endif(_gen)
2727
endif()
2828
if(NOT DEFINED CTEST_CMAKE_GENERATOR)
29+
set(CTEST_BUILD_FLAGS -j) # not --parallel as this goes to generator directly
2930
if(WIN32)
3031
set(CTEST_CMAKE_GENERATOR "MinGW Makefiles")
31-
set(CTEST_BUILD_FLAGS -j) # not --parallel as this goes to generator directly
3232
else()
3333
set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
34-
set(CTEST_BUILD_FLAGS -j) # not --parallel as this goes to generator directly
3534
endif()
3635
endif()
3736

0 commit comments

Comments
 (0)