@@ -256,8 +256,6 @@ endif()
256256#######################################
257257
258258option (OPENEXR_FORCE_INTERNAL_OPENJPH "Force downloading OpenJPH from a git repo" OFF )
259- set (OPENEXR_OPENJPH_REPO "https://github.com/aous72/OpenJPH.git" CACHE STRING "OpenJPH git repo URI" )
260- set (OPENEXR_OPENJPH_TAG "master" CACHE STRING "OpenJPH git repo tag" )
261259
262260if (NOT OPENEXR_FORCE_INTERNAL_OPENJPH)
263261 find_package (openjph CONFIG QUIET )
@@ -276,68 +274,21 @@ if (NOT OPENEXR_FORCE_INTERNAL_OPENJPH)
276274 pkg_check_modules(openjph IMPORTED_TARGET GLOBAL QUIET openjph=0.21)
277275 if (openjph_FOUND)
278276 set (EXR_OPENJPH_LIB PkgConfig::openjph)
279- message (STATUS "Using OpenJPH from ${openjph_LINK_LIBRARIES} " )
277+ message (STATUS "Using OpenJPH ${openjph_VERSION} from ${openjph_LINK_LIBRARIES} " )
280278 endif ()
281279 endif ()
282280 endif ()
283281endif ()
284282
285- if (NOT EXR_OPENJPH_LIB)
286- # Using internal OpenJPH
287- if (OPENEXR_FORCE_INTERNAL_OPENJPH)
288- message (STATUS "OpenJPH forced internal, fetching from ${OPENEXR_OPENJPH_REPO} @ ${OPENEXR_OPENJPH_TAG} " )
289- else ()
290- message (STATUS "OpenJPH was not found, fetching from ${OPENEXR_OPENJPH_REPO} @ ${OPENEXR_OPENJPH_TAG} " )
291- endif ()
292-
293- include (FetchContent)
294- FetchContent_Declare(
295- openjph
296- GIT_REPOSITORY ${OPENEXR_OPENJPH_REPO}
297- GIT_TAG ${OPENEXR_OPENJPH_TAG}
298- )
299-
300- set (OJPH_BUILD_TESTS OFF CACHE BOOL "" FORCE)
301- set (OJPH_ENABLE_TIFF_SUPPORT OFF CACHE BOOL "" FORCE)
302- set (OJPH_BUILD_EXECUTABLES OFF CACHE BOOL "" FORCE)
303- FetchContent_MakeAvailable(openjph)
304- install (
305- TARGETS openjph
306- EXPORT ${PROJECT_NAME}
307- )
308- set_target_properties (openjph PROPERTIES
309- POSITION_INDEPENDENT_CODE ON
310- RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /bin"
311- )
312-
313- # OpenEXR expects OpenJPH headers to live in an openjph folder,
314- # so OpenEXR's include looks like:
315- # #include <openjph/openjph_arch.h>
316- # However, when building OpenJPH via FetchContent, the headers
317- # reside in src/core/common directory in the OpenJPH source tree.
318- # Create a symlink called "openjph" that points to "common", so the
319- # OpenEXR includes see the files they expect.
320- # Then add that as the include directory.
321- #
322- # NOTE: This can go away when we vendor in the OpenJPH code and
323- # retire the FetchContent altogether.
324- file (CREATE_LINK
325- "${openjph_SOURCE_DIR} /src/core/common"
326- "${openjph_SOURCE_DIR} /src/core/openjph"
327- RESULT openjph_create_link_result
328- SYMBOLIC
329- )
330- # Creating a symlink may fail, for example on Windows without developer
331- # mode enabled, so fallback to copying in that case.
332- if (NOT openjph_create_link_result EQUAL 0)
333- file (COPY
334- "${openjph_SOURCE_DIR} /src/core/common/"
335- DESTINATION "${openjph_SOURCE_DIR} /src/core/openjph"
336- )
337- endif ()
338- include_directories ("${openjph_SOURCE_DIR} /src/core" )
283+ if (EXR_OPENJPH_LIB)
284+ # Using external library
285+ # For OpenEXR.pc.in for static build
286+ set (EXR_OPENJPH_PKGCONFIG_REQUIRES "openjph >= 0.21.0" )
287+ else ()
288+ # Using internal openjph
339289
340290 # extract the openjph version variables from ojph_version.h
291+ set (openjph_SOURCE_DIR "${CMAKE_SOURCE_DIR} /external/openjph" )
341292 set (openjph_version "${openjph_SOURCE_DIR} /src/core/common/ojph_version.h" )
342293 if (EXISTS "${openjph_version} " )
343294 file (STRINGS "${openjph_version} " _openjph_major REGEX "#define OPENJPH_VERSION_MAJOR" )
@@ -348,31 +299,15 @@ if(NOT EXR_OPENJPH_LIB)
348299 string (REGEX REPLACE ".*OPENJPH_VERSION_PATCH[ \t ]+([0-9]+).*" "\\ 1" openjph_VERSION_PATCH "${_openjph_patch} " )
349300 endif ()
350301
351- set (EXR_OPENJPH_LIB openjph)
352- endif ()
353-
354- if (NOT EXR_OPENJPH_LIB)
355- message (ERROR "Failed to find OpenJPH" )
356- endif ()
357-
358- if (openjph_VERSION VERSION_LESS "0.23" )
359- # OpenJPH 0.22 and before incorrectly appends "openjph" to INTERFACE_INCLUDE_DIRECTORIES
360- # so OpenEXR's "#include <openjph/ojph_arch.h>" does not work.
361- # Strip the "openjph" from the setting in this case. This allows the
362- # #include statements in OpenEXRCore/internal_ht.cpp to work properly for all openjph versions.
363- get_target_property (OPENJPH_INCLUDE_DIR openjph INTERFACE_INCLUDE_DIRECTORIES )
364- if (NOT OPENJPH_INCLUDE_DIR)
365- message (FATAL_ERROR "failed to set openjph header directory, version ${openjph_VERSION} " )
302+ set (openjph_VERSION "${openjph_VERSION_MAJOR} .${openjph_VERSION_MINOR} .${openjph_VERSION_PATCH} " )
303+
304+ if (OPENEXR_FORCE_INTERNAL_OPENJPH)
305+ message (STATUS "openjph forced internal, using vendored code (${openjph_VERSION} )" )
306+ else ()
307+ message (STATUS "openjph was not found, using vendored code (${openjph_VERSION} )" )
366308 endif ()
367- string (REGEX REPLACE "/openjph/?$" "" OPENJPH_PARENT_INCLUDE_DIR "${OPENJPH_INCLUDE_DIR} " )
368- set_target_properties (openjph PROPERTIES
369- INTERFACE_INCLUDE_DIRECTORIES "${OPENJPH_PARENT_INCLUDE_DIR} "
370- )
371- unset (OPENJPH_INCLUDE_DIR)
372- unset (OPENJPH_PARENT_INCLUDE_DIR)
373- endif ()
374309
375- set (EXR_OPENJPH_PKGCONFIG_REQUIRES "openjph >= 0.21.0" )
310+ endif ( )
376311
377312#######################################
378313# Find or install Imath
0 commit comments