From 423b3b13943b29baa0a378d9a1ec3ce495d614e2 Mon Sep 17 00:00:00 2001 From: Cary Phillips Date: Wed, 4 Nov 2026 14:07:03 -0500 Subject: [PATCH 1/2] Accept a newer OpenJPH, and warn when an installed one is too old OpenEXR requires OpenJPH 0.32.0 or newer, but a system OpenJPH 0.33.0 was silently ignored in favor of the vendored 0.32.0 (#2806): - find_package(openjph 0.32.0 CONFIG) accepts only 0.32.x, since OpenJPH's config version file uses SameMinorVersion compatibility. Retry with the newest version find_package() considered that's 0.32.0 or newer. Checking the version after an unconstrained find_package() isn't an option: that loads the package even when it's then rejected, and the imported openjph target it defines clashes with the vendored one ("add_library cannot create target openjph because an imported target with the same name already exists"), so an installed OpenJPH that's too old, e.g. 0.30.1, would fail the configure. - pkg_check_modules() required exactly openjph=0.32.0; require openjph>=0.32.0 instead. When an OpenJPH that's too old is installed, the vendored one is still used, but with a warning naming the version found, rather than just "openjph was not found". Also: - Set the minimum OpenJPH version in one place: OPENEXR_MINIMUM_OPENJPH_VERSION. - Look for Threads even when OPENEXR_ENABLE_THREADING is OFF. OpenJPH 0.33.0's exported target links to Threads::Threads without its config looking for it, so configuring with threading off and an external OpenJPH 0.33.0 failed with "the target was not found". - Require zstd 1.5.0 or newer when it's found via pkg-config too, as find_package(zstd) already does. Addresses: https://github.com/AcademySoftwareFoundation/openexr/issues/2806 Assisted-by: Copilot / Claude Opus 5.5 Signed-off-by: Cary Phillips --- cmake/OpenEXRSetup.cmake | 73 +++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 12 deletions(-) diff --git a/cmake/OpenEXRSetup.cmake b/cmake/OpenEXRSetup.cmake index 174ffc58c7..ec4b939382 100644 --- a/cmake/OpenEXRSetup.cmake +++ b/cmake/OpenEXRSetup.cmake @@ -193,15 +193,17 @@ endif() ############################### # Dependent libraries -# so we know how to add the thread stuff to the pkg-config package -# which is the only (but good) reason. +# Look for Threads even when OPENEXR_ENABLE_THREADING is OFF: besides +# adding the thread flags to the pkg-config package, OpenJPH 0.33.0's +# exported target links to Threads::Threads without its config looking +# for it, so find_package(openjph) below fails without it. +if(NOT TARGET Threads::Threads) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads) +endif() if(OPENEXR_ENABLE_THREADING) - if(NOT TARGET Threads::Threads) - set(THREADS_PREFER_PTHREAD_FLAG ON) - find_package(Threads) - if(NOT Threads_FOUND) - message(FATAL_ERROR "Unable to find a threading library, disable with OPENEXR_ENABLE_THREADING=OFF") - endif() + if(NOT Threads_FOUND) + message(FATAL_ERROR "Unable to find a threading library, disable with OPENEXR_ENABLE_THREADING=OFF") endif() if(OPENEXR_USE_TBB) find_package(TBB) @@ -267,12 +269,40 @@ endif() ####################################### option(OPENEXR_FORCE_INTERNAL_OPENJPH "Force downloading OpenJPH from a git repo" OFF) +set(OPENEXR_MINIMUM_OPENJPH_VERSION 0.32.0) set(OPENEXR_USE_INTERNAL_OPENJPH 0 CACHE INTERNAL "Whether OpenEXR bundles vendored OpenJPH into OpenEXRCore (0 or 1)") if (NOT OPENEXR_FORCE_INTERNAL_OPENJPH) - find_package(openjph 0.32.0 CONFIG QUIET) + # Installed OpenJPH versions that are too old, for the warning below + set(_openexr_openjph_rejected) + + find_package(openjph ${OPENEXR_MINIMUM_OPENJPH_VERSION} CONFIG QUIET) + if(NOT openjph_FOUND) + # OpenJPH's config version file accepts only the requested + # major.minor version (SameMinorVersion), so the call above rejects + # a newer OpenJPH, e.g. 0.33.0 (#2806). Retry with the newest + # version that call considered that's new enough. Don't instead + # find_package() without a version and check it here: that loads + # the package, and the imported openjph target it defines would + # clash with the vendored one if the version is then rejected. + set(_openexr_openjph_version) + foreach(_v IN LISTS openjph_CONSIDERED_VERSIONS) + if(_v VERSION_GREATER_EQUAL OPENEXR_MINIMUM_OPENJPH_VERSION) + if(NOT _openexr_openjph_version OR _v VERSION_GREATER _openexr_openjph_version) + set(_openexr_openjph_version ${_v}) + endif() + elseif(_v) + list(APPEND _openexr_openjph_rejected ${_v}) + endif() + endforeach() + if(_openexr_openjph_version) + find_package(openjph ${_openexr_openjph_version} CONFIG QUIET) + endif() + unset(_openexr_openjph_version) + endif() + if(openjph_FOUND) message(STATUS "Using OpenJPH ${openjph_VERSION} from ${openjph_DIR}") set(EXR_OPENJPH_LIB openjph) @@ -281,19 +311,37 @@ if (NOT OPENEXR_FORCE_INTERNAL_OPENJPH) find_package(PkgConfig) if(PKG_CONFIG_FOUND) include(FindPkgConfig) - pkg_check_modules(openjph IMPORTED_TARGET GLOBAL QUIET openjph=0.32.0) + pkg_check_modules(openjph IMPORTED_TARGET GLOBAL QUIET + "openjph>=${OPENEXR_MINIMUM_OPENJPH_VERSION}") if(openjph_FOUND) set(EXR_OPENJPH_LIB PkgConfig::openjph) message(STATUS "Using OpenJPH ${openjph_VERSION} from ${openjph_LINK_LIBRARIES}") + else() + pkg_check_modules(_openexr_openjph_any QUIET openjph) + if(_openexr_openjph_any_FOUND) + list(APPEND _openexr_openjph_rejected ${_openexr_openjph_any_VERSION}) + endif() endif() endif() endif() + + if(NOT EXR_OPENJPH_LIB AND _openexr_openjph_rejected) + list(REMOVE_DUPLICATES _openexr_openjph_rejected) + list(JOIN _openexr_openjph_rejected ", " _openexr_openjph_rejected) + message(WARNING + "Found OpenJPH ${_openexr_openjph_rejected}, but OpenEXR requires " + "${OPENEXR_MINIMUM_OPENJPH_VERSION} or newer, so it's using its " + "vendored OpenJPH instead. Install a newer OpenJPH, or set " + "OPENEXR_FORCE_INTERNAL_OPENJPH=ON to use the vendored one " + "without this warning.") + endif() + unset(_openexr_openjph_rejected) endif() if(EXR_OPENJPH_LIB) # Using external library # For OpenEXR.pc.in for static build - set(EXR_OPENJPH_PKGCONFIG_REQUIRES "openjph >= 0.32.0") + set(EXR_OPENJPH_PKGCONFIG_REQUIRES "openjph >= ${OPENEXR_MINIMUM_OPENJPH_VERSION}") else() # Using internal openjph set(OPENEXR_USE_INTERNAL_OPENJPH 1 CACHE INTERNAL @@ -426,7 +474,8 @@ if(NOT OPENEXR_FORCE_INTERNAL_ZSTD) find_package(PkgConfig) if(PKG_CONFIG_FOUND) include(FindPkgConfig) - pkg_check_modules(libzstd IMPORTED_TARGET GLOBAL QUIET libzstd) + pkg_check_modules(libzstd IMPORTED_TARGET GLOBAL QUIET + "libzstd>=${OPENEXR_MINIMUM_ZSTD_VERSION}") if(libzstd_FOUND) set(EXR_ZSTD_LIB PkgConfig::libzstd) set(EXR_ZSTD_VERSION ${libzstd_VERSION}) From a35cd789bbe3b61e4e7b9f193cf973d5ca7f81c8 Mon Sep 17 00:00:00 2001 From: Cary Phillips Date: Sat, 7 Nov 2026 10:32:24 -0800 Subject: [PATCH 2/2] Scope the OpenJPH 0.33.0 Threads workaround to where it's needed The previous commit looked for Threads unconditionally, ahead of the threading block, to define Threads::Threads for OpenJPH 0.33.0's exported target (whose config omits find_dependency(Threads)). That had two drawbacks: it ran even with OPENEXR_FORCE_INTERNAL_OPENJPH=ON, where no find_package(openjph) happens, and it broke the OPENEXR_ENABLE_THREADING check for parent projects that already define Threads::Threads: the guarded find_package(Threads) was skipped, leaving Threads_FOUND unset, so the FATAL_ERROR fired even though threading was available. Restore the threading block to its original form (the FATAL_ERROR check back inside the NOT TARGET guard), and move the workaround into the external-OpenJPH branch, right before find_package(openjph), where it is the only thing that needs it. Document the upstream fix (aous72/OpenJPH#420) and that the shim must remain as long as OpenEXR 3.5 is supported, since 3.5 cannot raise the minimum OpenJPH version. Assisted-by: Copilot / Claude Opus 4.8 Signed-off-by: Cary Phillips --- cmake/OpenEXRSetup.cmake | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/cmake/OpenEXRSetup.cmake b/cmake/OpenEXRSetup.cmake index ec4b939382..3ff3f4d921 100644 --- a/cmake/OpenEXRSetup.cmake +++ b/cmake/OpenEXRSetup.cmake @@ -193,17 +193,15 @@ endif() ############################### # Dependent libraries -# Look for Threads even when OPENEXR_ENABLE_THREADING is OFF: besides -# adding the thread flags to the pkg-config package, OpenJPH 0.33.0's -# exported target links to Threads::Threads without its config looking -# for it, so find_package(openjph) below fails without it. -if(NOT TARGET Threads::Threads) - set(THREADS_PREFER_PTHREAD_FLAG ON) - find_package(Threads) -endif() +# so we know how to add the thread stuff to the pkg-config package +# which is the only (but good) reason. if(OPENEXR_ENABLE_THREADING) - if(NOT Threads_FOUND) - message(FATAL_ERROR "Unable to find a threading library, disable with OPENEXR_ENABLE_THREADING=OFF") + if(NOT TARGET Threads::Threads) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads) + if(NOT Threads_FOUND) + message(FATAL_ERROR "Unable to find a threading library, disable with OPENEXR_ENABLE_THREADING=OFF") + endif() endif() if(OPENEXR_USE_TBB) find_package(TBB) @@ -275,6 +273,22 @@ set(OPENEXR_USE_INTERNAL_OPENJPH 0 CACHE INTERNAL "Whether OpenEXR bundles vendored OpenJPH into OpenEXRCore (0 or 1)") if (NOT OPENEXR_FORCE_INTERNAL_OPENJPH) + # Workaround for OpenJPH 0.33.0: its exported CMake target links to + # Threads::Threads, but its installed package config does not + # find_dependency(Threads), so the find_package(openjph) below errors out + # on a missing Threads::Threads target when OpenEXR has not already + # created it (e.g. with OPENEXR_ENABLE_THREADING=OFF). Define it here. + # + # The upstream fix is https://github.com/aous72/OpenJPH/pull/420. This + # shim can be removed once OpenEXR's minimum OpenJPH + # (OPENEXR_MINIMUM_OPENJPH_VERSION) is a release that includes it. 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_package(Threads) + endif() + # Installed OpenJPH versions that are too old, for the warning below set(_openexr_openjph_rejected)