Skip to content

BUG: Use TIFF::TIFF target instead of TIFF_LIBRARIES variable#6531

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
blowekamp:fixSystemTIFFLibraries
Jun 29, 2026
Merged

BUG: Use TIFF::TIFF target instead of TIFF_LIBRARIES variable#6531
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
blowekamp:fixSystemTIFFLibraries

Conversation

@blowekamp

Copy link
Copy Markdown
Member

Use the modern TIFF::TIFF imported target instead of ${TIFF_LIBRARIES} when ITK_USE_SYSTEM_TIFF=ON. Closes #6529.

Root cause

CMake's FindTIFF.cmake populates the legacy TIFF_LIBRARIES variable for
backward compatibility by querying LOCATION_RELEASE and LOCATION_DEBUG on
the TIFF::tiff imported target. When libtiff is built with
CMAKE_BUILD_TYPE=None (Arch Linux packaging convention), the targets file
only registers IMPORTED_LOCATION_NONE. CMake falls back to that path for
both LOCATION_RELEASE and LOCATION_DEBUG queries, returning the same
path twice. FindTIFF.cmake lacks a NOT STREQUAL guard (unlike
SelectLibraryConfigurations.cmake) and emits:

TIFF_LIBRARIES = optimized;/usr/lib/libtiff.so.6.2.0;debug;/usr/lib/libtiff.so.6.2.0

ITK's itk_module_impl() loop in ITKModuleMacros.cmake then prepends the
ITK:: namespace to any token that is not a file path or already namespaced,
turning optimizedITK::optimized and debugITK::debug.
REMOVE_DUPLICATES strips the second copy of the path, leaving:

set(ITKTIFF_LIBRARIES "ITK::optimized;/usr/lib/libtiff.so.6.2.0;ITK::debug")

target_link_libraries then fails because ITK::optimized is not a target.

The upstream CMake bug (missing STREQUAL guard in FindTIFF.cmake) was
introduced in Sep 2023 and remains unfixed as of CMake master (Dec 2025).

Fix

Modules/ThirdParty/TIFF/CMakeLists.txt: replace "${TIFF_LIBRARIES}" with
"TIFF::TIFF". The TIFF::TIFF imported target is always created by
FindTIFF.cmake when TIFF is found (since CMake 3.5), contains :: so it
passes through itk_module_impl()'s namespace loop unchanged, and correctly
encapsulates all per-configuration link details internally.

Export code (ITKTIFF_EXPORT_CODE_INSTALL / ITKTIFF_EXPORT_CODE_BUILD) is
added so that downstream find_package(ITK) calls re-invoke
find_package(TIFF) and recreate the TIFF::TIFF target.

AI assistance
  • Tool: GitHub Copilot (Claude Sonnet 4.6)
  • Role: root-cause analysis, Docker reproduction environment, fix authorship
  • Reproduction: Arch Linux Docker image (archlinux:latest) with PKGBUILD
    dependencies, mounting the ITK source read-only, running cmake configure
    only — confirmed ITK::optimized in generated ITKTIFF.cmake.

FindTIFF.cmake populates TIFF_LIBRARIES using legacy optimized/debug
keywords when LOCATION_RELEASE and LOCATION_DEBUG both resolve to the
same fallback path. ITK then incorrectly prepends its namespace,
producing ITK::optimized and ITK::debug which are not valid targets.

Use the TIFF::TIFF imported target directly and add export code so
downstream find_package(ITK) calls invoke find_package(TIFF).
@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots area:ThirdParty Issues affecting the ThirdParty module labels Jun 29, 2026
@blowekamp blowekamp marked this pull request as ready for review June 29, 2026 19:45
@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a CMake build failure that occurs when ITK_USE_SYSTEM_TIFF=ON and the system libtiff was built with CMAKE_BUILD_TYPE=None (Arch Linux packaging convention). The root cause is a bug in CMake's FindTIFF.cmake that emits a duplicated path with optimized/debug keywords, which ITK's module macro then erroneously namespaces as ITK::optimized — an undefined target.

  • Replaces "${TIFF_LIBRARIES}" with "TIFF::TIFF", the modern CMake imported target that is always created by FindTIFF.cmake when TIFF is found (CMake ≥ 3.5) and is immune to the legacy variable's duplication bug.
  • Adds ITKTIFF_EXPORT_CODE_INSTALL / ITKTIFF_EXPORT_CODE_BUILD blocks that re-invoke find_package(TIFF REQUIRED) for downstream consumers, matching the identical pattern already used by the ITKJPEG and ITKPNG modules.
  • Drops the no-op set(ITKTIFF_SYSTEM_INCLUDE_DIRS) (was always empty).

