From 36beb9bf4e1bfc20fca56c5753825e87759717f2 Mon Sep 17 00:00:00 2001 From: Zach Lewis Date: Sun, 12 Jul 2026 13:49:44 -0400 Subject: [PATCH 1/6] build(cmake): guard libtiff's missing Deflate target 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 #4439 Assisted-by: Codex / GPT-5 Signed-off-by: Zach Lewis --- src/cmake/externalpackages.cmake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cmake/externalpackages.cmake b/src/cmake/externalpackages.cmake index 107b8ad255..02f215b871 100644 --- a/src/cmake/externalpackages.cmake +++ b/src/cmake/externalpackages.cmake @@ -90,6 +90,14 @@ endif () checked_find_package (libuhdr VERSION_MIN 1.3) +# Static libtiff configs may reference this target without importing it. +# https://github.com/AcademySoftwareFoundation/OpenImageIO/issues/4439 +if (NOT TARGET Deflate::Deflate) + find_package (libdeflate CONFIG QUIET) + alias_library_if_not_exists (Deflate::Deflate libdeflate::libdeflate_static) + alias_library_if_not_exists (Deflate::Deflate libdeflate::libdeflate_shared) +endif () + checked_find_package (TIFF REQUIRED VERSION_MIN 4.0 RECOMMEND_MIN 4.5 From 9bdcdfeb46ef2a9f515724c7bd52e38799306927 Mon Sep 17 00:00:00 2001 From: Zach Lewis Date: Sun, 12 Jul 2026 15:41:00 -0400 Subject: [PATCH 2/6] build(cmake): link libtiff workaround upstream Reference the upstream libtiff report from the defensive target guard. Assisted-by: Codex / GPT-5 Signed-off-by: Zach Lewis --- src/cmake/externalpackages.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmake/externalpackages.cmake b/src/cmake/externalpackages.cmake index 02f215b871..46db62798c 100644 --- a/src/cmake/externalpackages.cmake +++ b/src/cmake/externalpackages.cmake @@ -91,7 +91,7 @@ checked_find_package (libuhdr VERSION_MIN 1.3) # Static libtiff configs may reference this target without importing it. -# https://github.com/AcademySoftwareFoundation/OpenImageIO/issues/4439 +# https://gitlab.com/libtiff/libtiff/-/work_items/871 if (NOT TARGET Deflate::Deflate) find_package (libdeflate CONFIG QUIET) alias_library_if_not_exists (Deflate::Deflate libdeflate::libdeflate_static) From 5b9af7c7de6be1fc49fe46f8365cf71158d7debe Mon Sep 17 00:00:00 2001 From: Zach Lewis Date: Sun, 12 Jul 2026 16:29:36 -0400 Subject: [PATCH 3/6] build(cmake): guard static OIIO consumers 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 --- src/cmake/Config.cmake.in | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index 080a499968..94e1924a6d 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -20,6 +20,16 @@ if (NOT @BUILD_SHARED_LIBS@) # This is required in static library builds, as e.g. PNG::PNG appears among # INTERFACE_LINK_LIBRARIES. If the project does not know about PNG target, it will cause # configuration error about unknown targets being linked in. + # 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) + if (TARGET libdeflate::libdeflate_static) + add_library (Deflate::Deflate ALIAS libdeflate::libdeflate_static) + elseif (TARGET libdeflate::libdeflate_shared) + add_library (Deflate::Deflate ALIAS libdeflate::libdeflate_shared) + endif () + endif () find_dependency(TIFF) find_dependency(OpenColorIO) if (@JPEG_FOUND@) From a5991f47f8a2809dd529b4f7197a17db853d15b6 Mon Sep 17 00:00:00 2001 From: Zach Lewis Date: Mon, 3 Aug 2026 15:52:42 -0400 Subject: [PATCH 4/6] build(cmake): use checked_find_package for deflate guard Route the pre-TIFF libdeflate guard through checked_find_package so it appears in the dependency report and can use the local auto-builders, rather than a bare find_package. Also document why the guard must precede TIFF discovery: since CMake 3.29, FindTIFF probes the config package first, so a previously auto-built static libtiff rediscovered from the local deps cache is loaded after build_TIFF.cmake (which formerly supplied the Deflate::Deflate alias) has been skipped. Assisted-by: Claude Code (Fable 5) Signed-off-by: Zach Lewis --- src/cmake/externalpackages.cmake | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cmake/externalpackages.cmake b/src/cmake/externalpackages.cmake index 46db62798c..6fe1a891b1 100644 --- a/src/cmake/externalpackages.cmake +++ b/src/cmake/externalpackages.cmake @@ -90,10 +90,14 @@ endif () checked_find_package (libuhdr VERSION_MIN 1.3) -# Static libtiff configs may reference this target without importing it. -# https://gitlab.com/libtiff/libtiff/-/work_items/871 +# Static libtiff configs may reference Deflate::Deflate without importing it +# (https://gitlab.com/libtiff/libtiff/-/work_items/871), so libdeflate must be +# located before TIFF discovery. In particular, a previously auto-built static +# TIFF rediscovered from the local deps cache needs this; the libdeflate found +# during build_TIFF.cmake does not carry over to later reconfigures. if (NOT TARGET Deflate::Deflate) - find_package (libdeflate CONFIG QUIET) + checked_find_package (libdeflate + VERSION_MIN 1.18) alias_library_if_not_exists (Deflate::Deflate libdeflate::libdeflate_static) alias_library_if_not_exists (Deflate::Deflate libdeflate::libdeflate_shared) endif () From 7f457eb2634a045b2bc9301ff8989eefdceda5bd Mon Sep 17 00:00:00 2001 From: Zach Lewis Date: Mon, 3 Aug 2026 17:09:41 -0400 Subject: [PATCH 5/6] build(deps): keep Homebrew out of local dependency child builds IGNORE_HOMEBREWED_DEPS pruned prefix paths and set CMAKE_IGNORE_PATH, but CMAKE_IGNORE_PATH does not stop config-package searches, and local dependency child builds could still quietly resolve Homebrew packages we are ignoring. Concretely: with a Homebrew Imath 3.2 installed, the local OpenEXR build resolved Imath_DIR=/opt/homebrew/lib/cmake/Imath while OpenImageIO itself used the locally built Imath 3.1.10, and libOpenImageIO then failed to link with Imath_3_2 vs Imath_3_1 namespace-mangled symbol mismatches. Set CMAKE_IGNORE_PREFIX_PATH for the Homebrew prefixes (honored by config searches) and forward it to dependency child builds alongside CMAKE_IGNORE_PATH. Verified: the OpenEXR child build resolves the local deps Imath and libOpenImageIO links clean. Assisted-by: Claude Code (Fable 5) Signed-off-by: Zach Lewis --- CMakeLists.txt | 6 ++++++ src/cmake/dependency_utils.cmake | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2586106b69..1d7471e87f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,6 +223,12 @@ if (IGNORE_HOMEBREWED_DEPS) ) endforeach () + # Also ignore the whole prefixes, which (unlike CMAKE_IGNORE_PATH) is + # honored by config-package searches, and is forwarded to local + # dependency child builds so they can't quietly resolve a Homebrew + # package (e.g. a mismatched Imath) that we ourselves are ignoring. + list (APPEND CMAKE_IGNORE_PREFIX_PATH ${HOMEBREW_PREFIXES}) + message (STATUS "CMAKE_IGNORE_PATH: ${CMAKE_IGNORE_PATH}") endif () diff --git a/src/cmake/dependency_utils.cmake b/src/cmake/dependency_utils.cmake index 879580a46b..0e92c5c6a0 100644 --- a/src/cmake/dependency_utils.cmake +++ b/src/cmake/dependency_utils.cmake @@ -731,6 +731,10 @@ macro (build_dependency_with_cmake pkgname) string(REPLACE ";" "\\;" CMAKE_IGNORE_PATH_ESCAPED "${CMAKE_IGNORE_PATH}") list(APPEND _pkg_CMAKE_ARGS "-DCMAKE_IGNORE_PATH=${CMAKE_IGNORE_PATH_ESCAPED}") endif() + if (CMAKE_IGNORE_PREFIX_PATH) + string(REPLACE ";" "\\;" CMAKE_IGNORE_PREFIX_PATH_ESCAPED "${CMAKE_IGNORE_PREFIX_PATH}") + list(APPEND _pkg_CMAKE_ARGS "-DCMAKE_IGNORE_PREFIX_PATH=${CMAKE_IGNORE_PREFIX_PATH_ESCAPED}") + endif() # Pass along any CMAKE_MSVC_RUNTIME_LIBRARY if (WIN32 AND CMAKE_MSVC_RUNTIME_LIBRARY) From 27823fd60db35d62518e011ef4097f79fe2ea321 Mon Sep 17 00:00:00 2001 From: Zach Lewis Date: Mon, 3 Aug 2026 17:57:13 -0400 Subject: [PATCH 6/6] build(cmake): make installed static OIIO config stand alone Configuring a downstream consumer against an installed static OpenImageIO previously failed at generate time on targets the export references but the installed config never imported, and even after configuring, static links were silently missing libraries referenced via $. In the static block of the installed OpenImageIOConfig.cmake: - guard CMath::CMath (libtiff's libm wrapper, referenced by static libtiff exports without being imported, like Deflate::Deflate); - find_dependency OpenEXR, GIF, WebP, and ZLIB, whose targets appear in the export's link interface; - prefer libpng's own config, since the export may reference PNG::png_static, which the FindPNG module never defines; - resolve the TARGET_NAME_IF_EXISTS references too (Threads, BZip2, Freetype, libjpeg-turbo, OpenJPEG, openjph, pugixml), including reconstructing libuhdr::libuhdr, since libuhdr ships no CMake config; - fix the literal 'if ()' rendered when OIIO_TBB is empty. Verified with an all-locally-built static install: a minimal consumer (find_package(OpenImageIO) + link OpenImageIO::OpenImageIO) now configures, links, and runs; before, it failed at generate on CMath::CMath and OpenEXR::OpenEXR and at link on PNG, WebP, OpenJPEG, and libuhdr. Assisted-by: Claude Code (Fable 5) Signed-off-by: Zach Lewis --- src/cmake/Config.cmake.in | 51 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index 94e1924a6d..456d69c5d3 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -30,20 +30,63 @@ if (NOT @BUILD_SHARED_LIBS@) add_library (Deflate::Deflate ALIAS libdeflate::libdeflate_shared) endif () endif () + # Static libtiff configs may likewise reference CMath::CMath (libtiff's + # libm wrapper target) without importing it. + if (NOT WIN32 AND NOT TARGET CMath::CMath) + add_library (CMath::CMath INTERFACE IMPORTED) + set_target_properties (CMath::CMath PROPERTIES + INTERFACE_LINK_LIBRARIES m) + endif () find_dependency(TIFF) + find_dependency(OpenEXR) find_dependency(OpenColorIO) + if (@GIF_FOUND@) + find_dependency(GIF) + endif() if (@JPEG_FOUND@) find_dependency(JPEG) endif() if (@PNG_FOUND@) - find_dependency(PNG) + # Prefer libpng's own config, whose static/shared targets a static + # OIIO export may reference (e.g. PNG::png_static); fall back to + # the FindPNG module. + find_package (PNG CONFIG QUIET) + if (NOT TARGET PNG::PNG AND NOT TARGET PNG::png_static + AND NOT TARGET PNG::png_shared) + find_dependency(PNG) + endif () + endif() + if (@WebP_FOUND@) + find_dependency(WebP CONFIG) endif() + find_dependency(ZLIB) if (@DCMTK_FOUND@) find_dependency(DCMTK) endif() - # The following have the same problem except that INTERFACE_LINK_LIBRARIES use - # TARGET_NAME_IF_EXISTS, so the error only happens on link time. - if (@OIIO_TBB@) + # Resolve targets referenced via $ too, so + # static consumer links are not silently missing libraries. + find_dependency(Threads) + if (@BZIP2_FOUND@) + find_dependency(BZip2) + endif() + if (@FREETYPE_FOUND@) + find_dependency(Freetype) + endif() + find_package (libjpeg-turbo CONFIG QUIET) + find_package (OpenJPEG CONFIG QUIET) + find_package (openjph CONFIG QUIET) + find_package (pugixml CONFIG QUIET) + # libuhdr ships no CMake config of its own, so reconstruct the imported + # target the OIIO export refers to. + if (@libuhdr_FOUND@ AND NOT TARGET libuhdr::libuhdr) + find_library (_OIIO_libuhdr_LIBRARY NAMES uhdr libuhdr) + if (_OIIO_libuhdr_LIBRARY) + add_library (libuhdr::libuhdr UNKNOWN IMPORTED) + set_target_properties (libuhdr::libuhdr PROPERTIES + IMPORTED_LOCATION "${_OIIO_libuhdr_LIBRARY}") + endif () + endif () + if ("@OIIO_TBB@") find_dependency(TBB) endif () endif ()