mirror of
https://github.com/HDFGroup/hdf5.git
synced 2026-09-25 04:09:44 +03:00
Fix standalone example build issues (#6598)
* Build the examples as C++11 to match the HDF5 C++ library The standalone examples build forces CMAKE_CXX_STANDARD 98, but H5public.h includes <cinttypes>, which requires C++11. Any C++ translation unit that includes hdf5.h is therefore affected, not just users of the C++ API, and the HDF5 C++ library itself is built as C++11 (config/flags/HDFCompilerCXXFlags.cmake). The C++ examples do not compile as a result, against static or shared HDF5 alike. Only the standalone build is affected, which is why this is not visible in ordinary use. The C++98 setting lives in BASIC_SETTINGS, and HDF5Examples/CMakeLists.txt skips that whole block when EXAMPLES_EXTERNALLY_CONFIGURED is set -- which HDF5 does for its own in-tree example build (config/cmake/HDF5ExampleCache.cmake). Built in tree, the examples inherit HDF5's C++11 and compile normally, and that is the path the CI workflows exercise. The standalone path, where the C++98 setting does apply, is driven by the release scripts rather than by the workflows, and has the C++ examples off by default. * Select the examples' HL, Fortran and C++ libraries on the right variable When the examples are built standalone against an installed HDF5, the HL, Fortran and C++ branches choose between the shared and static libraries using BUILD_SHARED_LIBS, while the C branch just above them uses H5EXAMPLE_USE_SHARED_LIBS. H5EXAMPLE_USE_SHARED_LIBS is what decides whether the "shared" or the "static" component is requested from find_package, so only the matching HDF5_<linkage>_<lang>_FOUND variables are ever set. BUILD_SHARED_LIBS cannot select a linkage on its own; it can only agree or fail to match. Of its four combinations with H5EXAMPLE_USE_SHARED_LIBS, three produce no observable difference. In the fourth, H5EXAMPLE_USE_SHARED_LIBS=ON with BUILD_SHARED_LIBS unset, the shared branch is not taken and the static branch cannot be, so the HL, Fortran and C++ examples are disabled with "libs not found" even though the libraries are installed and were found. Use H5EXAMPLE_USE_SHARED_LIBS, which is the declared option and is already what the C branch uses. A build driven through config/examples/CTestScript.cmake does not reach the broken combination, because it configures with HDF5Examples/config/cmake/cacheinit.cmake, which forces BUILD_SHARED_LIBS=ON. A direct cmake invocation without that cache file does. In either case the HL, Fortran and C++ examples are off by default, so this is only visible once they are enabled. BUILD_SHARED_LIBS remains documented as a user option in config/examples/HDF5_Examples_options.cmake but no longer influences library selection; that comment should be revisited separately.
This commit is contained in:
@@ -37,7 +37,10 @@ macro (BASIC_SETTINGS varname)
|
||||
if (H5EXAMPLE_BUILD_CXX)
|
||||
ENABLE_LANGUAGE (CXX)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 98)
|
||||
# Match the standard the HDF5 C++ library itself is built with.
|
||||
# H5public.h includes <cinttypes>, so any C++ translation unit
|
||||
# with hdf5.h needs C++11
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
set (CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
||||
set (CMAKE_CXX_EXTENSIONS OFF)
|
||||
endif ()
|
||||
@@ -246,7 +249,7 @@ macro (HDF5_SUPPORT)
|
||||
message (STATUS "HDF5 HL libs not found - disable build of HL examples")
|
||||
else ()
|
||||
if (H5EXAMPLE_BUILD_HL AND ${HDF5_PROVIDES_HL_LIB})
|
||||
if (BUILD_SHARED_LIBS AND HDF5_shared_HL_FOUND)
|
||||
if (H5EXAMPLE_USE_SHARED_LIBS AND HDF5_shared_HL_FOUND)
|
||||
set (H5EXAMPLE_HDF5_LINK_LIBS ${H5EXAMPLE_HDF5_LINK_LIBS} ${HDF5_HL_SHARED_LIBRARY})
|
||||
elseif (HDF5_static_HL_FOUND)
|
||||
set (H5EXAMPLE_HDF5_LINK_LIBS ${H5EXAMPLE_HDF5_LINK_LIBS} ${HDF5_HL_STATIC_LIBRARY})
|
||||
@@ -262,7 +265,7 @@ macro (HDF5_SUPPORT)
|
||||
message (STATUS "HDF5 Fortran libs not found - disable build of Fortran examples")
|
||||
else ()
|
||||
if (H5EXAMPLE_BUILD_FORTRAN AND ${HDF5_PROVIDES_FORTRAN})
|
||||
if (BUILD_SHARED_LIBS AND HDF5_shared_Fortran_FOUND)
|
||||
if (H5EXAMPLE_USE_SHARED_LIBS AND HDF5_shared_Fortran_FOUND)
|
||||
set (H5EXAMPLE_HDF5_LINK_LIBS ${H5EXAMPLE_HDF5_LINK_LIBS} ${HDF5_FORTRAN_SHARED_LIBRARY})
|
||||
if (H5EXAMPLE_BUILD_HL AND ${HDF5_PROVIDES_HL_LIB})
|
||||
set (H5EXAMPLE_HDF5_LINK_LIBS ${H5EXAMPLE_HDF5_LINK_LIBS} ${HDF5_FORTRAN_HL_SHARED_LIBRARY})
|
||||
@@ -284,7 +287,7 @@ macro (HDF5_SUPPORT)
|
||||
message (STATUS "HDF5 CXX libs not found - disable build of CXX examples")
|
||||
else ()
|
||||
if (H5EXAMPLE_BUILD_CXX AND ${HDF5_PROVIDES_CPP_LIB})
|
||||
if (BUILD_SHARED_LIBS AND HDF5_shared_CXX_FOUND)
|
||||
if (H5EXAMPLE_USE_SHARED_LIBS AND HDF5_shared_CXX_FOUND)
|
||||
set (H5EXAMPLE_HDF5_LINK_LIBS ${H5EXAMPLE_HDF5_LINK_LIBS} ${HDF5_CXX_SHARED_LIBRARY})
|
||||
if (H5EXAMPLE_BUILD_HL AND ${HDF5_PROVIDES_HL_LIB})
|
||||
set (H5EXAMPLE_HDF5_LINK_LIBS ${H5EXAMPLE_HDF5_LINK_LIBS} ${HDF5_CXX_HL_SHARED_LIBRARY})
|
||||
|
||||
@@ -91,6 +91,34 @@ We would like to thank the many HDF5 community members who contributed to this r
|
||||
|
||||
The installed CMake package version configuration file for the library previously used `SameMinorVersion` for the version compatibility logic, causing a `find_package(HDF5 X.Y.Z)` call to fail unless the version of a located HDF5 installation matched both `X` and `Y` of the version number exactly (i.e., releases with a greater minor version number weren't considered backward compatible). This reflected the version compatibility of HDF5 releases prior to version 2.0.0, but doesn't reflect the version compatibility of HDF5 version 2.0.0+ releases. The version compatibility logic now uses `SameMajorVersion`, so a `find_package(HDF5 X.Y.Z)` call will accept all versions of HDF5 where the major version matches `X` (i.e., only releases with a greater major version number will be rejected as not backward compatible).
|
||||
|
||||
### Fixed the C++ examples failing to compile when built standalone
|
||||
|
||||
The standalone examples build used C++98, but `H5public.h` includes
|
||||
`<cinttypes>`, which requires C++11. This affected any C++ translation unit
|
||||
including `hdf5.h`, and did not match the HDF5 C++ library itself, which is
|
||||
built as C++11. The C++ examples did not compile, against either static or
|
||||
shared HDF5. The examples are now built as C++11.
|
||||
|
||||
Only the standalone build was affected. Examples built as part of the HDF5
|
||||
build inherit the library's own C++ standard.
|
||||
|
||||
### Fixed the examples skipping the HL, Fortran and C++ programs in some configurations
|
||||
|
||||
When built standalone against an installed HDF5, the examples chose between
|
||||
the shared and static HL, Fortran and C++ libraries using `BUILD_SHARED_LIBS`,
|
||||
while the C library used `H5EXAMPLE_USE_SHARED_LIBS`. Since
|
||||
`H5EXAMPLE_USE_SHARED_LIBS` determines which component is requested from
|
||||
`find_package`, and therefore which `HDF5_<linkage>_<lang>_FOUND` variables
|
||||
exist, `BUILD_SHARED_LIBS` could not select a linkage on its own. With
|
||||
`H5EXAMPLE_USE_SHARED_LIBS` on and `BUILD_SHARED_LIBS` unset, those examples
|
||||
were disabled with a "libs not found" message even though the libraries were
|
||||
installed and had been found. The selection now uses
|
||||
`H5EXAMPLE_USE_SHARED_LIBS`, matching the C library.
|
||||
|
||||
Builds driven through `CTestScript.cmake` were not affected, since its cache
|
||||
file forces `BUILD_SHARED_LIBS` on. This affected cases where the examples
|
||||
were built directly without that cache file.
|
||||
|
||||
## Tools
|
||||
|
||||
### Fixed an issue with quoting of data values in h5ls and h5dump when displaying as ASCII characters
|
||||
|
||||
Reference in New Issue
Block a user