Skip to content

COMP: Detect the VTK rendering backend from imported targets - #6850

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:comp-vtkglue-rendering-detection
Sep 7, 2026
Merged

COMP: Detect the VTK rendering backend from imported targets#6850
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:comp-vtkglue-rendering-detection

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Sep 6, 2026

Copy link
Copy Markdown
Member

Fixes #6846. ITKVtkGlue cannot configure against a VTK built without rendering, even though the module contains explicit logic intended to support that case. The logic is unreachable because it tests VTK_RENDERING_BACKEND, a VTK 8 variable that VTK 9 does not define.

Detect the backend from the imported targets instead, so the existing STREQUAL "None" guards work as written.

Why the existing guards never fire

itk-module-init.cmake defaults the backend when the variable is empty:

if(NOT VTK_RENDERING_BACKEND)
  set(VTK_RENDERING_BACKEND OpenGL2)
endif()

VTK 9 never sets VTK_RENDERING_BACKEND — confirmed against a 9.6.2 install:

$ grep -rl VTK_RENDERING_BACKEND <vtk-build>/lib/cmake/vtk-9.6/
(no matches)

So the variable is always empty, always becomes OpenGL2, and every
if(NOT VTK_RENDERING_BACKEND STREQUAL "None") guard is unconditionally true.
The rendering libraries are appended in all cases, and
vtk_module_autoinit is then called with VTK::RenderingOpenGL2 on a VTK that
may not have it.

The module was written to support a rendering-free VTK: src/CMakeLists.txt
already guards QuickView.cxx, and test/CMakeLists.txt already guards the
viewer tests, both on the same STREQUAL "None" condition. Only the line that
computes the value is wrong, so an intended-optional dependency has been
mandatory for the whole VTK 9 era.

Four sites

The detection block appears three times, and two of those run at the
consumer's find_package(ITK) rather than in ITK's own configure:

Site Evaluated at Affects
itk-module-init.cmake ITK configure ITK's own build
CMakeLists.txt, ITKVtkGlue_EXPORT_CODE_INSTALL consumer find_package(ITK) installed ITK
CMakeLists.txt, ITKVtkGlue_EXPORT_CODE_BUILD consumer find_package(ITK) build-tree ITK

So the effect is not limited to building ITK — every downstream project that
consumes an installed ITK re-runs the same broken detection.

A fourth site is in the wrapping layer and contains no reference to the
variable at all. itk_auto_load_and_end_wrap_submodules() discovers every
.wrap file, so itkViewImage was wrapped regardless of the backend, and
itkViewImage.hxx includes vtkRenderWindow.h. With the three CMake sites
fixed, configure succeeded and the build then failed:

itkViewImage.hxx:21: fatal error: 'vtkRenderWindow.h' file not found

wrapping/itkViewImage.wrap now carries the same STREQUAL "None" guard the
sources and tests already use.

The two export-code copies live inside quoted strings whose escaping is
documented at CMakeLists.txt:70: \${VTK_RENDERING_BACKEND} must stay
escaped so it expands at consumer time, and the comment warns that mixing
escaped and unescaped forms is a latent bug (see PR #6144). The replacement
introduces no new variable references — only an if(TARGET ...) test — so it
does not interact with that hazard.

Verification

macOS arm64, two purpose-built VTK 9.6.2 trees differing only in rendering.

With rendering (VTK_GROUP_ENABLE_Rendering=WANT) — no regression:

  • configure succeeds
  • build completes with 0 errors; 12/12 VtkGlue tests pass, unchanged from before

Without rendering (VTK_GROUP_ENABLE_Rendering=NO) — the case that
previously could not configure at all:

  • configure now succeeds; on main it fails with

    CMake Error at Modules/Bridge/VtkGlue/src/CMakeLists.txt:5 (target_link_libraries):
      Target "ITKVtkGlue" links to:
        VTK::RenderingOpenGL2
      but the target was not found.
    
  • the build completes, 0 errors

  • 8 tests register and 8/8 pass: the three non-rendering C++ tests, the
    three Python tests and the two style checks

  • the three viewer tests (itkVtkMedianImageFilterTest, QuickViewTest,
    itkVtkConnectedComponentImageFilterTest) are correctly excluded

Note for reviewers merging alongside #6848

#6848 also touches Modules/Bridge/VtkGlue/itk-module-init.cmake, adding
configure-time checks for unusable VTK configurations. The two changes are in
different regions of the file and are logically independent, but a textual
conflict is possible depending on merge order. Happy to rebase whichever lands
second.

@hjmjohnson
hjmjohnson marked this pull request as ready for review September 6, 2026 17:04
@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:Python wrapping Python bindings for a class area:Bridge Issues affecting the Bridge module labels Sep 6, 2026
@hjmjohnson
hjmjohnson marked this pull request as draft September 6, 2026 17:07
@greptile-apps

greptile-apps Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Updates ITKVtkGlue configuration to detect VTK rendering support from the imported OpenGL2 target, retain rendering-enabled behavior when available, and avoid enabling rendering-dependent integration where VTK does not provide it.

Confidence Score: 5/5

Safe to merge.

No outstanding findings remain. The previously raised source-comment requirement was addressed by hjmjohnson, who confirmed the comment was condensed in commit b1f8fc7; the current code contains the condensed single-line comment.

Files Needing Attention: None.

Reviews (2): Last reviewed commit: "COMP: Detect the VTK rendering backend f..." | Re-trigger Greptile

Comment thread Modules/Bridge/VtkGlue/itk-module-init.cmake Outdated
VTK 9 does not define VTK_RENDERING_BACKEND, so the fallback to OpenGL2
always fired and every "STREQUAL None" guard was unconditionally true.
ITKVtkGlue therefore required a rendering-enabled VTK even though its
sources and tests already guard the viewer classes for the None case.

The same block appears in the two export-code strings, which run at the
consumer's find_package(ITK), so a downstream project re-ran the broken
detection as well. All three are changed.
@hjmjohnson
hjmjohnson force-pushed the comp-vtkglue-rendering-detection branch from 9ea5e23 to b1f8fc7 Compare September 6, 2026 17:30
@hjmjohnson
hjmjohnson marked this pull request as ready for review September 6, 2026 17:31

@dzenanz dzenanz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good even as-is.

Comment thread Modules/Bridge/VtkGlue/CMakeLists.txt
@hjmjohnson
hjmjohnson merged commit e152b22 into InsightSoftwareConsortium:main Sep 7, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Bridge Issues affecting the Bridge module area:Python wrapping Python bindings for a class 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.

ITKVtkGlue cannot configure against a rendering-free VTK; the VTK_RENDERING_BACKEND guard is dead code

2 participants