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()
endif() endif()
if(NOT HDF5_LIBRARIES) if(NOT HDF5_INCLUDE_DIR)
if(NOT WIN32 AND NOT APPLE) # First try to find it as a config.
# debian default find_package(HDF5 CONFIG)
set(HDF5_LIBRARIES if(HDF5_DIR)
/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_cpp.so message(STATUS "HDF5: found config at '${HDF5_DIR}'.")
/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so set(HDF5_LIBRARIES hdf5_cpp-static)
/usr/lib/x86_64-linux-gnu/libsz.so
/usr/lib/x86_64-linux-gnu/libaec.so
z dl
)
else() else()
find_package(HDF5 CONFIG) # If it failed, still try to find as a module.
if(NOT HDF5_DIR) # 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( message(
FATAL_ERROR FATAL_ERROR
"HDF5_LIBRARY_DIR is not provided (current value: '${HDF5_LIBRARY_DIR}'). " "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() endif()
message(STATUS "Found HDF5 package: '${HDF5_DIR}'.")
set(HDF5_LIBRARIES hdf5_cpp-static)
endif() endif()
endif() endif()