FindHDF5 fails finding Fortran when HDF5 HL is not built/available
I have a problem making FindHDF5 from CMake 3.21 work for my application. I have a quite straight forward application written in Fortran and some C. I use MPI and HDF5, which are my two main dependencies.
I compile the HDF5 library myself, and do not need the high-level HDF5 stuff, so that does not exist in my install. When I try to find_package( HDF5 COMPONENTS C Fortran REQUIRED )
in my CMakeLists.txt it does not work.
The error I get is:
-- Found MPI_C: /opt/intel/compilers_and_libraries_2020.4.304/linux/mpi/intel64/lib/release/libmpi.so (found version "3.1")
-- Found MPI_Fortran: /opt/intel/compilers_and_libraries/linux/mpi/intel64/lib/libmpifort.so (found version "3.1")
-- Found MPI: TRUE (found version "3.1") found components: C Fortran
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- HDF5 Fortran compiler wrapper is unable to compile a minimal HDF5 program.
CMake Warning at /usr/local/share/cmake-3.21/Modules/FindHDF5.cmake:742 (message):
HDF5 found for language Fortran is not parallel but previously found
language is parallel.
Call Stack (most recent call first):
src/CMakeLists.txt:6 (find_package)
CMake Error at /usr/local/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find HDF5 (missing: HDF5_LIBRARIES HDF5_INCLUDE_DIRS Fortran)
(found version "")
Call Stack (most recent call first):
/usr/local/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/usr/local/share/cmake-3.21/Modules/FindHDF5.cmake:1001 (find_package_handle_standard_args)
src/CMakeLists.txt:6 (find_package)
-- Configuring incomplete, errors occurred!
I have tracked down the reason, and it lies in the cmake_hdf5_test.f90
produced by FindHDF5.cmake that is used to test if the compiler can build and link a HDF5 program.
The contents of cmake_hdf5_test.f90
is:
program hdf5_hello
use hdf5
use h5lt
use h5ds
integer error
call h5open_f(error)
call h5close_f(error)
end
which require the high-level libraries to be built, because of the use h5lt
and use h5ds
, both coming from the high-level library. If I comment out the use of h5lt
and h5ds
it works.
I wonder, is this a design feature, or a bug? It seems very strange, that you are allowed to use the C interfaces without the HL library (because in the corresponding cmake_hdf5_test.c
there is only #include <hdf5.h>
and not #include <hdf5_hl.h>
), but not with Fortran.