From cd9a08e1872adfd1320001ece511ed42a6bc16ce Mon Sep 17 00:00:00 2001 From: Cary Phillips Date: Sun, 8 Nov 2026 08:04:43 -0800 Subject: [PATCH] Find Threads in installed config before OpenJPH A threads-off OpenEXR built against a system OpenJPH 0.33.0 produced an installed OpenEXRConfig.cmake that broke downstream find_package(OpenEXR): CMake Error at .../openjph/openjph-targets.cmake (set_target_properties): The link interface of target "openjph" contains: Threads::Threads but the target was not found. OpenJPH 0.33.0's exported target links Threads::Threads, but its package config does not find_dependency(Threads). OpenEXRConfig.cmake only looked for Threads when OpenEXR itself was built with threading enabled, while find_dependency(openjph) runs whenever OpenJPH is external. So a consuming project that has not already found Threads -- a threads-off OpenEXR, or any downstream build that does not use threads itself -- failed when find_dependency(openjph) pulled in the openjph target. This mirrors the build-time workaround already present in OpenEXRSetup.cmake: define Threads::Threads before finding openjph when OpenJPH is external. Remove once OpenEXR's minimum OpenJPH includes aous72/OpenJPH#420; it must stay as long as 3.5 is supported, since 3.5 cannot raise the minimum. Assisted-by: Copilot / Claude Opus 4.8 Signed-off-by: Cary Phillips --- cmake/OpenEXRConfig.cmake.in | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmake/OpenEXRConfig.cmake.in b/cmake/OpenEXRConfig.cmake.in index fde1fd78e5..b2b79bcca4 100644 --- a/cmake/OpenEXRConfig.cmake.in +++ b/cmake/OpenEXRConfig.cmake.in @@ -36,6 +36,22 @@ if ("@EXR_OPENJPH_LIB@" STREQUAL "PkgConfig::openjph") openexr_find_pkgconfig_dependency(openjph "openjph=@openjph_VERSION@") endif() elseif (NOT @OPENEXR_USE_INTERNAL_OPENJPH@) + # Workaround for OpenJPH 0.33.0: its exported CMake target links to + # Threads::Threads, but its package config does not find_dependency(Threads), + # so the find_dependency(openjph) below fails in a consuming project that has + # not already found Threads. That includes an OpenEXR built with + # OPENEXR_ENABLE_THREADING=OFF (the block above did not look for Threads) and + # any downstream project that does not use threads itself. Define it here. + # + # This mirrors the equivalent build-time workaround in OpenEXRSetup.cmake. + # Remove once OpenEXR's minimum OpenJPH is a release that includes the + # upstream fix, https://github.com/aous72/OpenJPH/pull/420. Note that the + # OpenEXR 3.5 release cannot raise that minimum, so this must stay for as + # long as 3.5 is supported. + if (NOT TARGET Threads::Threads) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_dependency(Threads) + endif() find_dependency(openjph) endif()