Split static targets into separate optional target [UPDATED]#6216
Split static targets into separate optional target [UPDATED]#6216lrknox merged 7 commits intoHDFGroup:developfrom
Conversation
| TARGETS | ||
| ${install_targets_shared} | ||
| EXPORT | ||
| ${HDF5_EXPORTED_TARGETS} |
There was a problem hiding this comment.
It seems like the current pattern for this is ${HDF5_EXPORTED_TARGETS} for shared exports, and ${HDF5_EXPORTED_TARGETS}_static for static exports. This is slightly different than the naming pattern for the other shared vs. static variables, where the shared-specific one is suffixed with _shared. It might be good to use that pattern here too.
There was a problem hiding this comment.
The EXPORT argument directly controls the generated CMake file names:
EXPORT ${HDF5_EXPORTED_TARGETS} -> ${HDF5_PACKAGE}-targets.cmake (primary)
EXPORT ${HDF5_EXPORTED_TARGETS}_static -> ${HDF5_PACKAGE}-static-targets.cmake (variant)
By CMake convention, the base export set name (without suffix) represents the primary/default build artifact (shared libraries), while suffixed names are for variants. Changing the shared export to _shared would generate ${HDF5_PACKAGE}-shared-targets.cmake, breaking this convention and potentially affecting downstream consumers who expect the standard naming convention.
The asymmetry with install_targets_shared/install_targets_static is intentional—those are internal variables, while export set names follow external packaging conventions.
| # Used by hdf5-config.cmake.in to advertise available library targets | ||
| #----------------------------------------------------------------------------- | ||
| set_global_variable (HDF5_LIBRARIES_TO_EXPORT "") | ||
| set_global_variable (HDF5_UTILS_TO_EXPORT "") |
There was a problem hiding this comment.
Does removing this global change the export behavior? It doesn't seem like this was replaced with anything
There was a problem hiding this comment.
HDF5_UTILS_TO_EXPORT was intentionally removed and replaced by the CMake export set mechanism. The refactoring changed from manual tracking (export(TARGETS ${HDF5_UTILS_TO_EXPORT}...)) to automatic export sets (export(EXPORT ${HDF5_EXPORTED_TARGETS})). Since tools already have EXPORT in their install() commands, they're automatically included. This ensures build-tree and install-tree exports are identical.
There was a problem hiding this comment.
See my other comment; I believe this could be an unexpected change in behavior.
CMakeInstallation.cmake
Outdated
| endif () | ||
| export ( | ||
| TARGETS ${HDF5_LIBRARIES_TO_EXPORT} ${HDF5_LIB_DEPENDENCIES} ${HDF5_UTILS_TO_EXPORT} | ||
| EXPORT ${HDF5_EXPORTED_TARGETS} |
There was a problem hiding this comment.
I believe this is a change in behavior because a project building the library as a sub-project could unset HDF5_EXPORTED_TARGETS, in which case none of the targets would be available for export at all whereas previously they were. I'm assuming the previous behavior is intended because only the logic above is guarded by if (HDF5_EXPORTED_TARGETS) whereas this export() call isn't. I don't think ${HDF5_EXPORTED_TARGETS} should be used here since it could be unset.
There was a problem hiding this comment.
However, looking closer at the logic, I also believe this export () call should be moved outside of the enclosing if (NOT HDF5_EXTERNALLY_CONFIGURED), as the comment about the parent project makes no sense otherwise.
…5_UTILS_TO_EXPORT - Move build-tree export(TARGETS) outside if(NOT HDF5_EXTERNALLY_CONFIGURED) so sub-project builds can access targets in the build tree - Use export(TARGETS) with global variables instead of export(EXPORT) to avoid dependency on HDF5_EXPORTED_TARGETS which could be unset by parent - Restore OPTIONAL on static targets include (needed for build-tree config where all targets are in a single combined file) - Keep OPTIONAL on Java targets include - Restore original comment and HDF5_UTILS_TO_EXPORT global variable - Re-add set_global_variable(HDF5_UTILS_TO_EXPORT) calls in tool/util files
…5_UTILS_TO_EXPORT - Move build-tree export(TARGETS) outside if(NOT HDF5_EXTERNALLY_CONFIGURED) so sub-project builds can access targets in the build tree - Use export(TARGETS) with global variables instead of export(EXPORT) to avoid dependency on HDF5_EXPORTED_TARGETS which could be unset by parent - Restore OPTIONAL on static targets include (needed for build-tree config where all targets are in a single combined file) - Keep OPTIONAL on Java targets include - Restore original comment and HDF5_UTILS_TO_EXPORT global variable - Re-add set_global_variable(HDF5_UTILS_TO_EXPORT) calls in tool/util files
…5_UTILS_TO_EXPORT - Move build-tree export(TARGETS) outside if(NOT HDF5_EXTERNALLY_CONFIGURED) so sub-project builds can access targets in the build tree - Use export(TARGETS) with global variables instead of export(EXPORT) to avoid dependency on HDF5_EXPORTED_TARGETS which could be unset by parent - Restore OPTIONAL on static targets include (needed for build-tree config where all targets are in a single combined file) - Keep OPTIONAL on Java targets include - Restore original comment and HDF5_UTILS_TO_EXPORT global variable - Re-add set_global_variable(HDF5_UTILS_TO_EXPORT) calls in tool/util files
…5_UTILS_TO_EXPORT - Move build-tree export(TARGETS) outside if(NOT HDF5_EXTERNALLY_CONFIGURED) so sub-project builds can access targets in the build tree - Use export(TARGETS) with global variables instead of export(EXPORT) to avoid dependency on HDF5_EXPORTED_TARGETS which could be unset by parent - Restore OPTIONAL on static targets include (needed for build-tree config where all targets are in a single combined file) - Keep OPTIONAL on Java targets include - Restore original comment and HDF5_UTILS_TO_EXPORT global variable - Re-add set_global_variable(HDF5_UTILS_TO_EXPORT) calls in tool/util files
config/install/hdf5-config.cmake.in
Outdated
| endif () | ||
| include (@PACKAGE_SHARE_INSTALL_DIR@/@HDF5_PACKAGE@@HDF_PACKAGE_EXT@-targets.cmake) | ||
| if ( @BUILD_STATIC_LIBS@ AND @BUILD_SHARED_LIBS@ ) | ||
| include (@PACKAGE_SHARE_INSTALL_DIR@/@HDF5_PACKAGE@@HDF_PACKAGE_EXT@_static-targets.cmake) |
There was a problem hiding this comment.
This needs to be OPTIONAL if we are going to be able to split the static-targets.cmake into a separate -static sub-package.
There was a problem hiding this comment.
I guess it's still a bit unclear to me why this needs to be OPTIONAL. The only time the file should be missing is when BUILD_STATIC_LIBS is OFF, in which case include() shouldn't get called here.
There was a problem hiding this comment.
Ah ok, going back to your original comment about the sub-package being shipped separately I understand the need for OPTIONAL here now. It seems less than ideal though considering it would mask actual problems in the case where the static-targets file is missing due to an issue in our logic, but I don't have a good solution currently.
There was a problem hiding this comment.
@brtnfld We should put OPTIONAL back here and maybe include a comment in the file mentioning that some packages ship HDF5 in such a way that the individual targets files may not be available.
There was a problem hiding this comment.
Yeah, it's not great. Perhaps there could be a run time determination if BUILD_STATIC is set?
|
Thanks a lot for continuing the work on this. It will be very useful for the Fedora package. |
Replace bare include() calls with explicit if(EXISTS) checks and use runtime variables instead of configure-time substitutions for the static and Java target guards. Core and vendored dependency targets (ZLIB, SZIP) fail gracefully via CMAKE_FIND_PACKAGE_NAME_FOUND=FALSE with an actionable error message when files are missing, since HDF5 targets depend on them through INTERFACE_LINK_LIBRARIES. Static and Java targets degrade gracefully by clearing their PROVIDES_* flags when files are missing (e.g. distros that only ship shared libraries), allowing check_required_components() to report the correct error if the user requested those components. All temporary variables are unset after use to prevent leakage into downstream scopes.
# Conflicts: # CMakeFilters.cmake
| if (${HDF5_PACKAGE_NAME}_PROVIDES_STATIC_LIBS AND ${HDF5_PACKAGE_NAME}_PROVIDES_SHARED_LIBS) | ||
| include ("@PACKAGE_SHARE_INSTALL_DIR@/@HDF5_PACKAGE@@HDF_PACKAGE_EXT@_static-targets.cmake" OPTIONAL RESULT_VARIABLE _hdf5_static_loaded) | ||
| if (NOT _hdf5_static_loaded) | ||
| set (${CMAKE_FIND_PACKAGE_NAME}_static_FOUND FALSE) |
There was a problem hiding this comment.
Setting this hooks into CMake's native error-handling for find_package(), so the missing dependency occurs at configure-time rather than letting the application stumble into a cryptic target-not-found error at link-time at the near end of the build.
…p#6216) Build-tree exports can't diverge from install-tree exports — the export(EXPORT ...) reads directly from the install export sets. No manual list to keep in sync. Removed 3 global variables (HDF5_STATIC_LIBRARIES_TO_EXPORT, HDF5_JAVA_LIBRARIES_TO_EXPORT, HDF5_UTILS_TO_EXPORT) and their ~21 set_global_variable calls across tool/utility files. Fixed the static-only build bug in the PR where the base export set was guarded by BUILD_SHARED_LIBS, breaking tools export. Removed redundant utils in export files — the PR was dumping tools into all three build-tree export files (java, static, shared). Now they correctly appear only in the base export.
* Skip some parallel example tests for small MPIEXEC_MAX_NUMPROCS values (#6224) * chore: fix grammar (#6227) * Split static targets into separate optional target [UPDATED] (#6216) Build-tree exports can't diverge from install-tree exports — the export(EXPORT ...) reads directly from the install export sets. No manual list to keep in sync. Removed 3 global variables (HDF5_STATIC_LIBRARIES_TO_EXPORT, HDF5_JAVA_LIBRARIES_TO_EXPORT, HDF5_UTILS_TO_EXPORT) and their ~21 set_global_variable calls across tool/utility files. Fixed the static-only build bug in the PR where the base export set was guarded by BUILD_SHARED_LIBS, breaking tools export. Removed redundant utils in export files — the PR was dumping tools into all three build-tree export files (java, static, shared). Now they correctly appear only in the base export. * Apply filters to variable-length data (#6178) Closes can_apply and set_local filter callbacks skipped for H5T_VARIABLE dtypes #5942. A more detailed explanation of the rationale for this PR is in the linked issue. Mandatory filters can be now applied to variable-length data. This notably includes h5py object strings and NpyStrings. Optional filters applied to variable-length data no longer skip can_apply and set_local, only to jump directly to filter. This fixes hdf5_blosc and HDF5_Blosc2, which rely on set_local. Note that all filters which have neither can_apply nor set_local have always worked fine with vlen data, as long as they were tagged as optional. Notable examples are deflate, lzf, bzip2 (from hdf5plugin), and lz4 (also from hdf5plugin). Lossy filters, such as scale-offset, are and remain untested and most likely broken, as I expect them to treat the vlen metadata as numbers and corrupt it. The right place to ensure proper behaviour is their can_apply function, which however is broken (filters: can_apply does nothing for optional filters #6161).
Supersedes #6109
Additions:
Important
Split static targets into separate optional targets in HDF5 CMake configuration, removing global variables and fixing static-only build issues.
CMakeInstallation.cmakeandhdf5-config.cmake.in.BUILD_SHARED_LIBS.HDF5_STATIC_LIBRARIES_TO_EXPORT,HDF5_JAVA_LIBRARIES_TO_EXPORT,HDF5_UTILS_TO_EXPORT.c++/src/CMakeLists.txt,fortran/src/CMakeLists.txt, andhl/c++/src/CMakeLists.txt.install()commands to handle static and shared targets separately insrc/CMakeLists.txtandtools/lib/CMakeLists.txt.This description was created by
for 53710f2. You can customize this summary. It will automatically update as commits are pushed.