Skip to content

COMP: Do not require applications to rediscover zlib.#6489

Closed
jakeforster wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
jakeforster:retain-zlib
Closed

COMP: Do not require applications to rediscover zlib.#6489
jakeforster wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
jakeforster:retain-zlib

Conversation

@jakeforster

Copy link
Copy Markdown
Contributor

'find_package(ITK REQUIRED)' no longer calls 'find_package(ZLIB REQUIRED)'. ITK::ITKZLIBModule already exports the library and include directory of the zlib used by ITK, so rely on that.

  • Modules/ThirdParty/ZLIB/CMakeLists.txt (ITKZLIB_EXPORT_CODE_INSTALL): Make empty.

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)
  • Added license to new files (if any)
  • Added Python wrapping to new files (if any) as described in ITK Software Guide Section 9.5
  • Added ITK examples for all new major features (if any)

Refer to the ITK Software Guide for
further development details if necessary.

'find_package(ITK REQUIRED)' no longer calls 'find_package(ZLIB REQUIRED)'.
ITK::ITKZLIBModule already exports the library and include directory of the
zlib used by ITK, so rely on that.

* Modules/ThirdParty/ZLIB/CMakeLists.txt (ITKZLIB_EXPORT_CODE_INSTALL):
Make empty.
@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 22, 2026
@greptile-apps

This comment was marked as resolved.

Comment thread Modules/ThirdParty/ZLIB/CMakeLists.txt

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

Requesting one change before this lands: also empty ITKZLIB_EXPORT_CODE_BUILD, so build-tree and install-tree consumers see the same CMake environment (resolves greptile's P2). The build-tree find_package(ZLIB) is redundant for the same reason the install-tree one is — ITK::ITKZLIBModule already carries the absolute zlib library path and system include dirs.

I verified downstream impact empirically (system-zlib ITK, build tree and install tree). Net: safe for every standard consumption idiom; the only hypothetical consumer affected is one that references ZLIB::ZLIB without its own find_package(ZLIB)(no instances found).

Downstream consumer matrix (vs main baseline)
consumer idiom real-world vs baseline
find_package(ITK) + ${ITK_LIBRARIES} BioCell, Cleaver, HASI, RTK, remotes same (pass)
+ include(${ITK_USE_FILE}) c3d, elastix, LesionSizingToolkit same (pass)
find_package(ITK NO_MODULE) IGSIO same (pass)
find_package(ITK COMPONENTS …) elastix, RTK same (pass)
target_link_libraries(ITK::ITKZLIBModule) modern same (pass)
links ZLIB::ZLIB, no own find_package(ZLIB) piggyback (discouraged) install-tree configure fails now; emptying the build block too makes it symmetric in both trees

ITK_USE_SYSTEM_ZLIB=OFF (bundled zlib) is unaffected.

Note: ITK CI builds ITK_USE_SYSTEM_ZLIB=OFF, so CI does not exercise this code path — the matrix above is the evidence. Please also update the commit trailer to name both variables.

Comment thread Modules/ThirdParty/ZLIB/CMakeLists.txt
@blowekamp blowekamp self-requested a review June 22, 2026 13:00
@blowekamp

blowekamp commented Jun 22, 2026

Copy link
Copy Markdown
Member

In a pull request @bradking (which I can't find) recommended doing the find_package but not embedding the 3rd party libraries paths in the export code, and only doing the find package. It is my understanding that this is the best practice not include these absolute package paths to facilitate relocatable packages.

I need to look at this a bit closer.

@blowekamp

Copy link
Copy Markdown
Member

I see the following in my ITKTargets.cmake:


# Create imported target ITK::ITKZLIBModule
add_library(ITK::ITKZLIBModule INTERFACE IMPORTED)

set_target_properties(ITK::ITKZLIBModule PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "/scratch/itk/build-system/Modules/ThirdParty/ZLIB/src;/usr/include"
  INTERFACE_LINK_LIBRARIES "/usr/lib/x86_64-linux-gnu/libz.so"
)

The real bug is that this should refer to the ZLIB::ZLIB interface and not these hard coded path. I'll look into this.

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

This is the incorrect solution to the hard coded paths in ITKTargets.cmake.

@hjmjohnson

Copy link
Copy Markdown
Member

Superceeded. Thank you for identifying the problem and proposing a solution.

@hjmjohnson hjmjohnson closed this Jun 22, 2026
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