************************************************************************
* Build and Test HDF5 Examples with CMake                              *
************************************************************************

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.

                     Table of Contents

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 from the Kitware
      web site. The HDF5 product requires a minimum CMake version
      of 3.26.

   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 *.rpm or *.deb on Linux). You can obtain pre-built binaries
      from The HDF Group's website at www.hdfgroup.org.

   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. Use separate source and build directories.
      (CMake commands are executed in the build directory)

========================================================================
II. Building HDF5 Examples 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.

    Files in the HDF5 install/HDF5Examples directory:
       CMakePresets.json

    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

    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" 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.

      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 (examples):
            * MSYS Makefiles
            * MinGW Makefiles
            * NMake Makefiles
            * Unix Makefiles
            * 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:
            * H5EXAMPLE_BUILD_TESTING:BOOL=ON
            * BUILD_SHARED_LIBS:BOOL=[ON | OFF]
            * H5EXAMPLE_BUILD_FORTRAN:BOOL=[ON | OFF]
            * H5EXAMPLE_BUILD_JAVA:BOOL=[ON | OFF]

        if the hdf5 library was built with a namespace (i.e. "hdf5::") add:
            -D HDF5_NAMESPACE:STRING=hdf5::

      Example command line on Windows in c:\MyHDFstuff\hdf5ex\build directory:

           cmake -G "Visual Studio 17 2022" -DH5EXAMPLE_BUILD_TESTING:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=ON ..

    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.

      To build from the command line, navigate to your build directory and
      execute the following:

              cmake --build . --config {Debug | Release}

      NOTE: "--config {Debug | Release}" may be optional on your platform. We
            recommend choosing either Debug or Release on Windows. If you are
            using the pre-built binaries from HDF, use Release.

      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.

    D. Test HDF5 Examples.

      To test the build, navigate to your build directory and execute:

              ctest . -C {Debug | Release}

      NOTE: "-C {Debug | Release}" may be optional on your platform. We
            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
           cd <example_path_root>/HDF5Examples/
           sh ./test-pc.sh <example_path_root>/HDF5Examples/ <example_path_root>/H5EXAMPLE_BUILD/ .

   5. 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, and
      CTestConfig.cmake. CTestConfig.cmake is specific to the internal testing
      performed by The HDF Group. It should be altered for the user's
      installation and needs. The cacheinit.cmake file settings are used by
      The HDF Group for daily testing. It should be altered/ignored for the user's
      installation and needs.


========================================================================
III. Defaults in the CMakePresets.json file
========================================================================

####  DEFAULT:
####      "generator": "Ninja"
####      "binaryDir": "${sourceParentDir}/build/${presetName}"
####      "name": "ci-StdShar"
####        "BUILD_SHARED_LIBS": "ON",
####        "USE_SHARED_LIBS": "ON"
####        "CMAKE_BUILD_TYPE": "RelWithDebInfo"
####        "H5EXAMPLE_BUILD_FORTRAN": "ON"
####        "H5EXAMPLE_BUILD_CXX": "ON"
####        "H5EXAMPLE_BUILD_JAVA": "ON"
####        "HDF5_NAMESPACE": {"type": "STRING", "value": "hdf5::"},
####        "HDF5_PACKAGE_NAME": {"type": "STRING", "value": "hdf5"},
####        "H5EXAMPLE_BUILD_TESTING": "ON"


========================================================================
IV. Defaults in the HDF5_Examples_options.cmake file
========================================================================

####  DEFAULT:
####         BUILD_SHARED_LIBS:BOOL=OFF
####         H5EXAMPLE_BUILD_C:BOOL=ON
####         H5EXAMPLE_BUILD_HL:BOOL=OFF
####         H5EXAMPLE_BUILD_CXX:BOOL=OFF
####         H5EXAMPLE_BUILD_FORTRAN:BOOL=OFF
####         H5EXAMPLE_BUILD_JAVA:BOOL=OFF
####         H5EXAMPLE_BUILD_FILTERS:BOOL=OFF
####         H5EXAMPLE_BUILD_TESTING:BOOL=OFF
####         H5EXAMPLE_ENABLE_PARALLEL:BOOL=OFF


************************************************************************

Need further assistance, send email to help@hdfgroup.org

