I successfully built and installed HDF5 with parallel support using CMake. In my C++ project, which also uses CMake as build system, I want to check whether the HDF5 library found by find_package(HDF5 REQUIRED) has parallel mode enabled.
While I can check the value of the macro H5_HAVE_PARALLEL in my C++ code, I would prefer checking it at build time. Namely, if the HDF5 library found by CMake has no parallel support, the CMake build process should fail. Unfortunately, H5_HAVE_PARALLEL is a C macro, so I cannot use it directly in the CMakeLists.txt.
Is the parallel support indicated somewhere? Maybe exposed as a CMake variable or shown when running one of the HDF5 executables (h5dump, h5diff, etc.)?
After find_package call and check that HDF5_FOUND is true all the “User Options” in the hdf5-config.cmake file are available as variables, just like all the targets in hdf5-targets.cmake file are available for use. See the HDF5Examples config/source files for how this is done.
Depends on your use case - but you can browse the HDF5Examples source. In particular, look at the C/CMakeLists.txt file for if (H5EX_ENABLE_PARALLEL AND H5_HAVE_PARALLEL AND HDF5_ENABLE_PARALLEL) add_subdirectory (${PROJECT_SOURCE_DIR}/H5PAR) endif ()
Here I first check that examples configure wants parallel (H5EX_ENABLE_PARALLEL)
in the examples root CMakeLists.txt I checked that MPI is available (H5_HAVE_PARALLEL) and then I check to see if HDF5 was built with parallel (HDF5_ENABLE_PARALLEL)
Now it is clear. The variable H5_HAVE_PARALLEL is not in hdf5-targets.cmake, but I see that you defined it the root CMakeLists.txt:
if (MPI_C_FOUND)
set (H5_HAVE_PARALLEL 1)
...
endif()
and the fact that you check for H5_HAVE_PARALLEL in C/CMakeLists.txt makes sense because HDF5_ENABLE_PARALLEL is not sufficient, MPI must be present at runtime so that we can use HDF5 in parallel.
Once question remains: my hdf5-targets.cmake file has ${HDF5_PACKAGE_NAME}_ENABLE_PARALLEL}, not the hardcoded HDF5_ENABLE_PARALLEL, which you gave in your answer. So which one to use?
Indeed, on line 41 I have that. So I will use the more readable HDF5_ENABLE_PARALLEL in my own CMakeLists and hopefully HDF5 will not change this behaviour in the future.