Skip to content

COMP: Replace hdf5.h includes with itk_hdf5.h in MINC library#5978

Merged
blowekamp merged 1 commit intoInsightSoftwareConsortium:mainfrom
blowekamp:fix-minc-duplicate-hdf5-header
Mar 25, 2026
Merged

COMP: Replace hdf5.h includes with itk_hdf5.h in MINC library#5978
blowekamp merged 1 commit intoInsightSoftwareConsortium:mainfrom
blowekamp:fix-minc-duplicate-hdf5-header

Conversation

@blowekamp
Copy link
Member

Fixes -Wshadow-header warnings about duplicate header candidates. The MINC library sources included <hdf5.h> directly, which could resolve to two different headers (itkhdf5/hdf5.h and itkhdf5/src/hdf5.h) causing a shadow header warning.

Use ITK's itk_hdf5.h wrapper instead, which properly handles both internal and system HDF5 configurations.

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)
  • Added license to new files (if any)
  • Added Python wrapping to new files (if any) as described in ITK Software Guide Section 9.5
  • Added ITK examples for all new major features (if any)

Refer to the ITK Software Guide for
further development details if necessary.

@github-actions github-actions bot added type:Compiler Compiler support or related warnings area:ThirdParty Issues affecting the ThirdParty module labels Mar 24, 2026
@blowekamp blowekamp force-pushed the fix-minc-duplicate-hdf5-header branch from 0568f94 to 627d149 Compare March 24, 2026 17:28
@github-actions github-actions bot added the type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots label Mar 24, 2026
Fixes -Wshadow-header warnings about multiple candidates for header
'hdf5.h':

  Modules/ThirdParty/MINC/src/libminc/libsrc2/minc2.h:8:10: warning:
  multiple candidates for header 'hdf5.h' found; directory
  '.../HDF5/src/itkhdf5' chosen, ignoring others including
  '.../HDF5/src/itkhdf5/src' [-Wshadow-header]

The MINC library src/CMakeLists.txt manually added both itkhdf5/ and
itkhdf5/src/ to the include path, causing two hdf5.h candidates. Replace
this with the proper ITK::ITKHDF5Module target, which carries the correct
include directories via imported target properties. Update all MINC source
files to use the ITK wrapper <itk_hdf5.h> instead of <hdf5.h> directly.
@blowekamp blowekamp force-pushed the fix-minc-duplicate-hdf5-header branch from 627d149 to f4bcee4 Compare March 24, 2026 17:51
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

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

I am surprised that we missed this!

@blowekamp blowekamp marked this pull request as ready for review March 24, 2026 19:35
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 24, 2026

Greptile Summary

This PR fixes -Wshadow-header compiler warnings in the MINC third-party library by replacing all direct #include <hdf5.h> includes with ITK's #include <itk_hdf5.h> wrapper, and by updating CMakeLists.txt to use the modern CMake target ITK::ITKHDF5Module instead of manually managing include directories.

Key changes:

  • All 12 active #include <hdf5.h> occurrences across libsrc/, libsrc2/, and libcommon/ are replaced with #include <itk_hdf5.h>. The one remaining <hdf5.h> reference in libsrc2/dimension.c is pre-existing commented-out code and does not need updating.
  • CMakeLists.txt removes the if(NOT ITK_USE_SYSTEM_HDF5) block that explicitly set up include paths pointing to two overlapping HDF5 directories (itkhdf5/ and itkhdf5/src/) — the root cause of the shadow-header warning.
  • HDF5_LIBRARIES is updated from ${ITKHDF5_LIBRARIES} (a bare list of library targets) to ITK::ITKHDF5Module (a proper CMake imported target), consistent with how ZLIB_LIBRARY is already handled as ITK::ITKZLIBModule. The include directories for itk_hdf5.h (generated in ${ITKHDF5_BINARY_DIR}/src) are now correctly propagated to ${LIBMINC_LIBRARY} through CMake's INTERFACE_INCLUDE_DIRECTORIES mechanism when target_link_libraries links against ITK::ITKHDF5Module.
  • The itk_hdf5.h wrapper (generated from itk_hdf5.h.in) correctly routes to either <hdf5.h> (system HDF5) or itkhdf5/hdf5.h (bundled HDF5) based on ITK_USE_SYSTEM_HDF5, eliminating the ambiguous duplicate-candidate lookup that triggered the warning.

Confidence Score: 5/5

  • This PR is safe to merge — it is a targeted compiler-warning fix with no API or logic changes.
  • All changes are mechanical header substitutions (hdf5.hitk_hdf5.h) across files that were already compiling correctly. The CMake change is consistent with the existing pattern used by ZLIB (ITK::ITKZLIBModule) and correctly leverages target-based include propagation. No missed active #include <hdf5.h> occurrences remain; the one found in dimension.c was already commented out before this PR. The itk_hdf5.h wrapper covers both the internal and system HDF5 cases, so both build configurations are handled.
  • No files require special attention.

Important Files Changed

Filename Overview
Modules/ThirdParty/MINC/src/CMakeLists.txt Removes manual HDF5 include_directories block and switches HDF5_LIBRARIES from ${ITKHDF5_LIBRARIES} to the modern CMake target ITK::ITKHDF5Module, which propagates include directories via target interface properties.
Modules/ThirdParty/MINC/src/libminc/libsrc2/minc2.h Central libsrc2 header updated to include itk_hdf5.h instead of hdf5.h, fixing the shadow-header warning at the most impactful point since many .c files include this header.
Modules/ThirdParty/MINC/src/libminc/libsrc/minc.h libsrc public header updated to use itk_hdf5.h under the MINC2 conditional block; no functional change to the exposed API.
Modules/ThirdParty/MINC/src/libminc/libcommon/ParseArgv.c itk_hdf5.h substitution under the HAVE_MINC2 guard; straightforward and correct.
Modules/ThirdParty/MINC/src/libminc/libsrc2/convert.c One-line header substitution; no other changes.
Modules/ThirdParty/MINC/src/libminc/libsrc2/volume.c One-line header substitution; no other changes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["MINC source files\n(*.c, *.h)"] -->|"#include"| B{"itk_hdf5.h\n(wrapper)"}
    B -->|"ITK_USE_SYSTEM_HDF5 ON"| C["<hdf5.h>\n(system HDF5)"]
    B -->|"ITK_USE_SYSTEM_HDF5 OFF"| D["itkhdf5/hdf5.h\n(bundled HDF5)"]

    E["CMakeLists.txt\nMINC/src/"] -->|"sets"| F["HDF5_LIBRARIES =\nITK::ITKHDF5Module"]
    F -->|"target_link_libraries\npropagates INTERFACE_INCLUDE_DIRECTORIES"| G["${ITKHDF5_BINARY_DIR}/src\n(where itk_hdf5.h lives)"]
    G --> A

    H["Old approach\n(removed)"] -.->|"explicit include_directories()\nITKHDF5_SOURCE_DIR paths"| I["hdf5.h shadow warning\n(two candidate paths)"]
    style H fill:#fdd,stroke:#f88
    style I fill:#fdd,stroke:#f88
    style B fill:#dfd,stroke:#8d8
    style F fill:#dfd,stroke:#8d8
Loading

Reviews (1): Last reviewed commit: "COMP: Replace hdf5.h includes with itk_h..." | Re-trigger Greptile

@blowekamp
Copy link
Member Author

Related: #5980

@blowekamp blowekamp merged commit b644fc6 into InsightSoftwareConsortium:main Mar 25, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ThirdParty Issues affecting the ThirdParty module type:Compiler Compiler support or related warnings type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants