This file provides instructions for building HDF5 with support for various data filters, including zlib and libaec.
- CMake options
- Using system-installed libraries
- Using libraries built with CMake FetchContent
- Troubleshooting
HDF5 currently has built-in support for zlib, zlib-ng and libaec (szip), as well as support for a collection of dynamically-loaded filter libraries from the HDF5 filter plugins repository, which are controlled by the following CMake options:
HDF5_ENABLE_ZLIB_SUPPORT(ON/OFFDefault:OFF) - Enable zlib supportHDF5_ENABLE_SZIP_SUPPORT(ON/OFFDefault:OFF) - Enable libaec (szip) supportHDF5_USE_ZLIB_NG(ON/OFFDefault:OFF) - Enable zlib-ng supportHDF5_ENABLE_PLUGIN_SUPPORT(ON/OFFDefault:OFF) - Enable support for plugins from the HDF5 filter plugins repositoryHDF5_ALLOW_EXTERNAL_SUPPORT(NO/GIT/TGZDefault:NO) - Specify whether support for libraries from external sources should be enabled (see Using libraries built with CMake FetchContent)TGZPATH(<path>Default: top level of HDF5 source directory) - WhenHDF5_ALLOW_EXTERNAL_SUPPORTisTGZand a filter's_USE_LOCALCONTENTvariable isON(see below), specifies the directory to look in for a library's source code compressed file.
By default, setting HDF5_ENABLE_ZLIB_SUPPORT to ON will enable support for zlib. Setting the additional option HDF5_USE_ZLIB_NG to ON will cause HDF5 to instead use zlib-ng in place of zlib.
Additional CMake options for controlling how specific filters are found/used include the following:
HDF5_USE_ZLIB_STATIC(ON/OFFDefault:OFF) - Prefer locating and using static zlib libraries (if available) instead of shared librariesZLIB_USE_EXTERNAL(ON/OFFDefault:OFF) - IfONandHDF5_ALLOW_EXTERNAL_SUPPORTisGITorTGZ, instructs HDF5 to build zlib from an external source and use that while building HDF5 itself. IfONandHDF5_ALLOW_EXTERNAL_SUPPORTisNO, causes a configuration error.ZLIB_USE_LOCALCONTENT(ON/OFFDefault:OFF) - IfON,HDF5_ALLOW_EXTERNAL_SUPPORTisTGZandZLIB_USE_EXTERNALisON, instructs HDF5 to build zlib from a compressed source file on the filesystem, which is pointed to by the path formed from combiningTGZPATHandZLIB_TGZ_NAME, and use that while building HDF5 itself. IfONandHDF5_ALLOW_EXTERNAL_SUPPORTisNOorGIT, causes a configuration error.HDF5_MODULE_MODE_ZLIB(ON/OFFDefault:ON) - IfON, locates zlib using CMake's find_package() Module mode search, otherwise uses a Config mode search. In most cases this option should be left to the default value, but may need to be modified for specific zlib installations.ZLIB_GIT_URL(<url>Default: zlib) - Specifies the git URL to retrieve zlib from whenHDF5_ALLOW_EXTERNAL_SUPPORTisGITandZLIB_USE_EXTERNALisON(e.g., when building zlib with CMake's FetchContent)ZLIB_GIT_TAG/ZLIB_GIT_BRANCH(<git tag>Default:v<zlib_version>) - Specifies the git tag, commit hash or branch name to use for retrieving zlib whenHDF5_ALLOW_EXTERNAL_SUPPORTisGITandZLIB_USE_EXTERNALisON(e.g., when building zlib with CMake's FetchContent).ZLIB_GIT_BRANCHis deprecated in favor ofZLIB_GIT_TAG.ZLIB_TGZ_NAME(<filename>Default:zlib-<zlib_version>.tar.gz) - Specifies the base filename of a compressed file containing the zlib source code which will be used whenHDF5_ALLOW_EXTERNAL_SUPPORTisTGZandZLIB_USE_EXTERNALisON. Combined with eitherTGZPATHorZLIB_TGZ_ORIGPATH, depending on the value ofZLIB_USE_LOCALCONTENT, to form a full path to the compressed file.ZLIB_TGZ_ORIGPATH(<url>Default:https://github.com/madler/zlib/releases/download/v<zlib_version>) - Specifies the URL to retrieve a compressed file containing the zlib source code from whenHDF5_ALLOW_EXTERNAL_SUPPORTisTGZ,ZLIB_USE_EXTERNALisONandZLIB_USE_LOCALCONTENTisOFF. Combined withZLIB_TGZ_NAMEto form a full URL for the download.ZLIB_PACKAGE_NAME(<string>Default:zlib) - The package name to use when locating zlib libraries with CMake's find_package(). Usually should be left to the default value but may need to be modified in rare circumstances.
Note
The HDF5_USE_ZLIB_STATIC, ZLIB_USE_EXTERNAL and ZLIB_USE_LOCALCONTENT options also apply to zlib-ng when HDF5_USE_ZLIB_NG is set to ON.
ZLIBNG_GIT_URL(<url>Default: zlib-ng) - Specifies the git URL to retrieve zlib-ng from whenHDF5_ALLOW_EXTERNAL_SUPPORTisGIT,ZLIB_USE_EXTERNALisONandHDF5_USE_ZLIB_NGisON(e.g., when building zlib-ng with CMake's FetchContent)ZLIBNG_GIT_TAG/ZLIBNG_GIT_BRANCH(<git tag>Default:<zlibng_version>) - Specifies the git tag, commit hash or branch name to use for retrieving zlib-ng whenHDF5_ALLOW_EXTERNAL_SUPPORTisGIT,ZLIB_USE_EXTERNALisONandHDF5_USE_ZLIB_NGisON(e.g., when building zlib-ng with CMake's FetchContent).ZLIBNG_GIT_BRANCHis deprecated in favor ofZLIBNG_GIT_TAG.ZLIBNG_TGZ_NAME(<filename>Default:<zlibng_version>.tar.gz) - Specifies the base filename of a compressed file containing the zlib-ng source code which will be used whenHDF5_ALLOW_EXTERNAL_SUPPORTisTGZ,ZLIB_USE_EXTERNALisONandHDF5_USE_ZLIB_NGisON. Combined with eitherTGZPATHorZLIBNG_TGZ_ORIGPATH, depending on the value ofZLIB_USE_LOCALCONTENT, to form a full path to the compressed file.ZLIBNG_TGZ_ORIGPATH(<url>Default:https://github.com/zlib-ng/zlib-ng/archive/refs/tags) - Specifies the URL to retrieve a compressed file containing the zlib-ng source code from whenHDF5_ALLOW_EXTERNAL_SUPPORTisTGZ,ZLIB_USE_EXTERNALisON,ZLIB_USE_LOCALCONTENTisOFFandHDF5_USE_ZLIB_NGisON. Combined withZLIBNG_TGZ_NAMEto form a full URL for the download.ZLIBNG_PACKAGE_NAME(<string>Default:ZLIBNG) - The package name to use when locating zlib-ng libraries with CMake's find_package(). Usually should be left to the default value but may need to be modified in rare circumstances.
HDF5_USE_LIBAEC_STATIC(ON/OFFDefault:OFF) - Prefer locating and using static libaec libraries (if available) instead of shared librariesSZIP_USE_EXTERNAL(ON/OFFDefault:OFF) - IfONandHDF5_ALLOW_EXTERNAL_SUPPORTisGITorTGZ, instructs HDF5 to build libaec from an external source and use that while building HDF5 itself. IfONandHDF5_ALLOW_EXTERNAL_SUPPORTisNO, causes a configuration error.LIBAEC_USE_LOCALCONTENT(ON/OFFDefault:OFF) - IfON,HDF5_ALLOW_EXTERNAL_SUPPORTisTGZandSZIP_USE_EXTERNALisON, instructs HDF5 to build libaec from a compressed source file on the filesystem, which is pointed to by the path formed from combiningTGZPATHandLIBAEC_TGZ_NAME, and use that while building HDF5 itself. IfONandHDF5_ALLOW_EXTERNAL_SUPPORTisNOorGIT, causes a configuration error.LIBAEC_GIT_URL(<url>Default: libaec) - Specifies the git URL to retrieve libaec from whenHDF5_ALLOW_EXTERNAL_SUPPORTisGITandSZIP_USE_EXTERNALisON(e.g., when building libaec with CMake's FetchContent)LIBAEC_GIT_TAG/LIBAEC_GIT_BRANCH(<git tag>Default:v<libaec_version>) - Specifies the git tag, commit hash or branch name to use for retrieving libaec whenHDF5_ALLOW_EXTERNAL_SUPPORTisGITandSZIP_USE_EXTERNALisON(e.g., when building libaec with CMake's FetchContent).LIBAEC_GIT_BRANCHis deprecated in favor ofLIBAEC_GIT_TAG.LIBAEC_TGZ_NAME(<filename>Default:libaec-<libaec_version>.tar.gz) - Specifies the base filename of a compressed file containing the libaec source code which will be used whenHDF5_ALLOW_EXTERNAL_SUPPORTisTGZandSZIP_USE_EXTERNALisON. Combined with eitherTGZPATHorLIBAEC_TGZ_ORIGPATH, depending on the value ofLIBAEC_USE_LOCALCONTENT, to form a full path to the compressed file.LIBAEC_TGZ_ORIGPATH(<url>Default:https://github.com/MathisRosenhauer/libaec/releases/download/v<libaec_version>) - Specifies the URL to retrieve a compressed file containing the libaec source code from whenHDF5_ALLOW_EXTERNAL_SUPPORTisTGZ,SZIP_USE_EXTERNALisONandLIBAEC_USE_LOCALCONTENTisOFF. Combined withLIBAEC_TGZ_NAMEto form a full URL for the download.LIBAEC_PACKAGE_NAME(<string>Default:libaec) - The package name to use when locating libaec libraries with CMake's find_package(). Usually should be left to the default value but may need to be modified in rare circumstances.HDF5_ENABLE_SZIP_ENCODING(ON/OFFDefault:ON) - Specifies whether encoding should be enabled for the HDF5 szip filter. Deprecated option that is no longer used.
PLUGIN_USE_EXTERNAL(ON/OFFDefault:OFF) - IfONandHDF5_ALLOW_EXTERNAL_SUPPORTisGITorTGZ, instructs HDF5 to build several dynamically-loaded data filter plugins from the hdf5_plugins repository while building HDF5 itself. IfONandHDF5_ALLOW_EXTERNAL_SUPPORTisNO, causes a configuration error.PLUGIN_USE_LOCALCONTENT(ON/OFFDefault:OFF) - IfON,HDF5_ALLOW_EXTERNAL_SUPPORTisTGZandPLUGIN_USE_EXTERNALisON, instructs HDF5 to build several dynamically-loaded data filter plugins from a compressed source file on the filesystem, which is pointed to by the path formed from combiningTGZPATHandHDF5_FILTER_PLUGINS_TGZ_NAME/PLUGIN_TGZ_NAME, and use that while building HDF5 itself. IfONandHDF5_ALLOW_EXTERNAL_SUPPORTisNOorGIT, causes a configuration error.HDF5_FILTER_PLUGINS_GIT_URL/PLUGIN_GIT_URL(<url>Default: hdf5_plugins) - Specifies the git URL to retrieve HDF5 filter plugins from whenHDF5_ALLOW_EXTERNAL_SUPPORTisGITandPLUGIN_USE_EXTERNALisON(e.g., when building HDF5 filter plugins with CMake's FetchContent).PLUGIN_GIT_URLis deprecated in favor ofHDF5_FILTER_PLUGINS_GIT_URL.HDF5_FILTER_PLUGINS_GIT_TAG/PLUGIN_GIT_BRANCH(<git tag>Default:master) - Specifies the git tag, commit hash or branch name to use for retrieving HDF5 filter plugins whenHDF5_ALLOW_EXTERNAL_SUPPORTisGITandPLUGIN_USE_EXTERNALisON(e.g., when building HDF5 filter plugins with CMake's FetchContent).PLUGIN_GIT_BRANCHis deprecated in favor ofHDF5_FILTER_PLUGINS_GIT_TAG.HDF5_FILTER_PLUGINS_TGZ_NAME/PLUGIN_TGZ_NAME(<filename>Default:hdf5_plugins-master.tar.gz) - Specifies the base filename of a compressed file containing the HDF5 filter plugins source code which will be used whenHDF5_ALLOW_EXTERNAL_SUPPORTisTGZandPLUGIN_USE_EXTERNALisON. Combined with eitherTGZPATHorHDF5_FILTER_PLUGINS_TGZ_ORIGPATH/PLUGIN_TGZ_ORIGPATH, depending on the value ofPLUGIN_USE_LOCALCONTENT, to form a full path to the compressed file.PLUGIN_TGZ_NAMEis deprecated in favor ofHDF5_FILTER_PLUGINS_TGZ_NAME.HDF5_FILTER_PLUGINS_TGZ_ORIGPATH/PLUGIN_TGZ_ORIGPATH(<url>Default:https://github.com/HDFGroup/hdf5_plugins/releases/download/snapshot) - Specifies the URL to retrieve a compressed file containing the HDF5 filter plugins source code from whenHDF5_ALLOW_EXTERNAL_SUPPORTisTGZ,PLUGIN_USE_EXTERNALisONandPLUGIN_USE_LOCALCONTENTisOFF. Combined withHDF5_FILTER_PLUGINS_TGZ_NAME/PLUGIN_TGZ_NAMEto form a full URL for the download.PLUGIN_TGZ_ORIGPATHis deprecated in favor ofHDF5_FILTER_PLUGINS_TGZ_ORIGPATH.HDF5_FILTER_PLUGINS_PACKAGE_NAME/PLUGIN_PACKAGE_NAME(<string>Default:h5pl) - The package name to use when locating HDF5 filter plugins libraries with CMake's find_package(). Usually should be left to the default value but may need to be modified in rare circumstances.PLUGIN_PACKAGE_NAMEis deprecated in favor ofHDF5_FILTER_PLUGINS_PACKAGE_NAME.
To build HDF5 with data filter support using libraries that are installed on the system, setting the relevant HDF5_ENABLE_XXX_SUPPORT CMake options to ON should be enough in most cases. However, CMake can be instructed to look for specific libraries if desired or if the needed libraries are installed to directories that aren't in CMake's default search paths:
- For zlib, set the CMake variable
ZLIB_ROOTto the top level directory of a zlib installation - For zlib-ng, set the CMake variable
ZLIBNG_ROOTto the top level directory of a zlib installation - For libaec (szip), set the CMake variable
SZIP_ROOTorlibaec_ROOTto the top level directory of a libaec installation
Example: Configure HDF5 with zlib and libaec support from system libraries
cmake -DHDF5_ENABLE_ZLIB_SUPPORT=ON -DHDF5_ENABLE_SZIP_SUPPORT=ON <hdf5_source_dir>Example: Configure HDF5 with zlib installed to a non-system directory
cmake -DHDF5_ENABLE_ZLIB_SUPPORT=ON -DZLIB_ROOT=/path/to/my/zlib/installation <hdf5_source_dir>Example: Configure HDF5 with zlib-ng static libraries installed to a non-system directory
cmake -DHDF5_ENABLE_ZLIB_SUPPORT=ON -DHDF5_USE_ZLIB_NG=ON -DHDF5_USE_ZLIB_STATIC=ON -DZLIBNG_ROOT=/path/to/my/zlib-ng/installation <hdf5_source_dir>Warning
HDF5 does not currently namespace libraries that are built using CMake's FetchContent functionality. Use caution when installing HDF5 to a system directory if any libraries are built this way, as there is risk of overwriting pre-existing libraries on the system. For this reason, it is recommended to install filter libraries on the system and allow HDF5 to find them at build time instead. This method is only provided as a convenience for building HDF5 binaries and for testing of HDF5.
When building HDF5, one may choose to build the libraries for data filters alongside HDF5 by using CMake's FetchContent functionality.
This will either download the source code for libraries or use compressed source code files from the filesystem and add the source code to the HDF5 build and installation processes. To set up this method, several CMake variables need to be set when configuring HDF5. First, the CMake variable HDF5_ALLOW_EXTERNAL_SUPPORT must be set to the value GIT or TGZ. The value GIT will instruct the HDF5 build process to retrieve the source code for libraries from git URLs, whereas the value TGZ will instruct the build process to retrieve the source code for libraries from compressed files from either a web URL or a path on the filesystem.
Next, external support for the desired data filters needs to be configured into HDF5. This simply involves setting the relevant HDF5_ENABLE_XXX_SUPPORT and XXX_USE_EXTERNAL CMake options to ON.
Finally, any CMake options for how the source code should be retrieved and built must be set. The default values set for most of these options can be found in CacheURLs.cmake and can be changed by setting values for the CMake variables listed there. Note that the HDF5_USE_XXX_STATIC options affect which type of library, shared or static, is built when building external libraries.
Tip
CMake options for a library can generally be passed through when building them with FetchContent by defining those options when configuring HDF5 (e.g., add -DZLIB_BUILD_TESTING=OFF to the list of HDF5 configuration options), but be aware that HDF5 may override the values for some of these variables.
When the HDF5_ALLOW_EXTERNAL_SUPPORT CMake option is specified as GIT, all filter libraries will be downloaded from git URLs using a specified git tag, commit hash or branch name. For example, using the default values for libaec will cause CMake to download the libaec source from https://github.com/MathisRosenhauer/libaec.git (LIBAEC_GIT_URL) using the git tag v1.1.6 (LIBAEC_GIT_TAG as of the time of writing). Each filter's _GIT_URL and _GIT_TAG CMake variables may have values specified for them to change where the source code is downloaded from.
Example: Configure HDF5 with zlib-ng from system libraries and libaec (szip) from the default git repository
cmake -DHDF5_ALLOW_EXTERNAL_SUPPORT=GIT -DHDF5_ENABLE_ZLIB_SUPPORT=ON -DHDF5_USE_ZLIB_NG=ON -DHDF5_ENABLE_SZIP_SUPPORT=ON -DSZIP_USE_EXTERNAL=ON <hdf5_source_dir>Example: Configure HDF5 with zlib-ng, libaec and the HDF5 filter plugins from the default git repositories
cmake -DHDF5_ALLOW_EXTERNAL_SUPPORT=GIT -DHDF5_ENABLE_ZLIB_SUPPORT=ON -DHDF5_USE_ZLIB_NG=ON -DZLIB_USE_EXTERNAL=ON -DHDF5_ENABLE_SZIP_SUPPORT=ON -DSZIP_USE_EXTERNAL=ON -DHDF5_ENABLE_PLUGIN_SUPPORT=ON -DPLUGIN_USE_EXTERNAL=ON <hdf5_source_dir>Example: Configure HDF5 with libaec from a custom git repository
cmake -DHDF5_ALLOW_EXTERNAL_SUPPORT=GIT -DHDF5_ENABLE_SZIP_SUPPORT=ON -DSZIP_USE_EXTERNAL=ON -DLIBAEC_GIT_URL="https://github.com/user/libaec.git" -DLIBAEC_GIT_TAG="my_libaec_tag" <hdf5_source_dir>When the HDF5_ALLOW_EXTERNAL_SUPPORT CMake option is specified as TGZ, the way in which filter libraries are retrieved depends on the value for that filter's _USE_LOCALCONTENT CMake option. For each filter that has its _USE_LOCALCONTENT variable set to OFF, CMake will download a compressed file with the relevant library's source code from a URL formed by combining the filter's _TGZ_ORIGPATH and _TGZ_NAME CMake variables. For example, the default values of LIBAEC_TGZ_ORIGPATH and LIBAEC_TGZ_NAME are https://github.com/MathisRosenhauer/libaec/releases/download/v<libaec_version> and libaec-<libaec_version>.tar.gz, respectively. As of the time of writing, the current default version of libaec is 1.1.6, resulting in a URL of https://github.com/MathisRosenhauer/libaec/releases/download/v1.1.6/libaec-1.1.6.tar.gz. CMake will download this file, uncompress it and use the contents as source code when building the library alongside HDF5. Each filter's _TGZ_ORIGPATH and _TGZ_NAME CMake variables may have values specified for them to change where the file is downloaded from.
For each filter that has its _USE_LOCALCONTENT variable set to ON, CMake will search the directory specified by TGZPATH for the compressed file with that filter's library source code according to the default names, which can be changed by setting a filter's _TGZ_NAME variable. For example, to locate compressed files with zlib and libaec libraries with the names zlib.tar.gz and libaec.tar.gz in the directory /home/user/filters, specify the following CMake options when configuring HDF5:
-DTGZPATH="/home/user/filters"-DZLIB_TGZ_NAME="zlib.tar.gz"-DLIBAEC_TGZ_NAME="libaec.tar.gz"
CMake will combine TGZPATH with each of ZLIB_TGZ_NAME and LIBAEC_TGZ_NAME to form full paths to each file.
Example: Configure HDF5 with zlib-ng and libaec from downloaded tar.gz files with the default names
cmake -DHDF5_ALLOW_EXTERNAL_SUPPORT=TGZ -DHDF5_ENABLE_ZLIB_SUPPORT=ON -DHDF5_USE_ZLIB_NG=ON -DZLIB_USE_EXTERNAL=ON -DHDF5_ENABLE_SZIP_SUPPORT=ON -DSZIP_USE_EXTERNAL=ON <hdf5_source_dir>Example: Configure HDF5 with zlib-ng and libaec from tar.gz files on the system with custom names
cmake -DHDF5_ALLOW_EXTERNAL_SUPPORT=TGZ -DTGZPATH="/path/to/files" -DHDF5_ENABLE_ZLIB_SUPPORT=ON -DHDF5_USE_ZLIB_NG=ON -DZLIB_USE_EXTERNAL=ON -DZLIB_USE_LOCALCONTENT=ON -DZLIBNG_TGZ_NAME="zlib-ng-2.3.3.tar.gz" -DHDF5_ENABLE_SZIP_SUPPORT=ON -DSZIP_USE_EXTERNAL=ON -DLIBAEC_USE_LOCALCONTENT=ON -DLIBAEC_TGZ_NAME="libaec-1.1.6.tar.gz" <hdf5_source_dir>If the HDF5 build process does not properly locate libraries for a data filter on the system, debugging of the process can be enabled when configuring HDF5 by passing the option -DCMAKE_FIND_DEBUG_MODE=ON. This option is intended for advanced users, but will give information about what paths on the system are or are not being searched.