Skip to content

Commit 565b24a

Browse files
committed
findhdf5: don't error when some components not found
1 parent cf2a47e commit 565b24a

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ find_c_fortran()
66

77
project(h5fortran
88
LANGUAGES C Fortran
9-
VERSION 3.4.4
9+
VERSION 3.4.5
1010
DESCRIPTION "thin, light object-oriented HDF5 Fortran interface"
1111
HOMEPAGE_URL https://github.com/geospace-code/h5fortran)
1212

cmake/Modules/FindHDF5.cmake

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,22 @@ if(_zlib)
9292
find_package(ZLIB REQUIRED)
9393

9494
if(_szip)
95-
# Szip even though not directly used because if system static links libhdf5 with szip,
95+
# Szip even though not used by h5fortran.
96+
# If system HDF5 dynamically links libhdf5 with szip,
9697
# our builds will fail if we don't also link szip.
97-
find_package(SZIP REQUIRED)
98-
set(CMAKE_REQUIRED_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${HDF5_C_LIBRARIES} SZIP::SZIP ZLIB::ZLIB ${CMAKE_DL_LIBS})
99-
else()
100-
set(CMAKE_REQUIRED_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${HDF5_C_LIBRARIES} ZLIB::ZLIB ${CMAKE_DL_LIBS})
98+
# however, we don't require SZIP for this case as other HDF5 libraries may statically
99+
# link SZIP.
100+
find_package(SZIP)
101+
if(SZIP_FOUND)
102+
list(APPEND CMAKE_REQUIRED_LIBRARIES SZIP::SZIP)
103+
endif()
101104
endif()
102-
else()
103-
set(CMAKE_REQUIRED_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${HDF5_C_LIBRARIES} ${CMAKE_DL_LIBS})
105+
106+
list(APPEND CMAKE_REQUIRED_LIBRARIES ZLIB::ZLIB)
104107
endif()
105108

109+
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
110+
106111
set(THREADS_PREFER_PTHREAD_FLAG true)
107112
find_package(Threads)
108113
if(Threads_FOUND)
@@ -116,11 +121,12 @@ endfunction(detect_config)
116121

117122
# === main program
118123

124+
set(CMAKE_REQUIRED_LIBRARIES)
119125
set(_lsuf hdf5 hdf5/serial)
120126
set(_psuf static ${_lsuf})
121127

122128
# we don't use pkg-config directly because some distros pkg-config for HDF5 is broken
123-
# however so far at least we've see the paths are often correct
129+
# however at least the paths are often correct
124130

125131
find_package(PkgConfig)
126132
if(PkgConfig_FOUND)
@@ -169,6 +175,7 @@ if(Fortran IN_LIST HDF5_FIND_COMPONENTS)
169175
DOC "HDF5 Fortran modules")
170176

171177
if(HDF5_Fortran_HL_LIBRARY AND HDF5_Fortran_LIBRARY AND HDF5_Fortran_INCLUDE_DIR)
178+
list(APPEND CMAKE_REQUIRED_LIBRARIES ${HDF5_Fortran_LIBRARIES})
172179
set(HDF5_Fortran_FOUND true)
173180
set(HDF5_HL_FOUND true)
174181
endif()
@@ -219,6 +226,7 @@ find_path(HDF5_INCLUDE_DIR
219226
DOC "HDF5 C header")
220227

221228
if(HDF5_C_HL_LIBRARY AND HDF5_C_LIBRARY AND HDF5_INCLUDE_DIR)
229+
list(APPEND CMAKE_REQUIRED_LIBRARIES ${HDF5_C_LIBRARIES})
222230
set(HDF5_C_FOUND true)
223231
set(HDF5_HL_FOUND true)
224232
endif()
@@ -279,12 +287,9 @@ if(HDF5_Fortran_FOUND AND NOT HDF5_Fortran_links)
279287
set(HDF5_links false)
280288
endif()
281289

282-
set(CMAKE_REQUIRED_INCLUDES)
283-
set(CMAKE_REQUIRED_LIBRARIES)
284-
285290
include(FindPackageHandleStandardArgs)
286291
find_package_handle_standard_args(HDF5
287-
REQUIRED_VARS HDF5_links
292+
REQUIRED_VARS HDF5_C_LIBRARIES HDF5_links
288293
VERSION_VAR HDF5_VERSION
289294
HANDLE_COMPONENTS)
290295

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
project('h5fortran', 'fortran',
22
meson_version : '>=0.52.0',
3-
version : '3.4.4',
3+
version : '3.4.5',
44
default_options : ['default_library=static', 'buildtype=release', 'warning_level=3'])
55

66
subdir('meson')

0 commit comments

Comments
 (0)