Confidence Score: 5/5

Safe to merge — the change is a targeted one-file fix that aligns with the established JPEG and PNG module patterns already in the codebase.

The fix is a direct substitution of a broken legacy variable with a well-supported imported target, with export code added to match identical code in the JPEG and PNG modules. No logic is removed; the previously empty ITKTIFF_SYSTEM_INCLUDE_DIRS assignment was a no-op. The TIFF::TIFF target has been available since CMake 3.5 and carries include directories and link flags internally, so consumers are not affected.

No files require special attention.

Important Files Changed

Filename Overview
Modules/ThirdParty/TIFF/CMakeLists.txt Switches system TIFF linkage from the broken legacy TIFF_LIBRARIES variable to the TIFF::TIFF imported target; adds downstream export code to match the JPEG/PNG module pattern; drops the empty ITKTIFF_SYSTEM_INCLUDE_DIRS assignment.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[CMake configure with ITK_USE_SYSTEM_TIFF=ON] --> B[find_package TIFF REQUIRED]
    B --> C{Build type?}
    C -- "Release/Debug" --> D["TIFF_LIBRARIES = /usr/lib/libtiff.so (OK)"]
    C -- "None (Arch Linux)" --> E["TIFF_LIBRARIES = optimized;/usr/lib/libtiff.so;debug;/usr/lib/libtiff.so (BUG)"]
    D -- "Before fix" --> F["ITKTIFF_LIBRARIES = TIFF_LIBRARIES"]
    E -- "Before fix" --> G["itk_module_impl() namespace loop: optimized → ITK::optimized, debug → ITK::debug"]
    G --> H["target_link_libraries FAILS: ITK::optimized is not a target"]
    D -- "After fix" --> I["ITKTIFF_LIBRARIES = TIFF::TIFF (contains ::, passes unchanged)"]
    E -- "After fix" --> I
    I --> J["target_link_libraries succeeds"]
    I --> K["ITKTIFF_EXPORT_CODE_INSTALL/BUILD: find_package(TIFF REQUIRED) for downstream consumers"]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[CMake configure with ITK_USE_SYSTEM_TIFF=ON] --> B[find_package TIFF REQUIRED]
    B --> C{Build type?}
    C -- "Release/Debug" --> D["TIFF_LIBRARIES = /usr/lib/libtiff.so (OK)"]
    C -- "None (Arch Linux)" --> E["TIFF_LIBRARIES = optimized;/usr/lib/libtiff.so;debug;/usr/lib/libtiff.so (BUG)"]
    D -- "Before fix" --> F["ITKTIFF_LIBRARIES = TIFF_LIBRARIES"]
    E -- "Before fix" --> G["itk_module_impl() namespace loop: optimized → ITK::optimized, debug → ITK::debug"]
    G --> H["target_link_libraries FAILS: ITK::optimized is not a target"]
    D -- "After fix" --> I["ITKTIFF_LIBRARIES = TIFF::TIFF (contains ::, passes unchanged)"]
    E -- "After fix" --> I
    I --> J["target_link_libraries succeeds"]
    I --> K["ITKTIFF_EXPORT_CODE_INSTALL/BUILD: find_package(TIFF REQUIRED) for downstream consumers"]
Loading

Reviews (1): Last reviewed commit: "BUG: Use TIFF::TIFF target instead of TI..." | Re-trigger Greptile

@hjmjohnson hjmjohnson merged commit 21dcc18 into InsightSoftwareConsortium:main Jun 29, 2026
22 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:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ITKTIFFModule can't configure

3 participants