Skip to content

COMP: Enable DCMTK PNG/TIFF/ZLIB via find_package with ITK libraries (supersedes #5537)#6393

Draft
hjmjohnson wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:dcmtk-enable-png-tiff-zlib-find-package
Draft

COMP: Enable DCMTK PNG/TIFF/ZLIB via find_package with ITK libraries (supersedes #5537)#6393
hjmjohnson wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:dcmtk-enable-png-tiff-zlib-find-package

Conversation

@hjmjohnson
Copy link
Copy Markdown
Member

Enables PNG/TIFF/ZLIB/JPEG support in the internally-built DCMTK by turning on DCMTK_USE_FIND_PACKAGE and teaching the DCMTK fork to consume ITK's bundled codecs directly. Fixes the Module_IOTransformDCMTK build failure in #5539 and supersedes #5537 (the original one-line WIP by @dzenanz).

Depends on DCMTK fork commit 5b5c6f0d5 on for/itk-dcmtk-3.7.0-ccfd10b (pushed); DCMTKGitTag.cmake is bumped to it.

Root cause (issue #5539)

On Windows (non-MinGW) DCMTK defaults DCMTK_USE_FIND_PACKAGE=FALSE, so the entire block that wires TIFF/JPEG/PNG/ZLIB is skipped — the DCMTK_WITH_* options and the raw *_LIBRARY/*_INCLUDE_DIR hints ITK passes are silently ignored and the features are compiled out.

Turning DCMTK_USE_FIND_PACKAGE on (as #5537 did) then forces find_package(JPEG)/find_package(TIFF) unconditionally. The stock FindJPEG/FindTIFF modules probe a canonical header in the include dir for version extraction, but ITK's internally-built libraries place the header in a subdirectory (.../JPEG/src/itkjpeg-turbo/jpeglib.h vs the passed .../JPEG/src), so configure dies reading jpeglib.h.

DCMTK's PNG and ZLIB branches already guard with if(X_INCLUDE_DIR AND X_LIBRARY) to use ITK's hints directly and skip find_package. JPEG and TIFF lacked that guard. The fork commit adds it for JPEG and TIFF, mirroring the existing pattern.

What changed
  • DCMTK fork (for/itk-dcmtk-3.7.0-ccfd10b, 5b5c6f0d5): CMake/3rdparty.cmake — add ITK-aware bypass guards to the JPEG and TIFF lookups.
  • Modules/ThirdParty/DCMTK/CMakeLists.txt: set DCMTK_USE_FIND_PACKAGE=ON; for MSVC pass /Zc:__cplusplus to the DCMTK build so its STL feature probes observe the real __cplusplus value and enable C++17 (otherwise STL support is disabled and ITKIODCMTK fails to compile — the Turning on Module_IOTransformDCMTK triggers a compile time error in ITKIODCMTK #5539 symptom).
  • DCMTKGitTag.cmake: bump to the fork commit.

The MSVC runtime-CRT concern in #2872 is already handled in main via CMAKE_MSVC_RUNTIME_LIBRARY + CMP0091; no change here.

Validation

Built and tested locally on macOS with -DModule_ITKIODCMTK=ON:

  • DCMTK ExternalProject configures via the JPEG/TIFF find_package bypass, using ITK's internal libitktiff/libitkjpeg (not system libs); all DCMTK libraries build; ITKIODCMTK links.
  • ctest -R DCMTK: 23/24 pass (only ITKIODCMTKKWStyleTest (Not Run) — KWStyle absent). A stock-main baseline build is identical (23/24, same Not-Run) → no regression.

macOS already forces DCMTK_USE_FIND_PACKAGE=TRUE, so the original find_package failure and the MSVC /Zc:__cplusplus fix can only be exercised on Windows CI.

Set DCMTK_USE_FIND_PACKAGE=ON so DCMTK wires up PNG, TIFF, ZLIB, and JPEG
support; without it the DCMTK_WITH_* options are silently ignored on
Windows and those features are compiled out (issue InsightSoftwareConsortium#5539).

Bump the vendored DCMTK to a fork commit that guards the TIFF and JPEG
lookups with the same ITK-aware bypass the PNG and ZLIB branches already
use, so the stock Find modules are not invoked on ITK's internal library
layout (which has no canonical header for version extraction).

For MSVC, pass /Zc:__cplusplus to the DCMTK build so its STL feature
probes observe the real __cplusplus value and enable C++17; otherwise
they disable STL support and ITKIODCMTK fails to compile (issue InsightSoftwareConsortium#5539).

Co-Authored-By: Dženan Zukić <dzenan.zukic@kitware.com>
@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:ThirdParty Issues affecting the ThirdParty module labels Jun 4, 2026
@blowekamp
Copy link
Copy Markdown
Member

@hjmjohnson With the update ITK interface modules with target based properties, the preferred way to use ITK's provided libraries is not to specify the old variables but just set the library variables to the ITK exported interface libraries which have the build in library files, header includes etc.

The new pattern in libraries using ITK libraries is something like:

if (NOT TIFF_LIBRARIES)
 # other stufff
  find_package(TIFF)
endif()

Then in the ITK level CMakeFile set TIFF_LIBRARIES like this:

# Expat:
set(GDCM_USE_SYSTEM_EXPAT ON CACHE INTERNAL "")
set(EXPAT_INCLUDE_DIR ${ITKExpat_INCLUDE_DIRS})
set(EXPAT_LIBRARY ${ITKExpat_LIBRARIES})
# OpenJPEG:
set(GDCM_USE_SYSTEM_OPENJPEG ON CACHE INTERNAL "")
set(GDCM_USE_OPENJPEG_V2 ON CACHE INTERNAL "")
set(OPENJPEG_INCLUDE_DIRS "")
set(OPENJPEG_LIBRARIES "ITK::ITKOpenJPEGModule")
# ZLIB:
set(GDCM_USE_SYSTEM_ZLIB ON CACHE INTERNAL "")
set(ZLIB_INCLUDE_DIR ${ITKZLIB_INCLUDE_DIRS})
set(ZLIB_LIBRARY ${ITKZLIB_LIBRARIES})

By not running the find_packages in the thirdparty library things are much easier. Additionally, the ITK level variable are already support both ITK vendored libraries and system libraries.

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.

Looks good on a glance. Thanks for giving me co-author credit. Consider Brad's suggestion. Good even as-is, assuming it works, of course 😄

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