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
- Change options with the options file
- Common CMake and configure options
- Windows: How to build a standalone static executable
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:
Option | Purpose | ||||||||
---|---|---|---|---|---|---|---|---|---|
BUILD_GENERATOR | Which CMake generator to use (required) | ||||||||
INSTALLDIR | Root folder where HDF5 is installed When specifying INSTALLDIR you must run | ||||||||
CTEST_CONFIGURATION_TYPE ( | Used to specify the mode of building. To specify CTEST_CONFIGURATION_TYPE when building, simply change the
Following are the values that can be specified with the
| ||||||||
CTEST_SOURCE_NAME | Name of source folder (eg. hdf5-1.10.N) | ||||||||
-VV | Builds 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:
Option | Configure | CMake |
---|---|---|
Build shared libraries | --enable-shared | set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DBUILD_SHARED_LIBS:BOOL=ON") |
Build HDF5 C++ library | --enable-cxx | set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_CPP_LIB:BOOL=ON") |
Build HDF5 Fortran 2003 library | --enable-fortran | set(ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF5_BUILD_FORTRAN:BOOL=ON") |
Disable ZLIB filter | --with-zlib | set(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-szlib | set(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-parallel | set(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-threadsafe | set(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.
- Edit the root
UserMacros.cmake
file in the HDF5 source code.
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 fileWindows_MT.cmake
, which contains information on what needs to be done.
In general, you will need to either replace or edit thehdf5-N.N.N/UserMacros.cmake
file so that theWindows_MT.cmake
file can be found.
(On Windows, copy the entire file toUserMacros.cmake
.) - Edit
HDF5Options.cmake
in theCMake-hdf5-N.N.N
directory and add the BUILD_STATIC_CRT_LIBS option.
set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DBUILD_STATIC_CRT_LIBS:BOOL=ON")
Once these changes have been made, then build HDF5 with CMake.
--- Last Modified: September 20, 2019 | 01:52 PM