My project’s CMakeLists.txt includes find_package(HDF5 REQUIRED COMPONENTS Fortran CONFIG). I get no errors with cmake ../ from the build directory, but cmake --build . gives this error:
45 | USE HDF5
| 1
Fatal Error: Cannot open module file 'hdf5.mod' for reading at (1): No such file or directory
compilation terminated.
The hdf5.mod file is certainly present, and CMake finds the hdf5-config.cmake file, so I don’t know what to try or what’s going on.
We do test our binaries with the HDF5 Examples project (included in the CMake-hdf5-1.12.2.zipe file).
In the base CMakeLists.txt file after finding HDF5, we check for Fortran support:
option (HDF_BUILD_FORTRAN "Build FORTRAN support" OFF)
if (HDF_BUILD_FORTRAN AND HDF5_BUILD_FORTRAN)
set (LINK_Fortran_LIBS ${LINK_LIBS})
# Parallel IO usage requires MPI to be Linked and Included
if (H5_HAVE_PARALLEL)
set (LINK_Fortran_LIBS ${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 ()
add_subdirectory (FORTRAN)
configure_file (${HDF5EX_F90_SRC_DIR}/H5D/h5_version.h.in ${PROJECT_BINARY_DIR}/FORTRAN/H5D/h5_version.h @ONLY)
endif ()
and then in the Fortran subdir (these includes should be moved to target includes, though):
For anyone else struggling with using/enabling/testing Fortran libs with the CMake build, here’s another hint. The magical (and as far as I can tell undocumented) incantation you need to build the Fortran examples is:
$ cd HDF5Examples
$ mkdir build
$ cd build
$ cmake -DHDF_BUILD_FORTRAN=ON -DBUILD_SHARED_LIBS=ON ../
I did not touch any configuration about static vs shared libs before, and it seems to me like shared is the default .