From a3f72007ab611d4adfe8ccfd61f80928a07a2175 Mon Sep 17 00:00:00 2001 From: Fabio Rossi Date: Tue, 6 Jan 2026 14:56:03 +0100 Subject: [PATCH] fix hdf5 detection avoid side-effects of reusing cached variables (defined PCHDF5_FOUND for pkgconfig and HDF5_HEAD_FOUND for hdf5.h detections) --- cMake/FreeCAD_Helpers/SetupSalomeSMESH.cmake | 33 ++++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/cMake/FreeCAD_Helpers/SetupSalomeSMESH.cmake b/cMake/FreeCAD_Helpers/SetupSalomeSMESH.cmake index c991d49cfe..f39dc8f34f 100644 --- a/cMake/FreeCAD_Helpers/SetupSalomeSMESH.cmake +++ b/cMake/FreeCAD_Helpers/SetupSalomeSMESH.cmake @@ -103,20 +103,33 @@ macro(SetupSalomeSMESH) set(HDF5_VARIANT "hdf5-serial") else() message(STATUS "We guess that libmed was built using hdf5-openmpi version") - set(HDF5_VARIANT "hdf5-openmpi") + set(HDF5_VARIANT "hdf5-openmpi;hdf5_openmpi") set(HDF5_PREFER_PARALLEL TRUE) # if pkg-config fails, find_package(HDF5) needs this endif() - pkg_search_module(HDF5 ${HDF5_VARIANT}) - if(NOT HDF5_FOUND) + pkg_search_module(PCHDF5 ${HDF5_VARIANT}) + if(NOT PCHDF5_FOUND) find_package(HDF5 REQUIRED) else() - add_compile_options(${HDF5_CFLAGS}) - link_directories(${HDF5_LIBRARY_DIRS}) - link_libraries(${HDF5_LIBRARIES}) - endif() - check_include_file_cxx(hdf5.h HDF5_FOUND) - if(NOT HDF5_FOUND) - message( FATAL_ERROR "hdf5.h was not found.") + add_compile_options(${PCHDF5_CFLAGS}) + link_directories(${PCHDF5_LIBRARY_DIRS}) + link_libraries(${PCHDF5_LIBRARIES}) + + # workaround to define include dir from PCHDF5_CFLAGS (pkg-config PCHDF5_INCLUDEDIR is only filled since hdf5 1.14.6) + set(hdf5_include_path "") + foreach(flag IN LISTS PCHDF5_CFLAGS) + if(flag MATCHES "^-I") + string(REGEX REPLACE "^-I[ ]*" "" flag "${flag}") + list(APPEND hdf5_include_path "${flag}") + endif() + endforeach() + + set(_save_INC CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_INCLUDES ${hdf5_include_path}) + check_include_file_cxx(hdf5.h HDF5_HEAD_FOUND) + set(CMAKE_REQUIRED_INCLUDES ${_save_INC}) + if(NOT HDF5_HEAD_FOUND) + message( FATAL_ERROR "hdf5.h was not found (tested pkg-config ${HDF5_VARIANT}, suggested header location was '${hdf5_include_path}').") + endif() endif() # Med Fichier can require MPI