Skip to content

Reject find_package calls with non-standard capitalization - #6603

Open
mattjala wants to merge 2 commits into
HDFGroup:developfrom
mattjala:cmake-config-find-package-name
Open

Reject find_package calls with non-standard capitalization#6603
mattjala wants to merge 2 commits into
HDFGroup:developfrom
mattjala:cmake-config-find-package-name

Conversation

@mattjala

@mattjala mattjala commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

HDF5 installs hdf5-config.cmake, and CMake's config-mode search accepts either Config.cmake or -config.cmake, so find_package() locates HDF5 for any capitalization the caller provides (HDF5, hdf5, HdF5). CMake then records the requested components under the exact capitalization that was used, in _FIND_COMPONENTS.

The config reads that state as ${HDF5_PACKAGE_NAME}_FIND_COMPONENTS, and HDF5_PACKAGE_NAME is the uppercased package name, so it always reads the specific variable HDF5_FIND_COMPONENTS. Any capitalization other than HDF5 has its component list read back as empty. The package is still found, but the config concludes that no components were requested and applies its defaults.

This PR swaps ${HDF5_PACKAGE_NAME} for ${CMAKE_FIND_PACKAGE_NAME} in the names of variables used by CMake's mechanisms in order to correctly retain the components list for any provided capitalization pattern for HDF5.

EDIT: The problem this PR addressed is now resolved by rejecting incorrect capitalizations instead of doing work to make sure they still get the correct configuration information.

HDF5 installs hdf5-config.cmake, and CMake's config-mode search accepts
either <Name>Config.cmake or <lowercased-Name>-config.cmake, so find_package()
locates HDF5 for any capitalization the caller provides (HDF5, hdf5, HdF5). CMake then records the
requested components under the exact capitalization that was used, in <capitalization>_FIND_COMPONENTS.

The config reads that state as ${HDF5_PACKAGE_NAME}_FIND_COMPONENTS, and
HDF5_PACKAGE_NAME is the uppercased package name, so it always reads
HDF5_FIND_COMPONENTS. Any capitalization other than HDF5 therefore has its
component list read back as empty. The package is still found, but the config
concludes that no components were requested and applies its defaults, dropping
the request with no error or warning.

This PR swaps ${HDF5_PACKAGE_NAME} for ${CMAKE_FIND_PACKAGE_NAME}
in the names of variables used by CMake's mechanisms in order to
correctly retain the components list for any provided
capitalization pattern for HDF5.
Copilot AI lite review requested due to automatic review settings August 11, 2026 21:14
@github-project-automation github-project-automation Bot moved this to To be triaged in HDF5 - TRIAGE & TRACK Aug 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Review Checklist

This PR touches the following areas. Each needs a sign-off
from its listed owners before merging.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the installed hdf5-config.cmake template to correctly respect find_package() component requests regardless of how the caller capitalizes the package name (e.g., HDF5, hdf5, HdF5), by using CMAKE_FIND_PACKAGE_NAME for CMake’s *_FIND_COMPONENTS-related variables.

Changes:

  • Switch component handling from ${HDF5_PACKAGE_NAME}_FIND_COMPONENTS to ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS so the caller’s requested component list is preserved for any capitalization.
  • Update *_NOT_FOUND_MESSAGE assignment to use ${CMAKE_FIND_PACKAGE_NAME} so error reporting aligns with the caller’s package name capitalization.
Suppressed comments (1)

config/install/hdf5-config.cmake.in:228

  • When libaec targets can’t be loaded, ${HDF5_PACKAGE_NAME}_FOUND is set to FALSE, but for config-mode packages CMake checks ${CMAKE_FIND_PACKAGE_NAME}_FOUND (the capitalization used in find_package()). This can cause find_package(hdf5 REQUIRED) to succeed even though the config returns early.
      set (${HDF5_PACKAGE_NAME}_FOUND FALSE)
      set (${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "Couldn't locate libaec targets file ${_libaec_targets_file_name}")

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread config/install/hdf5-config.cmake.in Outdated
@jhendersonHDF

Copy link
Copy Markdown
Collaborator

I may need to think about this more, but this is a case where I might actually suggest simply rejecting any package name that isn't exactly HDF5 in our configuration file instead of trying to work around the problem. Both find_package (hdf5 MODULE REQUIRED) and find_package (HdF5 MODULE REQUIRED) will fail because the module in CMake is FindHDF5.cmake and the convention for variables set by that is HDF5_XXX, so we typically would want to always match that convention in our configuration file for variables set for compatibility. Something like hdf5_XXX would only confuse the issue.

@github-actions
github-actions Bot removed the request for review from lrknox August 12, 2026 16:25
@mattjala mattjala changed the title Retain components when using non-uppercase package name in find_package Reject find_package calls with non-standard capitalization Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: To be triaged

Development

Successfully merging this pull request may close these issues.

3 participants