COMP: Do not require applications to rediscover zlib.#6489
Conversation
'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.
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
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.
|
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. |
|
I see the following in my ITKTargets.cmake: 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
left a comment
There was a problem hiding this comment.
This is the incorrect solution to the hard coded paths in ITKTargets.cmake.
|
Superceeded. Thank you for identifying the problem and proposing a solution. |
'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.
PR Checklist
Refer to the ITK Software Guide for
further development details if necessary.