From 674ed36e4135ae245bd65f4c515550ac61722066 Mon Sep 17 00:00:00 2001 From: Bruno Postle Date: Thu, 4 Jun 2026 22:31:48 +0100 Subject: [PATCH] Fix HDF5 config-mode detection to use shared library when static is absent When HDF5 is found via its CMake config file, the code previously hardcoded the hdf5_cpp-static target. On distributions that ship only shared HDF5 (e.g. Fedora rawhide where the config file was added in a newer package), this caused a link failure. Now checks for hdf5_cpp-static, hdf5_cpp-shared, and hdf5::hdf5_cpp-shared in order, falling back to module-mode discovery. --- cmake/FindHDF5.cmake | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmake/FindHDF5.cmake b/cmake/FindHDF5.cmake index 399b1c9f13..3230336a7d 100644 --- a/cmake/FindHDF5.cmake +++ b/cmake/FindHDF5.cmake @@ -88,7 +88,15 @@ if(NOT HDF5_INCLUDE_DIR OR NOT HDF5_LIBRARY_DIR) mark_as_advanced(HDF5_DIR) if(HDF5_DIR) message(STATUS "HDF5: found config at '${HDF5_DIR}'.") - set(HDF5_LIBRARIES hdf5_cpp-static) + if(TARGET hdf5_cpp-static) + set(HDF5_LIBRARIES hdf5_cpp-static) + elseif(TARGET hdf5_cpp-shared) + set(HDF5_LIBRARIES hdf5_cpp-shared) + elseif(TARGET hdf5::hdf5_cpp-shared) + set(HDF5_LIBRARIES hdf5::hdf5_cpp-shared) + else() + find_package(HDF5 REQUIRED COMPONENTS CXX) + endif() else() # If it failed, still try to find as a module. # E.g. on Ubuntu `libhdf5-dev` doesn't provie hdf5-config.cmake.