Fix MPI Fortran configuration for HDF5Examples (#6206)

When building Fortran parallel examples without MPI wrappers, the
compiler couldn't find mpi.mod because MPI_Fortran_INCLUDE_DIRS
was not populated. This occurred because find_package(MPI) was only
called for C, not Fortran.

Added enable_language(Fortran) and find_package(MPI REQUIRED
COMPONENTS Fortran) to properly configure MPI for Fortran examples,
ensuring MPI include directories and libraries are correctly set.
This commit is contained in:
Scot Breitenfeld
2026-02-06 10:06:35 -06:00
committed by GitHub
parent 519bcf787e
commit b8b246e14a
+2
View File
@@ -143,10 +143,12 @@ 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}")