From 49ae2f225a4bfbcf3ed724f16d09e30e06c8d636 Mon Sep 17 00:00:00 2001 From: Scot Breitenfeld Date: Thu, 12 Feb 2026 14:10:39 -0600 Subject: [PATCH] Updates to #6205 (#6208) * Fix MPI Fortran configuration for HDF5Examples (#6205) When building Fortran parallel examples standalone without MPI wrappers, the compiler cannot find mpi.mod because MPI_Fortran_INCLUDE_DIRS is not populated. * Use MPI::MPI_Fortran imported target instead of raw MPI variables Replace manual MPI_Fortran_LIBRARIES, MPI_Fortran_LINK_FLAGS, and MPI_Fortran_INCLUDE_DIRS usage with the MPI::MPI_Fortran imported target, which transitively carries all include dirs, compile flags, and link flags. This eliminates the CMAKE_Fortran_EXE_LINKER_FLAGS hack and the manual target_include_directories in H5PAR. --- HDF5Examples/CMakeLists.txt | 11 +---------- HDF5Examples/FORTRAN/CMakeLists.txt | 7 +++++++ HDF5Examples/FORTRAN/H5PAR/CMakeLists.txt | 1 - 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/HDF5Examples/CMakeLists.txt b/HDF5Examples/CMakeLists.txt index 23ca29e3ea1..cb5086c5ab8 100644 --- a/HDF5Examples/CMakeLists.txt +++ b/HDF5Examples/CMakeLists.txt @@ -143,18 +143,8 @@ if (${H5_LIBVER_DIR} GREATER 16) if (EXISTS "${H5EXAMPLES_SOURCE_DIR}/FORTRAN" AND IS_DIRECTORY "${H5EXAMPLES_SOURCE_DIR}/FORTRAN") option (H5EXAMPLE_BUILD_FORTRAN "Build examples FORTRAN support" OFF) if (H5EXAMPLE_BUILD_FORTRAN AND HDF5_PROVIDES_FORTRAN) - enable_language(Fortran) set (H5EXAMPLE_LINK_Fortran_LIBS ${H5EXAMPLE_HDF5_LINK_LIBS}) - # Parallel IO usage requires MPI to be Linked and Included - if (H5_HAVE_PARALLEL) - find_package(MPI REQUIRED COMPONENTS Fortran) - set (H5EXAMPLE_LINK_Fortran_LIBS ${H5EXAMPLE_LINK_Fortran_LIBS} ${MPI_Fortran_LIBRARIES}) - if (MPI_Fortran_LINK_FLAGS) - set (CMAKE_Fortran_EXE_LINKER_FLAGS "${MPI_Fortran_LINK_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}") - endif () - endif () - configure_file (${H5EXAMPLE_F90_SRC_DIR}/H5D/h5_version.h.in ${PROJECT_BINARY_DIR}/FORTRAN/H5D/h5_version.h @ONLY) configure_file (${H5EXAMPLE_F90_SRC_DIR}/H5D/h5_version.h.in ${PROJECT_BINARY_DIR}/FORTRAN/H5G/h5_version.h @ONLY) else () @@ -225,6 +215,7 @@ endif () # Build examples #----------------------------------------------------------------------------- add_subdirectory (C) +# Fortran MPI setup (find_package, link flags) is handled in FORTRAN/CMakeLists.txt if (H5EXAMPLE_BUILD_FORTRAN AND HDF5_PROVIDES_FORTRAN) add_subdirectory (FORTRAN) endif () diff --git a/HDF5Examples/FORTRAN/CMakeLists.txt b/HDF5Examples/FORTRAN/CMakeLists.txt index bd4e24fbc7a..6ca9afb4ed2 100644 --- a/HDF5Examples/FORTRAN/CMakeLists.txt +++ b/HDF5Examples/FORTRAN/CMakeLists.txt @@ -1,6 +1,13 @@ cmake_minimum_required (VERSION 3.26) PROJECT (HDF5Examples_F90 Fortran) +# Parallel IO usage requires MPI to be linked and included +if (H5_HAVE_PARALLEL) + find_package(MPI REQUIRED COMPONENTS Fortran) + # Use imported target — carries include dirs, compile flags, and link flags transitively + list(APPEND H5EXAMPLE_LINK_Fortran_LIBS MPI::MPI_Fortran) +endif () + #----------------------------------------------------------------------------- # Build the Fortran Examples #----------------------------------------------------------------------------- diff --git a/HDF5Examples/FORTRAN/H5PAR/CMakeLists.txt b/HDF5Examples/FORTRAN/H5PAR/CMakeLists.txt index fc818f84b35..f50712b8d82 100644 --- a/HDF5Examples/FORTRAN/H5PAR/CMakeLists.txt +++ b/HDF5Examples/FORTRAN/H5PAR/CMakeLists.txt @@ -30,7 +30,6 @@ foreach (example_name ${examples}) "$<$:-DH5_USE_114_API>" "$<$:-DH5_USE_200_API>" ) - target_include_directories (${EXAMPLE_VARNAME}_f90_${example_name} PUBLIC ${MPI_Fortran_INCLUDE_DIRS}) target_link_libraries (${EXAMPLE_VARNAME}_f90_${example_name} ${H5EXAMPLE_LINK_Fortran_LIBS}) set_target_properties (${EXAMPLE_VARNAME}_f90_${example_name} PROPERTIES LINKER_LANGUAGE Fortran) endforeach ()