fix hdf5 detection

avoid side-effects of reusing cached variables (defined PCHDF5_FOUND for
pkgconfig and HDF5_HEAD_FOUND for hdf5.h detections)
This commit is contained in:
Fabio Rossi
2026-01-06 14:56:03 +01:00
committed by Chris Hennes
parent 7ddee25ec9
commit 419e1822b8

View File

@@ -103,20 +103,33 @@ macro(SetupSalomeSMESH)
set(HDF5_VARIANT "hdf5-serial") set(HDF5_VARIANT "hdf5-serial")
else() else()
message(STATUS "We guess that libmed was built using hdf5-openmpi version") 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 set(HDF5_PREFER_PARALLEL TRUE) # if pkg-config fails, find_package(HDF5) needs this
endif() endif()
pkg_search_module(HDF5 ${HDF5_VARIANT}) pkg_search_module(PCHDF5 ${HDF5_VARIANT})
if(NOT HDF5_FOUND) if(NOT PCHDF5_FOUND)
find_package(HDF5 REQUIRED) find_package(HDF5 REQUIRED)
else() else()
add_compile_options(${HDF5_CFLAGS}) add_compile_options(${PCHDF5_CFLAGS})
link_directories(${HDF5_LIBRARY_DIRS}) link_directories(${PCHDF5_LIBRARY_DIRS})
link_libraries(${HDF5_LIBRARIES}) link_libraries(${PCHDF5_LIBRARIES})
endif()
check_include_file_cxx(hdf5.h HDF5_FOUND) # workaround to define include dir from PCHDF5_CFLAGS (pkg-config PCHDF5_INCLUDEDIR is only filled since hdf5 1.14.6)
if(NOT HDF5_FOUND) set(hdf5_include_path "")
message( FATAL_ERROR "hdf5.h was not found.") 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() endif()
# Med Fichier can require MPI # Med Fichier can require MPI