Skip to content

GDCM: fix missing zlib include path when ITK_USE_SYSTEM_ZLIB#6563

Draft
dzenanz wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
dzenanz:gdcmBuild
Draft

GDCM: fix missing zlib include path when ITK_USE_SYSTEM_ZLIB#6563
dzenanz wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
dzenanz:gdcmBuild

Conversation

@dzenanz

@dzenanz dzenanz commented Jul 7, 2026

Copy link
Copy Markdown
Member

The original error message was:

------ Build started: Project: gdcmCommon, Configuration: Debug x64 ------
  gdcmDeflateStream.cxx
M:\a\Slicer-deb\ITK-build\Modules\ThirdParty\ZLIB\src\itk_zlib.h(35,11): error C1083: Cannot open include file: 'zlib.h': No such file or directory

While trying to build within Slicer. While this does fix it for Slicer, I am not sure whether this is the best fix.

PR Checklist

The original error message was:

------ Build started: Project: gdcmCommon, Configuration: Debug x64 ------
  gdcmDeflateStream.cxx
M:\a\Slicer-deb\ITK-build\Modules\ThirdParty\ZLIB\src\itk_zlib.h(35,11): error C1083: Cannot open include file: 'zlib.h': No such file or directory

Root cause:
The include chain:
gdcmDeflateStream.cxx
  → zipstreamimpl.h → gdcm_zlib.h
    → [GDCM_USE_SYSTEM_ZLIB defined] → itk_zlib.h
      → [ITK_USE_SYSTEM_ZLIB defined] → #include <zlib.h>   ← C1083

When the bundled zlib is used, GDCM receives headers through
ITK::ITKZLIBModule's INTERFACE_INCLUDE_DIRECTORIES, so the empty string
remains correct. When the system zlib is used, ZLIB_INCLUDE_DIR (a CMake
cache variable populated by find_package(ZLIB)) is forwarded as
ZLIB_INCLUDE_DIRS so GDCM's include_directories() call picks it up.
@github-actions github-actions Bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots area:ThirdParty Issues affecting the ThirdParty module labels Jul 7, 2026
@dzenanz

dzenanz commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

@greptileai review

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes GDCM's zlib include setup when ITK uses a system zlib. The main changes are:

  • Pass ITK's discovered zlib include directory into GDCM for system-zlib builds.
  • Keep the bundled-zlib include path behavior unchanged.
  • Continue linking GDCM against ITK::ITKZLIBModule.

Confidence Score: 5/5

This looks safe to merge.

No blocking issues found in the changed code.

No files need attention.

T-Rex T-Rex Logs

What T-Rex did

  • Configured the project with CMake for the GDCM system, confirming ZLIB version 1.2.13 and EXIT_CODE 0.
  • Built the project with cmake --build, compiled gdcmDeflateStream.cxx, and created the library libitkgdcmCommon-6.0.a with EXIT_CODE 0.
  • Validated the toolchain and environment by inspecting cmake, ninja, and pkg-config paths and confirming ZLIB version 1.2.13.
  • Uploaded three artifacts containing the configure log, the build log, and the tool/environment log for review.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
Modules/ThirdParty/GDCM/src/CMakeLists.txt Updates the private GDCM zlib include-directory handoff for system-zlib builds.

Reviews (2): Last reviewed commit: "COMP: GDCM: fix missing zlib include pat..." | Re-trigger Greptile

Comment thread Modules/ThirdParty/GDCM/src/CMakeLists.txt
@dzenanz dzenanz marked this pull request as ready for review July 7, 2026 20:53
@dzenanz dzenanz requested a review from blowekamp July 7, 2026 20:56
@blowekamp

Copy link
Copy Markdown
Member

Here are the lines that pass the ZLIB config to ITK:
https://github.com/Slicer/Slicer/blob/main/SuperBuild/External_ITK.cmake#L134-L138

The current expectation would be that when find_package ZLIB with ZLIB_ROOT alone set, it would create the ZLIB::ZLIB imported target with the properties of the include and library paths. This should make the other variable not needed.

Clearly something is not working correctly there, when the ZLIB::ZLIB import target to ITK needs to be inspected to determine what is going on the the FindZLIB in this situation.

@blowekamp blowekamp 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.

The comments are misleading and will create further confusion.

set(ZLIB_INCLUDE_DIRS "")
if(ITK_USE_SYSTEM_ZLIB)
# ZLIB_INCLUDE_DIR is populated by find_package(ZLIB) in ITK's ZLIB module.
# Pass it explicitly so GDCM's root CMakeLists can find the real system <zlib.h>

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.

These statements are verbose and misleading.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is the suggested course of actions to reduce/remove comments, or to abandon the PR? I was trying to build Slicer from this commit: dzenanz/Slicer@d177327

@blowekamp blowekamp Jul 8, 2026

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.

It looks like that branch is based on a couple months ago version of ITK. There have been several fixes for using system libraries in just the past couple of weeks that should be included. So this issue may already be fixed in ITK main?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Main from 2 days ago is merged there. Nothing related to GDCM got merged since.

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.

I tried to reproduce the error. I checkout dzenanz/Slicer@d177327 and was successfully able to built the ITK target on a clean build. So I wasn't able to reproduce to look at this further.

@blowekamp blowekamp Jul 8, 2026

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.

I was able to build your slicer branch with your ITK 7ed87c5 (before this change) and was not able to reproduce the issue either. This is on a linux system while above it is reported as a windows system.

I wonder if this reported issue is related to the multi-build (release/debug) VS system.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Let me try building that on Linux.

@hjmjohnson hjmjohnson self-requested a review July 8, 2026 13:58

@hjmjohnson hjmjohnson 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.

I assume this was a transient build error, and that a clean build could not replicate the problem as Brad indicated.

@dzenanz dzenanz marked this pull request as draft July 10, 2026 14:55
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: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