Reject find_package calls with non-standard capitalization - #6603
Reject find_package calls with non-standard capitalization#6603mattjala wants to merge 2 commits into
Conversation
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.
Review ChecklistThis PR touches the following areas. Each needs a sign-off
|
There was a problem hiding this comment.
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_COMPONENTSto${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTSso the caller’s requested component list is preserved for any capitalization. - Update
*_NOT_FOUND_MESSAGEassignment 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}_FOUNDis set to FALSE, but for config-mode packages CMake checks${CMAKE_FIND_PACKAGE_NAME}_FOUND(the capitalization used infind_package()). This can causefind_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.
|
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 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.