cmake - use find_package for hdf5 as a general fallback

Previously we were setting `HDF5_LIBRARIES` explicitly, but I'm not sure if really worked, since we never set `HDF5_INCLUDE_DIR` and user would have to provide it manually either way.
`find_package(HDF5)` will search for default paths and will set `HDF5_LIBRARIES` and `HDF5_INCLUDE_DIR` automatically.
This commit is contained in:
Andrej730
2025-09-17 10:27:35 +05:00
parent 94851016d7
commit 867852688e
+12 -15
View File
@@ -746,27 +746,24 @@ if(HDF5_SUPPORT)
endif()
endif()
if(NOT HDF5_LIBRARIES)
if(NOT WIN32 AND NOT APPLE)
# debian default
set(HDF5_LIBRARIES
/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_cpp.so
/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so
/usr/lib/x86_64-linux-gnu/libsz.so
/usr/lib/x86_64-linux-gnu/libaec.so
z dl
)
if(NOT HDF5_INCLUDE_DIR)
# First try to find it as a config.
find_package(HDF5 CONFIG)
if(HDF5_DIR)
message(STATUS "HDF5: found config at '${HDF5_DIR}'.")
set(HDF5_LIBRARIES hdf5_cpp-static)
else()
find_package(HDF5 CONFIG)
if(NOT HDF5_DIR)
# If it failed, still try to find as a module.
# E.g. on Ubuntu `libhdf5-dev` doesn't provie hdf5-config.cmake.
# Will automatically fill HDF5_LIBRARIES and HDF5_INCLUDE_DIR.
find_package(HDF5)
if(NOT HDF5_INCLUDE_DIR)
message(
FATAL_ERROR
"HDF5_LIBRARY_DIR is not provided (current value: '${HDF5_LIBRARY_DIR}'). "
"Also could not find HDF5 package."
"Also could not find HDF5 package (neither module or config)."
)
endif()
message(STATUS "Found HDF5 package: '${HDF5_DIR}'.")
set(HDF5_LIBRARIES hdf5_cpp-static)
endif()
endif()