Skip to content

Commit 795a07a

Browse files
committed
FindHDF5: check that all components present before prereqs
1 parent 8144e3e commit 795a07a

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

cmake/Modules/FindHDF5.cmake

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,17 @@ URL "https://hdfgroup.org/"
4444
DESCRIPTION "versatile file format"
4545
PURPOSE "h5fortran is an object-oriented HDF5 API")
4646

47+
4748
function(detect_config)
4849

50+
if(Fortran IN_LIST HDF5_FIND_COMPONENTS AND NOT HDF5_Fortran_FOUND)
51+
return()
52+
endif()
53+
54+
if(CXX IN_LIST HDF5_FIND_COMPONENTS AND NOT HDF5_CXX_FOUND)
55+
return()
56+
endif()
57+
4958
set(CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIR})
5059

5160
foreach(f H5pubconf.h H5pubconf-64.h)
@@ -79,6 +88,10 @@ if( "${_def}" MATCHES
7988
set(HDF5_VERSION ${HDF5_VERSION} PARENT_SCOPE)
8089
endif()
8190

91+
if(PkgConfig_FOUND)
92+
pkg_search_module(pc_zlib zlib)
93+
endif()
94+
8295
# otherwise can pickup miniconda zlib
8396
get_filename_component(_hint ${HDF5_C_LIBRARY} DIRECTORY)
8497
if(NOT ZLIB_ROOT)
@@ -127,11 +140,9 @@ set(_psuf static ${_lsuf})
127140

128141
# we don't use pkg-config directly because some distros pkg-config for HDF5 is broken
129142
# however at least the paths are often correct
130-
131143
find_package(PkgConfig)
132144
if(PkgConfig_FOUND)
133145
pkg_search_module(pc_hdf5 hdf5 hdf5-serial)
134-
pkg_search_module(pc_zlib zlib)
135146
endif()
136147

137148
if(Fortran IN_LIST HDF5_FIND_COMPONENTS)

cmake/build_hdf5.cmake

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,8 @@ set(HDF5_INCLUDE_DIRS ${HDF5_ROOT}/include)
2121
# --- Zlib
2222
set(zlib_root -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=ON -DZLIB_USE_EXTERNAL:BOOL=OFF)
2323

24-
if(TARGET ZLIB::ZLIB)
25-
get_property(ZLIB_ROOT TARGET ZLIB::ZLIB PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
26-
list(APPEND zlib_root -DZLIB_ROOT:PATH=${ZLIB_ROOT} -DZLIB_LIBRARY:FILEPATH=${ZLIB_LIBRARIES} -DZLIB_INCLUDE_DIR:PATH=${ZLIB_INCLUDE_DIRS})
27-
add_custom_target(ZLIB) # dummy
28-
else()
29-
include(${CMAKE_CURRENT_LIST_DIR}/zlib_setup.cmake)
30-
endif()
24+
include(${CMAKE_CURRENT_LIST_DIR}/zlib_setup.cmake)
25+
3126
# --- HDF5
3227
# https://forum.hdfgroup.org/t/issues-when-using-hdf5-as-a-git-submodule-and-using-cmake-with-add-subdirectory/7189/2
3328

0 commit comments

Comments
 (0)