Describe the bug
I work on a program that uses a mixture of C and Fortran. Only the C side of the code interacts with HDF5 or MPI. As a result, we typically don't enable Fortran support in our MPI and HDF5 builds.
If I build our code with parallel HDF5 2.1.0 or 2.1.1, however, the call to find_dependency(MPI QUIET REQUIRED), [here] will see that we have the Fortran language enabled, and attempt to load MPI::MPI_Fortran.
Here is a minimum working example that shows this behavior. To trigger a failure requires a build of MPI without Fortran enabled, such as OpenMPI with the --enable-mpi-fortran=no configure option.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.27)
project(TestProject LANGUAGES C Fortran)
find_package(HDF5 NAMES hdf5 REQUIRED COMPONENTS C)
add_executable(test
test.c
test.f90
)
set_target_properties(test PROPERTIES LINKER_LANGUAGE C)
target_link_libraries(test PRIVATE hdf5-shared)
test.c:
#include "hdf5.h"
extern double return_1();
int main(void) {
double fortran_value = return_1();
printf("Fortran function returned: %f\n", fortran_value);
// Create HDF5 file
hid_t file_id = H5Fcreate("test.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
H5Fclose(file_id);
}
test.f90:
function return_1() result(val) bind(C, name="return_1")
use iso_c_binding
implicit none
real(c_double) :: val
val = 1.0d0
end function return_1
On my machine, I get the output:
CMake Error at ${BUILDSYSTEM}/cmake/cmake-4.3.1/share/cmake-4.3/Modules/FindPackageHandleStandardArgs.cmake:290 (message):
Could NOT find MPI (missing: MPI_Fortran_FOUND) (found version "3.1")
Call Stack (most recent call first):
${BUILDSYSTEM}/cmake/cmake-4.3.1/share/cmake-4.3/Modules/FindPackageHandleStandardArgs.cmake:654 (_FPHSA_FAILURE_MESSAGE)
${BUILDSYSTEM}/cmake/cmake-4.3.1/share/cmake-4.3/Modules/FindMPI.cmake:2006 (find_package_handle_standard_args)
${BUILDSYSTEM}/cmake/cmake-4.3.1/share/cmake-4.3/Modules/CMakeFindDependencyMacro.cmake:93 (find_package)
${BUILDSYSTEM}/cmake/cmake-4.3.1/share/cmake-4.3/Modules/CMakeFindDependencyMacro.cmake:125 (__find_dependency_common)
${HOME}/HDF5/cmake/hdf5-config.cmake:124 (find_dependency)
CMakeLists.txt:5 (find_package)
Replacing find_dependency(MPI QUIET REQUIRED) with find_dependency(MPI QUIET REQUIRED COMPONENTS C) in hdf5-config.cmake.in appears to fix it, but I don't know enough of HDF5's architecture to know if this will cause problems.
Expected behavior
I expect a non-Fortran build of HDF5 to not need MPI_Fortran.
Platform
- HDF5 commit f010df9
- Linux, RHEL 8
- Intel 2024.2.1 (
icx + ifort)
- CMake 4.3.1 + Ninja 1.13.2
- Built with
cmake .. -G Ninja -DHDF5_ENABLE_PARALLEL=ON -DHDF5_BUILD_FORTRAN=OFF
- OpenMPI 5.0.10 with
--enable-mpi-fortran=no
We have also tested 2.1.1 and 2.1.0 on various other systems, such as Windows with MS-MPI, which does not provide Fortran bindings, and have had similar issues.
Describe the bug
I work on a program that uses a mixture of C and Fortran. Only the C side of the code interacts with HDF5 or MPI. As a result, we typically don't enable Fortran support in our MPI and HDF5 builds.
If I build our code with parallel HDF5 2.1.0 or 2.1.1, however, the call to
find_dependency(MPI QUIET REQUIRED), [here] will see that we have the Fortran language enabled, and attempt to loadMPI::MPI_Fortran.Here is a minimum working example that shows this behavior. To trigger a failure requires a build of MPI without Fortran enabled, such as OpenMPI with the
--enable-mpi-fortran=noconfigure option.CMakeLists.txt:
test.c:
test.f90:
On my machine, I get the output:
Replacing
find_dependency(MPI QUIET REQUIRED)withfind_dependency(MPI QUIET REQUIRED COMPONENTS C)inhdf5-config.cmake.inappears to fix it, but I don't know enough of HDF5's architecture to know if this will cause problems.Expected behavior
I expect a non-Fortran build of HDF5 to not need
MPI_Fortran.Platform
icx+ifort)cmake .. -G Ninja -DHDF5_ENABLE_PARALLEL=ON -DHDF5_BUILD_FORTRAN=OFF--enable-mpi-fortran=noWe have also tested 2.1.1 and 2.1.0 on various other systems, such as Windows with MS-MPI, which does not provide Fortran bindings, and have had similar issues.