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/Config.cmake.in b/src/cmake/Config.cmake.in index 080a499968..456d69c5d3 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -20,20 +20,73 @@ 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 () + # 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 () 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) diff --git a/src/cmake/externalpackages.cmake b/src/cmake/externalpackages.cmake index 107b8ad255..6fe1a891b1 100644 --- a/src/cmake/externalpackages.cmake +++ b/src/cmake/externalpackages.cmake @@ -90,6 +90,18 @@ endif () checked_find_package (libuhdr VERSION_MIN 1.3) +# 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) + 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 () + checked_find_package (TIFF REQUIRED VERSION_MIN 4.0 RECOMMEND_MIN 4.5