From 1cc3f9685391db7a8ebfe803602ddacf7236a980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=BEenan=20Zuki=C4=87?= Date: Tue, 7 Jul 2026 15:10:11 -0400 Subject: [PATCH] COMP: GDCM: fix missing zlib include path when ITK_USE_SYSTEM_ZLIB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ← 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. --- Modules/ThirdParty/GDCM/src/CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Modules/ThirdParty/GDCM/src/CMakeLists.txt b/Modules/ThirdParty/GDCM/src/CMakeLists.txt index 6b41ce9072a..382371f225d 100644 --- a/Modules/ThirdParty/GDCM/src/CMakeLists.txt +++ b/Modules/ThirdParty/GDCM/src/CMakeLists.txt @@ -41,7 +41,14 @@ set(OPENJPEG_INCLUDE_DIRS "") set(OPENJPEG_LIBRARIES "ITK::ITKOpenJPEGModule") # ZLIB: set(GDCM_USE_SYSTEM_ZLIB ON CACHE INTERNAL "") -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 + set(ZLIB_INCLUDE_DIRS "${ZLIB_INCLUDE_DIR}") +else() + # ITK's bundled zlib is provided through the target's INTERFACE_INCLUDE_DIRECTORIES + set(ZLIB_INCLUDE_DIRS "") +endif() set(ZLIB_LIBRARIES "ITK::ITKZLIBModule") # Configure GDCM privately so its options do not appear to the user.