Skip to content

Split static targets into separate optional target [UPDATED]#6216

Merged
lrknox merged 7 commits intoHDFGroup:developfrom
brtnfld:6109
Feb 24, 2026
Merged

Split static targets into separate optional target [UPDATED]#6216
lrknox merged 7 commits intoHDFGroup:developfrom
brtnfld:6109

Conversation

@brtnfld
Copy link
Collaborator

@brtnfld brtnfld commented Feb 12, 2026

Supersedes #6109

Additions:

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

Important

Split static targets into separate optional targets in HDF5 CMake configuration, removing global variables and fixing static-only build issues.

  • Behavior:
    • Export static and shared targets separately in CMakeInstallation.cmake and hdf5-config.cmake.in.
    • Fix static-only build bug by ensuring base export set is not guarded by BUILD_SHARED_LIBS.
  • Variables:
    • Remove global variables HDF5_STATIC_LIBRARIES_TO_EXPORT, HDF5_JAVA_LIBRARIES_TO_EXPORT, HDF5_UTILS_TO_EXPORT.
  • CMake Targets:
    • Add separate export targets for static libraries in c++/src/CMakeLists.txt, fortran/src/CMakeLists.txt, and hl/c++/src/CMakeLists.txt.
    • Update install() commands to handle static and shared targets separately in src/CMakeLists.txt and tools/lib/CMakeLists.txt.

This description was created by Ellipsis for 53710f2. You can customize this summary. It will automatically update as commits are pushed.

@brtnfld brtnfld moved this from To be triaged to In progress in HDF5 - TRIAGE & TRACK Feb 12, 2026
@brtnfld brtnfld added this to the HDF5 2.x.x milestone Feb 12, 2026
bmribler
bmribler previously approved these changes Feb 13, 2026
TARGETS
${install_targets_shared}
EXPORT
${HDF5_EXPORTED_TARGETS}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does removing this global change the export behavior? It doesn't seem like this was replaced with anything

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my other comment; I believe this could be an unexpected change in behavior.

mattjala
mattjala previously approved these changes Feb 17, 2026
endif ()
export (
TARGETS ${HDF5_LIBRARIES_TO_EXPORT} ${HDF5_LIB_DEPENDENCIES} ${HDF5_UTILS_TO_EXPORT}
EXPORT ${HDF5_EXPORTED_TARGETS}
Copy link
Collaborator

@jhendersonHDF jhendersonHDF Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

brtnfld added a commit to brtnfld/hdf5 that referenced this pull request Feb 18, 2026
…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
brtnfld added a commit to brtnfld/hdf5 that referenced this pull request Feb 18, 2026
…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
brtnfld added a commit to brtnfld/hdf5 that referenced this pull request Feb 18, 2026
…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
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be OPTIONAL if we are going to be able to split the static-targets.cmake into a separate -static sub-package.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

@jhendersonHDF jhendersonHDF Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not great. Perhaps there could be a run time determination if BUILD_STATIC is set?

@opoplawski
Copy link
Contributor

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.
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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lrknox lrknox merged commit a7ec64a into HDFGroup:develop Feb 24, 2026
140 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in HDF5 - TRIAGE & TRACK Feb 24, 2026
lrknox pushed a commit to lrknox/hdf5 that referenced this pull request Feb 25, 2026
…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.
lrknox added a commit that referenced this pull request Feb 25, 2026
* 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants