Improve the installation and usage docs for CMake (#5636)

* Workflow presets introduced in version CMake 3.25
This commit is contained in:
Allen Byrne
2025-07-28 09:14:35 -05:00
committed by GitHub
parent 4a12cfec19
commit f8aa8aa1ba
12 changed files with 496 additions and 187 deletions
+175 -92
View File
@@ -2,99 +2,187 @@
* Build and Test HDF5 Examples with CMake *
************************************************************************
Notes: This short instruction is written for users who want to quickly build
HDF5 Examples using the HDF5 binary package using the CMake tools.
Notes: This short instruction is written for users who want to quickly
exercise the installation of HDF5 by using the CMake tools to build
and test the HDF5 Examples. The following instructions will show
the default usage and then present common changes for non-default
installations.
More information about using CMake can be found at the Kitware
site, www.cmake.org.
CMake uses the command line; however, the visual CMake tool is
available for the configuration step. The steps are similar for
all of the operating systems supported by CMake.
Table of Contents
NOTES:
1. Using CMake for building and using HDF5 is under active
development. While we have attempted to provide error-free
files, please understand that development with CMake has not
been extensively tested outside of HDF. The CMake specific
files may change before the next release.
2. CMake for HDF5 development should be usable on any system
where CMake is supported. Please send us any comments on how
CMake support can be improved on any system.
Section I: Preconditions
Section II: Building HDF5 Examples with CMake
1. Using presets
2. Using CTestScript.cmake
3. Using Command Line CMake
Section III: Defaults in the CMakePresets.json file
Section IV: Defaults in the HDF5_Examples_options.cmake file
========================================================================
I. Preconditions
========================================================================
1. We suggest you obtain the latest CMake for windows from the Kitware
1. We suggest you obtain the latest CMake from the Kitware
web site. The HDF5 product requires a minimum CMake version
of 3.18.
of 3.18. If you are using VS2022, the minimum CMake version is 3.21.
CMakePresets.json, requires CMake 3.25 or higher.
2. You have installed the HDF5 library built with CMake, by executing
the HDF Install Utility (the *.msi file in the binary package for
Windows or the *.sh on Linux). If you are using a Windows platform,
you can obtain a pre-built Windows binary from The HDF Group's website
at www.hdfgroup.org.
Windows or the *.sh on Linux). You can obtain pre-built binaries
from The HDF Group's website at www.hdfgroup.org.
3. Set the environment variable HDF5_DIR to the installed location of
the config files for HDF5. On Windows:
HDF5_ROOT=C:/Program Files/HDF_Group/HDF5/z.y.x
3. Set the HDF5_ROOT CMake variable, -DHDF5_ROOT=<install_path>
or environment variable, set(ENV{HDF5_ROOT} "<install_path>")
to the installed location of HDF5.
On Windows:
HDF5_ROOT=C:/Program Files/HDF_Group/HDF5/z.y.x/
On unix:
HDF5_ROOT=<install root folder>/HDF_Group/HDF5/z.y.x/
If you are using shared libraries, you may need to add to the path
environment variable. Set the path environment variable to the
installed location of the library files for HDF5.
On Windows (*.dll):
PATH=%PATH%;C:/Program Files/HDF_Group/HDF5/z.y.x/bin
On unix (*.so):
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<install root folder>/HDF_Group/HDF5/z.y.x/lib
(Note there are no quote characters used on Windows and all platforms
use forward slashes)
4. Create separate source and build directories.
4. Use separate source and build directories.
(CMake commands are executed in the build directory)
========================================================================
II. Building HDF5 Examples with CMake
========================================================================
Go through these steps to build HDF5 applications with CMake.
1. Using presets
NOTE:
The CMakePresets.json files created by HDF Group are intended to be used with the Ninja build system,
which may need to be installed separately on some platforms.
1. Run CMake
2. Configure the cache settings
3. Build HDF5 Examples
4. Test HDF5 Examples.
Files in the HDF5 install/HDF5Examples directory:
CMakePresets.json
These steps are described in more detail below.
Default build process:
Create a directory to run the examples, i.e. \test_hdf5.
Copy the HDF5Examples folder to this directory.
Change into the HDF5Examples directory where CMakePresets.json exists.
Other options can be changed by creating a
CMakeUsersPresets.json file. (Advanced usage)
Available configurations presets can be displayed by executing:
cmake -S <path-to-source> --list-presets
1. Run CMake
Using individual command presets (where <compiler-type> is GNUC or MSVC or Clang):
cmake --preset ci-StdShar-<compiler-type>
cmake --build --preset ci-StdShar-<compiler-type>
ctest --preset ci-StdShar-<compiler-type>
cpack --preset ci-StdShar-<compiler-type>
Using the workflow preset to configure, build, and test the standard configuration:
execute "cmake --workflow --preset ci-StdShar-<compiler-type> --fresh"
where <compiler-type> is GNUC or MSVC or Clang
2. Using CTestScript.cmake
Files in the HDF5 install directory:
HDF5Examples folder
CTestScript.cmake
HDF5_Examples.cmake
HDF5_Examples_options.cmake
Default build process:
Create a directory to run the examples, i.e. \test_hdf5.
Copy HDF5Examples folder to this directory.
Copy CTestScript.cmake to this directory.
Copy HDF5_Examples.cmake to this directory.
Copy HDF5_Examples_options.cmake to this directory.
The default source folder is defined as "HDF5Examples". It can be changed
with the CTEST_SOURCE_NAME script option.
The default installation folder is defined for the platform.
It can be changed with the INSTALLDIR script option.
(Note: Windows has issues with spaces and paths -The path will need to
be set correctly.)
The default ctest configuration is defined as "Release". It can be changed
with the CTEST_CONFIGURATION_TYPE script option. Note that this must
be the same as the value used with the -C command line option.
On Windows, you can set the CTEST_VSVERS script option to either
64_VS2022 or 64_VS2019. Alternately, you can set the script
CTEST_CMAKE_GENERATOR option to "Visual Studio 16 2019" or "Visual Studio 17 2022",
and the CMAKE_GENERATOR_ARCHITECTURE script option to "x64".
The default build configuration is defined to build and use static libraries.
Shared libraries and other options can be changed by editing the
HDF5_Examples_options.cmake file.
If the defaults are okay, execute from this directory:
ctest -S HDF5_Examples.cmake -C Release -VV -O test.log
If the defaults need change, execute from this directory:
ctest -S HDF5_Examples.cmake,CTEST_SOURCE_NAME=MyExamples,INSTALLDIR=MyLocation -C Release -VV -O test.log
When executed, the ctest script will save the results to the log file, test.log, as
indicated by the ctest command. If you wish to see more build and test information,
add "-VV" to the ctest command. The output should show;
100% tests passed, 0 tests failed out of 206.
3. Using Command Line CMake
A. Visual Configuration
The visual CMake executable is named "cmake-gui.exe" on Windows and should be
available in your Start menu. For Linux, UNIX, and Mac users the
executable is named "cmake-gui" and can be found where CMake was
installed.
executable is named "cmake-gui" or the ncurses-based "ccmake" and can be found
where CMake was installed.
Specify the source and build directories. Make the build and source
directories different. For example on Windows, if the source is at
c:\MyHDFstuff\hdf5ex, then use c:\MyHDFstuff\hdf5ex\build or
c:\MyHDFstuff\build\hdf5ex for the build directory.
C:\MyHDFstuff\hdf5ex, then use C:\MyHDFstuff\hdf5ex\build or
C:\MyHDFstuff\build\hdf5ex for the build directory.
PREFERRED:
Users can perform the configuration step without using the visual
cmake-gui program. The following is an example command line
configuration step executed within the build directory:
Click the Configure button. If this is the first time you are
running cmake-gui in this directory, you will be prompted for the
generator you wish to use (for example on Windows, Visual Studio 15).
CMake will read in the CMakeLists.txt files from the source directory and
display options for the HDF5 Examples project. After the first configure you
can adjust the cache settings and/or specify locations of other programs.
Any conflicts or new values will be highlighted by the configure
process in red. Once you are happy with all the settings and there are no
more values in red, click the Generate button to produce the appropriate
build files.
On Windows, if you are using a Visual Studio generator, the solution and
project files will be created in the build folder.
On linux, if you are using the Unix Makefiles generator, the Makefiles will
be created in the build folder.
B. Alternative Command Line Configuration
Users can perform the configuration step without using the visual
cmake-gui program. The following is an example command line
configuration step executed within the build directory:
cmake -G "<generator>" [-D<options>] <sourcepath>
Where <generator> is
* Borland Makefiles
Where <generator> is (examples):
* MSYS Makefiles
* MinGW Makefiles
* NMake Makefiles
* Unix Makefiles
* Visual Studio 15
* Visual Studio 15 Win64
* Visual Studio 17
* Visual Studio 17 Win64
* Visual Studio 19
* Visual Studio 15 2017
* Visual Studio 15 2017 Win64
* Visual Studio 16 2019
* ... in addition VS2019 will need to set the "-A" option,
* ... [Win32, x64, ARM, ARM64]
* Visual Studio 17 2022
* ... in addition VS2022 will need to set the "-A" option,
* ... [Win32, x64, ARM, ARM64]
<options> is:
* H5EX_BUILD_TESTING:BOOL=ON
@@ -105,31 +193,11 @@ These steps are described in more detail below.
if the hdf5 library was built with a namespace (i.e. "hdf5::") add:
-D HDF5_NAMESPACE:STRING=hdf5::
2. Configure the cache settings
Example command line on Windows in c:\MyHDFstuff\hdf5ex\build directory:
2.1 Visual CMake users, click the Configure button. If this is the first time you are
running cmake-gui in this directory, you will be prompted for the
generator you wish to use (for example on Windows, Visual Studio 15).
CMake will read in the CMakeLists.txt files from the source directory and
display options for the HDF5 Examples project. After the first configure you
can adjust the cache settings and/or specify locations of other programs.
cmake -G "Visual Studio 17 2022" -DH5EX_BUILD_TESTING:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=ON ..
Any conflicts or new values will be highlighted by the configure
process in red. Once you are happy with all the settings and there are no
more values in red, click the Generate button to produce the appropriate
build files.
On Windows, if you are using a Visual Studio generator, the solution and
project files will be created in the build folder.
On linux, if you are using the Unix Makefiles generator, the Makefiles will
be created in the build folder.
2.2 Alternative command line example on Windows in c:\MyHDFstuff\hdf5ex\build directory:
cmake -G "Visual Studio 19" -DH5EX_BUILD_TESTING:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=ON ..
3. Build HDF5 examples
C. Build HDF5 examples
On Windows, you can build HDF5 examples using either the Visual Studio Environment
or the command line. The command line is normally used on linux, Unix, and Mac.
@@ -143,11 +211,11 @@ These steps are described in more detail below.
recommend choosing either Debug or Release on Windows. If you are
using the pre-built binaries from HDF, use Release.
3.1 If you wish to use the Visual Studio environment, open the solution
file in your build directory. Be sure to select either Debug or
Release and build the solution.
If you wish to use the Visual Studio environment, open the solution
file in your build directory. Be sure to select either Debug or
Release and build the solution.
4. Test HDF5 Examples.
D. Test HDF5 Examples.
To test the build, navigate to your build directory and execute:
@@ -157,6 +225,11 @@ These steps are described in more detail below.
recommend choosing either Debug or Release to match the build
step on Windows.
4. The files that support building with CMake are all of the files in the
config/cmake folder, the CMakeLists.txt files in each source folder.
CTestConfig.cmake is specific to the internal testing
4.1 Alternative command line example using the pkg-config shell scripts:
export HDF5_HOME=<root_path>/HDF_Group/HDF5/2.0.0
@@ -172,29 +245,39 @@ These steps are described in more detail below.
installation and needs.
========================================================================
III. Using HDF5 Libraries with Visual Studio 2008 (no longer supported)
III. Defaults in the CMakePresets.json file
========================================================================
1. Set up path for external libraries and headers
#### DEFAULT:
#### "generator": "Ninja"
#### "binaryDir": "${sourceParentDir}/build/${presetName}"
#### "name": "ci-StdShar"
#### "BUILD_SHARED_LIBS": "ON",
#### "USE_SHARED_LIBS": "ON"
#### "CMAKE_BUILD_TYPE": "RelWithDebInfo"
#### "H5EX_BUILD_FORTRAN": "ON"
#### "H5EX_BUILD_CXX": "ON"
#### "H5EX_BUILD_JAVA": "ON"
#### "HDF5_NAMESPACE": {"type": "STRING", "value": "hdf5::"},
#### "HDF5_PACKAGE_NAME": {"type": "STRING", "value": "hdf5"},
#### "H5EX_BUILD_TESTING": "ON"
Invoke Microsoft Visual Studio and go to "Tools" and select "Options",
find "Projects", and then "VC++ Directories".
1.1 If you are building on 64-bit Windows, find the "Platform" dropdown
and select "x64".
========================================================================
IV. Defaults in the HDF5_Examples_options.cmake file
========================================================================
1.2 Find the box "Show directories for", choose "Include files", add the
header path (i.e. c:\Program Files\HDF Group\HDF5\hdf5-1.8.x\include)
to the included directories.
1.3 Find the box "Show directories for", choose "Library files", add the
library path (i.e. c:\Program Files\HDF Group\HDF5\hdf5-1.8.x\lib)
to the library directories.
1.4 If using Fortran libraries, you will also need to setup the path
for the Intel Fortran compiler.
#### DEFAULT:
#### BUILD_SHARED_LIBS:BOOL=OFF
#### H5EX_BUILD_C:BOOL=ON
#### H5EX_BUILD_HL:BOOL=OFF
#### H5EX_BUILD_CXX:BOOL=OFF
#### H5EX_BUILD_FORTRAN:BOOL=OFF
#### H5EX_BUILD_JAVA:BOOL=OFF
#### H5EX_BUILD_FILTERS:BOOL=OFF
#### H5EX_BUILD_TESTING:BOOL=OFF
#### H5EX_ENABLE_PARALLEL:BOOL=OFF
************************************************************************