FindHDF5¶
Finds Hierarchical Data Format (HDF5), a library for reading and writing self-describing array data:
find_package(HDF5 [<version>] [COMPONENTS <components>...] [...])
If the HDF5 library is built using its CMake-based build system, it will as
of HDF5 version 1.8.15 provide its own CMake Package Configuration file
(hdf5-config.cmake) for use with the find_package() command in
config mode. By default, this module searches for this file and, if found,
returns the results based on the found configuration.
If the upstream configuration file is not found, this module falls back to
module mode and invokes the HDF5 wrapper compiler typically installed
with the HDF5 library. Depending on the configuration, this wrapper
compiler is named either h5cc (serial) or h5pcc (parallel). If
found, the wrapper is queried with the -show argument to determine the
compiler and linker flags required for building an HDF5 client application.
Both serial and parallel versions of the HDF5 wrapper are considered. The
first directory containing either is used. If both versions are found in the
same directory, the serial version is preferred by default. To change this
behavior, set the variable HDF5_PREFER_PARALLEL to TRUE.
In addition to finding the include directories and libraries needed to compile an HDF5 application, this module also attempts to find additional tools provided by the HDF5 distribution, which can be useful for regression testing or development workflows.
Components¶
This module supports optional components, which can be specified with the
find_package() command:
find_package(HDF5 [COMPONENTS <components>...])
Supported components include:
CFinds the
HDF5C library (C bindings).CXXFinds the
HDF5C++ library (C++ bindings).FortranFinds the
HDF5Fortran library (Fortran bindings).HLThis component can be used in combination with other components to find the high-level (HL) HDF5 library variants for C, CXX, and/or Fortran, which provide high-level functions.
If no components are specified, then this module will by default search for the
C component.
Imported Targets¶
This module provides the following Imported Targets:
HDF5::HDF5Added in version 3.19.
Target encapsulating the usage requirements for all found HDF5 binding libraries (
HDF5_LIBRARIES), available if HDF5 and all required components are found.hdf5::hdf5Added in version 3.19.
Target encapsulating the usage requirements for the HDF5 C library, available if HDF5 library and its
Ccomponent are found.hdf5::hdf5_cppAdded in version 3.19.
Target encapsulating the usage requirements for the HDF5 C and C++ libraries, available if HDF5 library, and its
CandCXXcomponents are found.hdf5::hdf5_fortranAdded in version 3.19.
Target encapsulating the usage requirements for the HDF5 Fortran library, available if HDF5 library and its
Fortrancomponent are found.hdf5::hdf5_hlAdded in version 3.19.
Target encapsulating the usage requirements for the HDF5 high-level C library, available if HDF5 library and its
C, andHLcomponents are found.hdf5::hdf5_hl_cppAdded in version 3.19.
High-level C++ library.
Target encapsulating the usage requirements for the HDF5 high-level C and high-level C++ libraries, available if HDF5 library and its
C,CXX, andHLcomponents are found.hdf5::hdf5_hl_fortranAdded in version 3.19.
Target encapsulating the usage requirements for the HDF5 high-level Fortran library, available if HDF5 library and its
Fortran, andHLcomponents are found.hdf5::h5diffAdded in version 3.19.
Imported executable target encapsulating the usage requirements for the
h5diffexecutable, available ifh5diffis found.
Result Variables¶
This module defines the following variables:
HDF5_FOUNDBoolean indicating whether (the requested version of) HDF5 was found.
HDF5_VERSIONAdded in version 3.3.
The version of HDF5 library found.
HDF5_INCLUDE_DIRSInclude directories containing header files needed to use HDF5.
HDF5_DEFINITIONSRequired compiler definitions for using HDF5.
HDF5_LIBRARIESLibraries of all requested bindings needed to link against to use HDF5.
HDF5_HL_LIBRARIESRequired libraries for the HDF5 high-level API for all bindings, if the
HLcomponent is enabled.HDF5_IS_PARALLELBoolean indicating whether the HDF5 library has parallel IO support.
For each enabled language binding component, a corresponding
HDF5_<LANG>_LIBRARIES variable, and potentially
HDF5_<LANG>_DEFINITIONS, will be defined. If the HL component is
enabled, then HDF5_<LANG>_HL_LIBRARIES variables will also be defined:
HDF5_C_DEFINITIONSRequired compiler definitions for HDF5 C bindings.
HDF5_CXX_DEFINITIONSRequired compiler definitions for HDF5 C++ bindings.
HDF5_Fortran_DEFINITIONSRequired compiler definitions for HDF5 Fortran bindings.
HDF5_C_INCLUDE_DIRSRequired include directories for HDF5 C bindings.
HDF5_CXX_INCLUDE_DIRSRequired include directories for HDF5 C++ bindings.
HDF5_Fortran_INCLUDE_DIRSRequired include directories for HDF5 Fortran bindings.
HDF5_C_LIBRARIESRequired libraries for the HDF5 C bindings.
HDF5_CXX_LIBRARIESRequired libraries for the HDF5 C++ bindings.
HDF5_Fortran_LIBRARIESRequired libraries for the HDF5 Fortran bindings.
HDF5_C_HL_LIBRARIESRequired libraries for the high-level C bindings, if the
HLcomponent is enabled.HDF5_CXX_HL_LIBRARIESRequired libraries for the high-level C++ bindings, if the
HLcomponent is enabled.HDF5_Fortran_HL_LIBRARIESRequired libraries for the high-level Fortran bindings, if the
HLcomponent is enabled.
Cache Variables¶
The following cache variables may also be set:
HDF5_C_COMPILER_EXECUTABLEThe path to the HDF5 C wrapper compiler.
HDF5_CXX_COMPILER_EXECUTABLEThe path to the HDF5 C++ wrapper compiler.
HDF5_Fortran_COMPILER_EXECUTABLEThe path to the HDF5 Fortran wrapper compiler.
HDF5_C_COMPILER_EXECUTABLE_NO_INTERROGATEAdded in version 3.6.
The path to the primary C compiler which is also the HDF5 wrapper. This variable is used only in module mode.
HDF5_CXX_COMPILER_EXECUTABLE_NO_INTERROGATEAdded in version 3.6.
The path to the primary C++ compiler which is also the HDF5 wrapper. This variable is used only in module mode.
HDF5_Fortran_COMPILER_EXECUTABLE_NO_INTERROGATEAdded in version 3.6.
The path to the primary Fortran compiler which is also the HDF5 wrapper. This variable is used only in module mode.
HDF5_DIFF_EXECUTABLEThe path to the HDF5 dataset comparison tool (
h5diff).
Hints¶
The following variables can be set before calling the find_package(HDF5)
to guide the search for HDF5 library:
HDF5_PREFER_PARALLELAdded in version 3.4.
Set this to boolean true to prefer parallel HDF5 (by default, serial is preferred). This variable is used only in module mode.
HDF5_FIND_DEBUGAdded in version 3.9.
Set this to boolean true to get extra debugging output by this module.
HDF5_NO_FIND_PACKAGE_CONFIG_FILEAdded in version 3.8.
Set this to boolean true to skip finding and using CMake package configuration file (
hdf5-config.cmake).HDF5_USE_STATIC_LIBRARIESSet this to boolean value to determine whether or not to prefer a static link to a dynamic link for
HDF5and all of its dependencies.Added in version 3.10: Support for
HDF5_USE_STATIC_LIBRARIESon Windows.
Examples¶
Examples: Finding HDF5¶
Finding HDF5:
find_package(HDF5)
Specifying a minimum required version of HDF5 to find:
find_package(HDF5 1.8.15)
Finding HDF5 and making it required (if HDF5 is not found, processing stops with an error message):
find_package(HDF5 1.8.15 REQUIRED)
Searching for static HDF5 libraries:
set(HDF5_USE_STATIC_LIBRARIES TRUE)
find_package(HDF5)
Specifying components to find high-level C and C++ functions:
find_package(HDF5 COMPONENTS C CXX HL)
Examples: Using HDF5¶
Finding HDF5 and linking it to a project target:
find_package(HDF5)
target_link_libraries(project_target PRIVATE HDF5::HDF5)
Using Fortran HDF5 and HDF5-HL functions:
find_package(HDF5 COMPONENTS Fortran HL)
target_link_libraries(project_target PRIVATE HDF5::HDF5)