hdf5
hdf5 copied to clipboard
Can not use parallel target in CMake in pure C++ project
Describe the bug When trying to link against the parallel HDF5 target in CMake in a C++ project, CMake complains that the MPI_C target is not found:
CMake Error at /home/cmacmack/.spack/opt/spack/linux-linuxmint21-icelake/gcc-11.3.0/hdf5-1.14.1-2-nabfxjrrsno6gmfw5fsnot4b5geztyd3/cmake/hdf5-targets.cmake:68 (set_target_properties):
The link interface of target "hdf5-shared" contains:
MPI::MPI_C
but the target was not found. Possible reasons include:
* There is a typo in the target name.
* A find_package call is missing for an IMPORTED target.
* An ALIAS target is missing.
This is related to but distinct from the bug addressed by #2400. The reason for the error is that the project only enables the C++ language and CMake therefore does not import the MPI_C target. (Presumably there would be a similar issue in Fortran projects.) Adding enable_language(C)
before importing the HDF5 package fixes the problem.
Expected behavior Parallel HDF5 imports the MPI::MPI_C package to satisfy its public dependency.
Platform (please complete the following information)
- HDF5 1.14.1-2
- Linux Mint 21.1 (which is based on Ubuntu 22.04)
- GCC 11.3.0
- CMake 3.24.3
-
set(HDF5_PREFER_PARALLEL TRUE)
- MPICH 4.1.1
HDF5 and its dependencies were compiled using Spack v0.20.3.
I have the same problem in a pure Fortran project where Fortran is the only enabled language. I'm doing
set(HDF5_PREFER_PARALLEL TRUE)
find_package(HDF5 REQUIRED COMPONENTS Fortran)
if (NOT HDF5_IS_PARALLEL)
message(FATAL_ERROR "Parallel HDF5 Required.")
endif ()
and my software versions are as follows
- HDF5 1.14.3
- RHEL 8.8
- Nvidia Fortran Compiler (nvfortran) 24.3
- CMake 3.27.9
- OpenMPI 4.1.6
HDF5, CMake, OpenMPI and their dependencies were built with Spack at d5c1e16e43.
Is it possible to get around this without enabling C (which slows down CMake configuration and is otherwise unneeded)? This only seems to be a problem with HDF5 1.14 and I've not had this problem with various build of 1.12 and 1.10.