Skip to content

COMP: Strip dead cmake_minimum_required + standalone wrapper from 4 ingests#6216

Merged
hjmjohnson merged 1 commit intoInsightSoftwareConsortium:mainfrom
hjmjohnson:cleanup-ingested-cmake-min
May 5, 2026
Merged

COMP: Strip dead cmake_minimum_required + standalone wrapper from 4 ingests#6216
hjmjohnson merged 1 commit intoInsightSoftwareConsortium:mainfrom
hjmjohnson:cleanup-ingested-cmake-min

Conversation

@hjmjohnson
Copy link
Copy Markdown
Member

Strips two upstream-original boilerplate idioms from four already-merged remote-module ingests: per-module cmake_minimum_required(VERSION X.Y.Z) declarations (redundant with ITK's top-level pin) and if(NOT ITK_SOURCE_DIR) ... else() itk_module_impl() endif() standalone-build wrappers (dead code in-tree, since ITK_SOURCE_DIR is always defined). Matches the v4 sanitizer rules now codified in #6204 so every future ingest will be born clean.

Files changed (4 modules)
Module Status before Action
Modules/Filtering/AnisotropicDiffusionLBR Both idioms present Both removed; set(ITK_DIR ${CMAKE_BINARY_DIR}) from the in-tree else-branch preserved as unconditional
Modules/Filtering/Cuberille Both idioms present Both removed
Modules/Filtering/LabelErodeDilate Both idioms present Both removed
Modules/Registration/Montage Both idioms present Both removed; set(ITK_DIR ${CMAKE_BINARY_DIR}) preserved as unconditional

The other four already-merged ingests (GenericLabelInterpolator, MGHIO, FastBilateral, MeshNoise) were already cleaned up during their respective ingest PRs and need no change.

The six open ingest PRs (#6206, #6208, #6211, #6212, #6214, #6215) each had an analogous cleanup applied directly on their branches earlier today.

Why both idioms are dead in-tree

cmake_minimum_required(VERSION X.Y.Z): the project's top-level CMakeLists.txt already pins a higher minimum than any of these per-module declarations (commonly 3.10.2 / 3.16.3). The per-module line at best does nothing and at worst lowers the floor for that subdirectory below ITK's policy.

if(NOT ITK_SOURCE_DIR) standalone-build guard: the upstream remote-module repos used this idiom so the module's CMakeLists.txt could be configured both as a fetched ITK module and as a stand-alone CMake project. In an in-tree ingested module, ITK_SOURCE_DIR is always defined, so the if-branch is unreachable.

Both patterns are flagged consistently by reviewers (e.g. @dzenanz on PRs #6206 / #6215) and by the v4 sanitizer's run summary.

Local verification
  • pre-commit run --all-files exit 0
  • cmake . reconfigure on the build tree clean (32 s)
  • 4 files modified, 6 insertions, 36 deletions

Four already-merged remote-module ingests still carry their
upstream-original boilerplate at the top of their module CMakeLists:

  - cmake_minimum_required(VERSION X.Y.Z) — redundant; ITK's top-level
    CMakeLists pins a higher minimum.
  - if(NOT ITK_SOURCE_DIR) ... find_package(ITK) ... else()
    itk_module_impl() endif() — dead code in-tree because
    ITK_SOURCE_DIR is always defined.

Strip both from:

  Modules/Filtering/AnisotropicDiffusionLBR
  Modules/Filtering/Cuberille
  Modules/Filtering/LabelErodeDilate
  Modules/Registration/Montage

Lines that had effect inside the in-tree else() branch
(set(ITK_DIR ${CMAKE_BINARY_DIR}) on AnisotropicDiffusionLBR and
Montage) are preserved unconditionally.

The other four merged ingests (GenericLabelInterpolator, MGHIO,
FastBilateral, MeshNoise) were already cleaned up during their
respective ingest PRs.

Matches the v4 ingest-pipeline rules now codified in PR InsightSoftwareConsortium#6204
(sanitize-history.py:patch_drop_cmake_minimum_required and
:patch_standalone_build_guard); future ingests will not introduce
this idiom.
@github-actions github-actions Bot added type:Compiler Compiler support or related warnings type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots area:Filtering Issues affecting the Filtering module area:Registration Issues affecting the Registration module labels May 5, 2026
@hjmjohnson hjmjohnson marked this pull request as ready for review May 5, 2026 16:35
Copy link
Copy Markdown
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.

Thanks for following up.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 5, 2026

Greptile Summary

This PR removes two boilerplate idioms that are dead code in ITK's in-tree module builds: per-module cmake_minimum_required(VERSION X.Y.Z) declarations (superseded by the top-level CMake policy) and if(NOT ITK_SOURCE_DIR) ... else() ... endif() standalone-build guards (the if-branch is unreachable in-tree since ITK_SOURCE_DIR is always defined). Four previously-ingested modules are cleaned up to match the v4 sanitizer rules from #6204.

  • AnisotropicDiffusionLBR and Montage: cmake_minimum_required removed and the standalone-build conditional collapsed, preserving set(ITK_DIR ${CMAKE_BINARY_DIR}) + itk_module_impl() unconditionally (was in the else-branch only).
  • Cuberille and LabelErodeDilate: cmake_minimum_required removed and the conditional collapsed to a bare itk_module_impl() call.

Confidence Score: 5/5

This PR is safe to merge — it removes only unreachable code paths and redundant CMake declarations with no change to in-tree build behavior.

All four modules only ever executed the else-branch of the standalone-build guard in an in-tree ITK build. Removing the dead if-branch and the superseded cmake_minimum_required calls leaves the effective CMake logic identical to before. The two modules that had set(ITK_DIR ${CMAKE_BINARY_DIR}) in their else-branches correctly preserve that line unconditionally.

No files require special attention; all changes are mechanical dead-code removal.

Important Files Changed

Filename Overview
Modules/Filtering/AnisotropicDiffusionLBR/CMakeLists.txt Removed cmake_minimum_required and the if(NOT ITK_SOURCE_DIR) guard; set(ITK_DIR) + itk_module_impl() preserved unconditionally from the former else-branch. Correct and clean.
Modules/Filtering/Cuberille/CMakeLists.txt Removed cmake_minimum_required and the standalone-build conditional; bare itk_module_impl() retained. Straightforward cleanup.
Modules/Filtering/LabelErodeDilate/CMakeLists.txt Removed cmake_minimum_required and the standalone-build conditional; bare itk_module_impl() retained. Straightforward cleanup.
Modules/Registration/Montage/CMakeLists.txt Removed cmake_minimum_required and the if(NOT ITK_SOURCE_DIR) guard; set(ITK_DIR) + itk_module_impl() preserved unconditionally from the former else-branch. Correct and clean.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[CMakeLists.txt processed by CMake] --> B{ITK_SOURCE_DIR defined?}
    B -- "Before PR: YES (in-tree, always true)" --> C["else-branch:\nset(ITK_DIR)\nitk_module_impl()"]
    B -- "Before PR: NO (standalone, unreachable)" --> D["if-branch:\nfind_package(ITK)\ninclude(ITKModuleExternal)"]
    D -. dead code .-> D
    A2[CMakeLists.txt after PR] --> E["set(ITK_DIR) if applicable\nitk_module_impl()"]
    style D fill:#ffcccc,stroke:#cc0000,stroke-dasharray: 5 5
    style E fill:#ccffcc,stroke:#007700
Loading

Reviews (1): Last reviewed commit: "COMP: Drop dead cmake_minimum_required +..." | Re-trigger Greptile

@hjmjohnson hjmjohnson merged commit 477ae98 into InsightSoftwareConsortium:main May 5, 2026
16 of 18 checks passed
@hjmjohnson hjmjohnson added this to the ITK 6.0 Release Candidate 1 milestone May 5, 2026
hjmjohnson added a commit to hjmjohnson/ITK that referenced this pull request May 6, 2026
…anup-ingested-cmake-min

COMP: Strip dead cmake_minimum_required + standalone wrapper from 4 ingests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Filtering Issues affecting the Filtering module area:Registration Issues affecting the Registration 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.

2 participants