If using the CTest script and configuration method to build HDF5, you can easily change the build options by either specifying the options on the command line or adding them to the options file, HDF5options.cmake.


Change options from the command line

As described on the Building HDF5 with CMake page, batch files for Windows and a shell script for Unix are provided for building HDF5. These files each contain a command that gets executed on the command line to build HDF5. They can be edited to add or change these options to the build command:

 

OptionPurpose
BUILD_GENERATORWhich CMake generator to use (required)
INSTALLDIR

Root folder where HDF5 is installed

When specifying INSTALLDIR you must run make install from the build/ directory to install HDF5. Please note that if HDF5 is built with SZIP and ZLIB, you must also run make install from the build/ZLIB-prefix/src/ZLIB-build/ and build/SZIP-prefix/src/SZIP-build/ directories in order to install the ZLIB and SZIP libraries with the HDF5 libraries.

CTEST_CONFIGURATION_TYPE 

(-C mode)

Used to specify the mode of building. To specify CTEST_CONFIGURATION_TYPE when building, simply change the -C option in the provided build scripts. For example:

ctest -S HDF5config.cmake,BUILD_GENERATOR=Unix -C RelWithDebInfo -VV -O hdf5.log

Following are the values that can be specified with the -C option:

Build Mode

Purpose
ReleaseBuilds the HDF5 libraries in "release" mode (DEFAULT)
RelWithDebInfoBuilds the HDF5 libraries in "release" mode and includes debug information to enable debugging of HDF5 applications
DebugBuilds the HDF5 libraries in "debug" mode
CTEST_SOURCE_NAMEName of source folder (eg. hdf5-1.10.N)
-VVBuilds in verbose mode. (-V is the default)

These are described at the top of the HDF5config.cmake file.

 


Change options with the options file

The HDF5options.cmake file is provided so that users can change build options without modifying the configuration file. It gets included by the configuration file and it overrides the settings in the configuration file.

Options can be set by using the following format:

set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DXXX:YY=ZZZZ")

The config/cmake/cacheinit.cmake file in the source code has a complete list of the options that can be used to build HDF5. (Section V in the release_docs/INSTALL_CMake.txt file in the source code lists the default CMake options used by HDF5.)

Several options are included in the HDF5options.cmake file, such as the options to turn off ZLIB or SZIP. Additional options can be added to this file, as needed. Common configure options that can be turned off or on in the HDF5options.cmake file are listed below.


 

Common CMake and configure Options

There are numerous CMake options available to users, many of which correspond directly to configure options. Below are a few important options that can be specified in the HDF5options.cmake file. The corresponding configure option is also shown:

OptionConfigureCMake
Build shared libraries--enable-sharedset(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DBUILD_SHARED_LIBS:BOOL=ON")
Build HDF5 C++ library--enable-cxxset(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=ON")
Build HDF5 Fortran 2003
library
--enable-fortranset(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=ON")
Disable ZLIB filter--with-zlibset(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_Z_LIB_SUPPORT:BOOL=OFF")
Use different ZLIB library--with-zlib

ZLIB_INCLUDE_DIR:PATH=<path to zlib includes directory>

ZLIB_LIBRARY:FILEPATH=<path to zlib/library file>

ZLIB_USE_EXTERNAL=1

Disable SZIP filter--with-szlibset(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_SUPPORT:BOOL=OFF")
set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_SZIP_ENCODING:BOOL=OFF")
Enable parallel build--enable-parallelset(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_PARALLEL:BOOL=ON")
set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DMPIEXEC_MAX_NUMPROCS:STRING=4")
Enable Threadsafe:--enable-threadsafeset(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_ENABLE_THREADSAFE:BOOL=ON")
Compile in Release Mode--enable-production-C Release (in build script) and set(CTEST_BUILD_CONFIGURATION "Release")
Compile in Debug Mode--enable-debug-C Debug (in build script) and set(CTEST_BUILD_CONFIGURATION "Debug")
Build HDF5 Java library--enable-java

set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_JAVA:BOOL=ON")

Also specify the location of Java in the JAVA_HOME environment variable.

 

Windows: How to build a standalone static executable

You need to build HDF5 with the /MT option. This can be done with a user macro in CMake. Go to this directory in the CMake source code:

CMake-hdf5-N.N.N/hdf5-N.N.N/config/cmake/UserMacros/

You will find the file Windows_MT.cmake in this directory, which contains information on what needs to be done. In general, you will need to either replace or edit the hdf5-N.N.N/UserMacros.cmake file so that the Windows_MT.cmake file can be found. Once this change has been made, then build HDF5 with CMake.