From 1089ee12a6646014e374a88044f6a93d211cd08e Mon Sep 17 00:00:00 2001 From: Chuck Atkins Date: Mon, 18 May 2026 15:48:23 -0400 Subject: [PATCH] Fix INSTALL_CMAKE_DIR for GNU_DIRS and enable by default on Linux. The previous `lib/cmake/hdf5-config.cmake` isn't in CMake's find_package search path since CMake expects that to be a common path with each package having it's own subdirectory. This changes it to `lib/cmake/hdf5/hdf5-config.cmake` so the config is now found when the install prefix is in `CMAKE_PREFIX_PATH`. This also sets `HDF5_USE_GNU_DIRS=ON` by default for non-Windows builds. Fixes #6137 --- HDF5Examples/config/HDFMacros.cmake | 12 ++++++++++-- config/HDFMacros.cmake | 13 +++++++++++-- docs/INSTALL_CMake_options.md | 6 +++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/HDF5Examples/config/HDFMacros.cmake b/HDF5Examples/config/HDFMacros.cmake index 07a79d6df81a..4125800988c8 100644 --- a/HDF5Examples/config/HDFMacros.cmake +++ b/HDF5Examples/config/HDFMacros.cmake @@ -90,8 +90,14 @@ macro (HDFTEST_COPY_FILE src dest target) endmacro () macro (HDF_DIR_PATHS package_prefix) - option (H5EXAMPLE_USE_GNU_DIRS "ON to use GNU Coding Standard install directory variables, OFF to use historical settings" OFF) + set(_H5EXAMPLE_USE_GNU_DIRS_DEFAULT ON) + if (CMAKE_SYSTEM_NAME MATCHES "^Windows") + set(_H5EXAMPLE_USE_GNU_DIRS_DEFAULT OFF) + endif() + option (H5EXAMPLE_USE_GNU_DIRS "ON to use GNU Coding Standard install directory variables, OFF to use historical settings" ${_H5EXAMPLE_USE_GNU_DIRS_DEFAULT}) mark_as_advanced (H5EXAMPLE_USE_GNU_DIRS) + unset (_H5EXAMPLE_USE_GNU_DIRS_DEFAULT) + if (H5EXAMPLE_USE_GNU_DIRS) include(GNUInstallDirs) if (NOT ${package_prefix}_INSTALL_BIN_DIR) @@ -113,7 +119,9 @@ macro (HDF_DIR_PATHS package_prefix) set (${package_prefix}_INSTALL_DATA_DIR ${CMAKE_INSTALL_DATADIR}) endif () if (NOT ${package_prefix}_INSTALL_CMAKE_DIR) - set (${package_prefix}_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake) + string(TOLOWER "${package_prefix}" package_prefix_lower) + set (${package_prefix}_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${package_prefix_lower}) + unset(package_prefix_lower) endif () if (NOT ${package_prefix}_INSTALL_DOC_DIR) set (${package_prefix}_INSTALL_DOC_DIR ${CMAKE_INSTALL_DOCDIR}) diff --git a/config/HDFMacros.cmake b/config/HDFMacros.cmake index c7fa701746d6..7ae4a31869d5 100644 --- a/config/HDFMacros.cmake +++ b/config/HDFMacros.cmake @@ -426,7 +426,14 @@ endmacro () # HDF_DIR_PATHS: Set up install directory variables and RPATHs. macro (HDF_DIR_PATHS package_prefix) - option (HDF5_USE_GNU_DIRS "ON to use GNU Coding Standard install directory variables, OFF to use historical settings" OFF) + set(_HDF5_USE_GNU_DIRS_DEFAULT ON) + if (CMAKE_SYSTEM_NAME MATCHES "^Windows") + set(_HDF5_USE_GNU_DIRS_DEFAULT OFF) + endif() + option (HDF5_USE_GNU_DIRS "ON to use GNU Coding Standard install directory variables, OFF to use historical settings" ${_HDF5_USE_GNU_DIRS_DEFAULT}) + mark_as_advanced (HDF5_USE_GNU_DIRS) + unset (_HDF5_USE_GNU_DIRS_DEFAULT) + if (HDF5_USE_GNU_DIRS) include(GNUInstallDirs) if (NOT ${package_prefix}_INSTALL_BIN_DIR) @@ -451,7 +458,9 @@ macro (HDF_DIR_PATHS package_prefix) set (${package_prefix}_INSTALL_DATA_DIR ${CMAKE_INSTALL_DATADIR}) endif () if (NOT ${package_prefix}_INSTALL_CMAKE_DIR) - set (${package_prefix}_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake) + string(TOLOWER "${package_prefix}" package_prefix_lower) + set (${package_prefix}_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${package_prefix_lower}) + unset(package_prefix_lower) endif () if (NOT ${package_prefix}_INSTALL_DOC_DIR) set (${package_prefix}_INSTALL_DOC_DIR ${CMAKE_INSTALL_DOCDIR}) diff --git a/docs/INSTALL_CMake_options.md b/docs/INSTALL_CMake_options.md index b4af17a38ba9..ba4c38c6b453 100644 --- a/docs/INSTALL_CMake_options.md +++ b/docs/INSTALL_CMake_options.md @@ -88,13 +88,13 @@ These options control how HDF5 gets installed. Options dealing with paths are ge | CMake option | Type | Default | Description | |:-------------|:-----|:--------|:------------| -| `HDF5_USE_GNU_DIRS` | `BOOL` | `OFF` | If `ON`, uses the GNU Coding Standard CMake install directory variables when setting up for installing the HDF5 library. See [GNUInstallDirs](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html) for more information. | +| `HDF5_USE_GNU_DIRS` | `BOOL` | Varies by platform | If `ON`, uses the GNU Coding Standard CMake install directory variables when setting up for installing the HDF5 library. See [GNUInstallDirs](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html) for more information. | | `HDF5_INSTALL_BIN_DIR` | `STRING` | `bin` | Specifies the directory to install executables in. | | `HDF5_INSTALL_LIB_DIR` | `STRING` | `lib` | Specifies the directory to install libraries in. | | `HDF5_INSTALL_JNI_LIB_DIR` | `STRING` | `lib` | Specifies the directory to install Java JNI libraries in. | | `HDF5_INSTALL_INCLUDE_DIR` | `STRING` | `include` | Specifies the directory to install header files in. | | `HDF5_INSTALL_MODULE_DIR` | `STRING` | `mod` (`HDF5_USE_GNU_DIRS=OFF`)
`HDF5_INSTALL_INCLUDE_DIR/mod` (`HDF5_USE_GNU_DIRS=ON`) | Specifies the directory to install Fortran .mod files in. | -| `HDF5_INSTALL_CMAKE_DIR` | `STRING` | `cmake` (`HDF5_USE_GNU_DIRS=OFF`)
`HDF5_INSTALL_LIB_DIR/cmake` (`HDF5_USE_GNU_DIRS=ON`) | Specifies the directory to install CMake files in. | +| `HDF5_INSTALL_CMAKE_DIR` | `STRING` | `cmake` (`HDF5_USE_GNU_DIRS=OFF`)
`HDF5_INSTALL_LIB_DIR/cmake/hdf5` (`HDF5_USE_GNU_DIRS=ON`) | Specifies the directory to install CMake files in. | | `HDF5_INSTALL_DATA_DIR` | `STRING` | `.` (for `MSVC` and `HDF5_USE_GNU_DIRS=OFF`)
`share` (`HDF5_USE_GNU_DIRS=ON`) | Specifies the directory to install miscellaneous data files in. | | `HDF5_INSTALL_DOC_DIR` | `STRING` | `HDF5_INSTALL_DATA_DIR` (`HDF5_USE_GNU_DIRS=OFF`)
`HDF5_INSTALL_DATA_DIR/doc/hdf5` (`HDF5_USE_GNU_DIRS=ON`) | Specifies the directory to install documentation files in. | | `HDF5_BUILD_WITH_INSTALL_NAME` | `BOOL` | `OFF` | **MacOS only** If `ON`, builds shared library CMake targets with the "install_name" field set to the installation path. See the related CMake property [INSTALL_NAME_DIR](https://cmake.org/cmake/help/latest/prop_tgt/INSTALL_NAME_DIR.html#prop_tgt:INSTALL_NAME_DIR). | @@ -315,7 +315,7 @@ These are options which can be set for controlling how the HDF5 example programs | `H5EXAMPLE_USE_110_API` | `BOOL` | `OFF` | If `ON`, compile the HDF5 library examples programs using the HDF5 1.10 API. | | `H5EXAMPLE_USE_18_API` | `BOOL` | `OFF` | If `ON`, compile the HDF5 library examples programs using the HDF5 1.8 API. | | `H5EXAMPLE_USE_16_API` | `BOOL` | `OFF` | If `ON`, compile the HDF5 library examples programs using the HDF5 1.6 API. | -| `H5EXAMPLE_USE_GNU_DIRS` | `BOOL` | `OFF` | If `ON`, uses the GNU Coding Standard CMake install directory variables when setting up for installing the HDF5 library example programs. See [GNUInstallDirs](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html) for more information. | +| `H5EXAMPLE_USE_GNU_DIRS` | `BOOL` | Varies by platform | If `ON`, uses the GNU Coding Standard CMake install directory variables when setting up for installing the HDF5 library example programs. See [GNUInstallDirs](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html) for more information. | | `H5EXAMPLE_DISABLE_COMPILER_WARNINGS` | `BOOL` | `OFF` | If `ON`, disables most or all compiler warnings when building the HDF5 library example programs. | | `H5EXAMPLE_BUILD_FRAMEWORKS` | `BOOL` | `OFF` | If `ON`, the HDF5 library example programs will be built as a framework bundle when built on MacOS. |