From 867852688e5367f630d41e2419db1adf54e506a6 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 17 Sep 2025 10:27:35 +0500 Subject: [PATCH] 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. --- cmake/CMakeLists.txt | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 86a9ebccb1..5d058fa16b 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -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()