build(cmake): guard libtiff's missing Deflate target#5313
Conversation
Static libtiff package exports can reference Deflate::Deflate without importing the target. Quietly load libdeflate's config and supply the alias before TIFF discovery when needed. Fixes AcademySoftwareFoundation#4439 Assisted-by: Codex / GPT-5 Signed-off-by: Zach Lewis <zachcanbereached@gmail.com>
Reference the upstream libtiff report from the defensive target guard. Assisted-by: Codex / GPT-5 Signed-off-by: Zach Lewis <zachcanbereached@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a CMake-side compatibility guard in OIIO’s dependency discovery to prevent configuration failures when a previously installed/static libtiff config exports TIFF::tiff with an unresolved link interface dependency on Deflate::Deflate (libtiff config-mode defect).
Changes:
- Before
checked_find_package(TIFF), conditionallyfind_package(libdeflate CONFIG QUIET)ifDeflate::Deflatedoes not already exist. - Alias
Deflate::Deflatetolibdeflate::libdeflate_staticorlibdeflate::libdeflate_sharedwhen available.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Define libtiff's missing Deflate target before the installed static OpenImageIO package resolves its TIFF dependency. Assisted-by: Codex / GPT-5 Signed-off-by: Zach Lewis <zachcanbereached@gmail.com>
| # Static libtiff configs may reference this target without importing it. | ||
| # https://gitlab.com/libtiff/libtiff/-/work_items/871 | ||
| if (NOT TARGET Deflate::Deflate) | ||
| find_package (libdeflate CONFIG QUIET) |
There was a problem hiding this comment.
Internally, we use checked_find_package, which has lots of bells and whistles, including that it will be included in the build log report of which dependencies were found at which version.
There was a problem hiding this comment.
There's something about when + how checked_find_package does what it does that makes it difficult for the config that libtiff sets up that fails to survive a rebuild, when the locally-built libtiff is rediscovered... I don't really understand enough about what's happening behind the scenes to grok exactly what's going on. But the only thing that seems to work is forcing tiff to always build locally (when rebuilding using an existing build dir persisting previously built deps).
Description
Fixes configuration failures when OIIO finds a previously autobuilt static libtiff package whose exported
TIFF::tifftarget referencesDeflate::Deflatewithout importing or defining that target.Before TIFF discovery, this adds a narrow compatibility guard that quietly loads libdeflate's config package and aliases its static or shared target as
Deflate::Deflatewhen necessary.Fixes #4439.
Root cause
libtiff links static TIFF builds against
Deflate::Deflate, causing the installedTIFF::tifftarget to export$<LINK_ONLY:Deflate::Deflate>.However, libtiff's installed
tiff-config.cmakeloads that exported target without importing its dependencies. The corresponding upstream template still contains# TODO: import dependencies.Upstream report: https://gitlab.com/libtiff/libtiff/-/work_items/871
OIIO encounters this during
checked_find_package(TIFF). CMake'sFindTIFFmodule first attempts libtiff's config package, which exposes the malformed export. This is not specific to CMake 4.3: I reproduced it with CMake 3.29.6 and 4.3.1. Issue #4439 likewise originally reported CMake 3.29+ on Linux and macOS rather than a Homebrew-specific failure.Why fix this in OIIO?
The underlying package-export defect belongs in libtiff, but an upstream fix will not repair already-installed libtiff releases or OIIO dependency caches. OIIO also builds the affected static libtiff configuration itself.
This also breaks OIIO's ability to self-build (some) dependencies that [in]directly depend on libtiff or deflate. (Not for any dependencies for which we currently have self-building recipes so far; but this has blocked me in the past from submitting PRs for some of the more complex (sub)dependencies (libheif comes to mind; maybe jxl...? can't remember, it was more than a year ago when I last looked into this)
The guard is intentionally defensive:
Deflate::Deflatedoes not already exist;Testing
Tested on:
Verification performed:
Steps taken to verify:
SKBUILD_BUILD_DIR,IGNORE_HOMEBREWED_DEPS=1, and without forcing a local TIFF rebuild. The first build autobuilt static TIFF 4.7.1 and libdeflate 1.23; the second found the cached TIFF package and completed without the previousDeflate::Deflateerror.No robots worth speaking of were harmed in the making of this PR
Assisted-by: Codex / GPT-5
Codex was used to trace the CMake package-discovery chain, inspect the libtiff exports, reproduce the failure, prepare the compatibility guard, and run the verification described above.