* 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.
This commit is contained in:
Scot Breitenfeld
2026-02-12 14:10:39 -06:00
committed by GitHub
parent a46a399230
commit 49ae2f225a
3 changed files with 8 additions and 11 deletions
+1 -10
View File
@@ -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 ()
+7
View File
@@ -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
#-----------------------------------------------------------------------------
@@ -30,7 +30,6 @@ foreach (example_name ${examples})
"$<$<BOOL:${${EXAMPLE_VARNAME}_USE_114_API}>:-DH5_USE_114_API>"
"$<$<BOOL:${${EXAMPLE_VARNAME}_USE_200_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 ()