2023-08-15 14:20:26 +00:00
|
|
|
# SPDX-FileCopyrightText: 2011 Blender Authors
|
2023-06-14 12:49:59 +00:00
|
|
|
#
|
2022-02-11 03:23:56 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2011-06-16 02:55:26 +00:00
|
|
|
# - Find OpenEXR library
|
2011-06-15 12:09:02 +00:00
|
|
|
# Find the native OpenEXR includes and library
|
|
|
|
# This module defines
|
|
|
|
# OPENEXR_INCLUDE_DIRS, where to find ImfXdr.h, etc. Set when
|
|
|
|
# OPENEXR_INCLUDE_DIR is found.
|
|
|
|
# OPENEXR_LIBRARIES, libraries to link against to use OpenEXR.
|
|
|
|
# OPENEXR_ROOT_DIR, The base directory to search for OpenEXR.
|
|
|
|
# This can also be an environment variable.
|
|
|
|
# OPENEXR_FOUND, If false, do not try to use OpenEXR.
|
2011-06-16 02:48:07 +00:00
|
|
|
#
|
2012-02-17 19:21:47 +00:00
|
|
|
# For individual library access these advanced settings are available
|
2011-06-16 02:48:07 +00:00
|
|
|
# OPENEXR_HALF_LIBRARY, Path to Half library
|
|
|
|
# OPENEXR_IEX_LIBRARY, Path to Half library
|
|
|
|
# OPENEXR_ILMIMF_LIBRARY, Path to Ilmimf library
|
|
|
|
# OPENEXR_ILMTHREAD_LIBRARY, Path to IlmThread library
|
|
|
|
# OPENEXR_IMATH_LIBRARY, Path to Imath library
|
|
|
|
#
|
2011-06-15 12:09:02 +00:00
|
|
|
# also defined, but not for general use are
|
|
|
|
# OPENEXR_LIBRARY, where to find the OpenEXR library.
|
|
|
|
|
2023-07-29 03:47:55 +00:00
|
|
|
# If `OPENEXR_ROOT_DIR` was defined in the environment, use it.
|
2023-08-17 03:15:56 +00:00
|
|
|
if(DEFINED OPENEXR_ROOT_DIR)
|
2023-07-29 03:47:55 +00:00
|
|
|
# Pass.
|
2023-08-17 03:15:56 +00:00
|
|
|
elseif(DEFINED ENV{OPENEXR_ROOT_DIR})
|
|
|
|
set(OPENEXR_ROOT_DIR $ENV{OPENEXR_ROOT_DIR})
|
|
|
|
else()
|
|
|
|
set(OPENEXR_ROOT_DIR "")
|
|
|
|
endif()
|
2011-06-15 12:09:02 +00:00
|
|
|
|
2022-11-03 01:10:16 +00:00
|
|
|
# Old versions (before 2.0?) do not have any version string,
|
|
|
|
# just assuming this should be fine though.
|
2023-08-17 03:15:56 +00:00
|
|
|
set(_openexr_libs_ver_init "2.0")
|
2014-07-19 13:59:51 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
set(_openexr_SEARCH_DIRS
|
2013-12-16 20:00:35 +00:00
|
|
|
${OPENEXR_ROOT_DIR}
|
2015-01-28 18:36:09 +00:00
|
|
|
/opt/lib/openexr
|
2013-12-16 20:00:35 +00:00
|
|
|
)
|
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
find_path(OPENEXR_INCLUDE_DIR
|
2013-12-16 20:00:35 +00:00
|
|
|
NAMES
|
|
|
|
OpenEXR/ImfXdr.h
|
|
|
|
HINTS
|
|
|
|
${_openexr_SEARCH_DIRS}
|
|
|
|
PATH_SUFFIXES
|
|
|
|
include
|
|
|
|
)
|
|
|
|
|
|
|
|
# If the headers were found, get the version from config file, if not already set.
|
2023-08-17 03:15:56 +00:00
|
|
|
if(OPENEXR_INCLUDE_DIR)
|
|
|
|
if(NOT OPENEXR_VERSION)
|
2014-01-04 02:12:45 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
find_file(_openexr_CONFIG
|
2014-01-04 02:12:45 +00:00
|
|
|
NAMES
|
|
|
|
OpenEXRConfig.h
|
|
|
|
PATHS
|
|
|
|
"${OPENEXR_INCLUDE_DIR}"
|
|
|
|
"${OPENEXR_INCLUDE_DIR}/OpenEXR"
|
|
|
|
NO_DEFAULT_PATH
|
|
|
|
)
|
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
if(_openexr_CONFIG)
|
|
|
|
file(STRINGS "${_openexr_CONFIG}" OPENEXR_BUILD_SPECIFICATION
|
2014-01-04 02:12:45 +00:00
|
|
|
REGEX "^[ \t]*#define[ \t]+OPENEXR_VERSION_STRING[ \t]+\"[.0-9]+\".*$")
|
2023-08-17 03:15:56 +00:00
|
|
|
else()
|
|
|
|
message(WARNING "Could not find \"OpenEXRConfig.h\" in \"${OPENEXR_INCLUDE_DIR}\"")
|
|
|
|
endif()
|
2013-12-16 20:00:35 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
if(OPENEXR_BUILD_SPECIFICATION)
|
|
|
|
message(STATUS "${OPENEXR_BUILD_SPECIFICATION}")
|
|
|
|
string(REGEX REPLACE ".*#define[ \t]+OPENEXR_VERSION_STRING[ \t]+\"([.0-9]+)\".*"
|
2014-07-19 13:59:51 +00:00
|
|
|
"\\1" _openexr_libs_ver_init ${OPENEXR_BUILD_SPECIFICATION})
|
2023-08-17 03:15:56 +00:00
|
|
|
else()
|
|
|
|
message(WARNING "Could not determine ILMBase library version, assuming ${_openexr_libs_ver_init}.")
|
|
|
|
endif()
|
2014-01-04 02:12:45 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
unset(_openexr_CONFIG CACHE)
|
2014-01-04 02:12:45 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
2013-12-16 20:00:35 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
set("OPENEXR_VERSION" ${_openexr_libs_ver_init} CACHE STRING "Version of OpenEXR lib")
|
|
|
|
unset(_openexr_libs_ver_init)
|
2014-07-19 13:59:51 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
string(REGEX REPLACE "([0-9]+)[.]([0-9]+).*" "\\1_\\2" _openexr_libs_ver ${OPENEXR_VERSION})
|
2011-06-15 12:09:02 +00:00
|
|
|
|
2022-02-16 16:38:44 +00:00
|
|
|
# Different library names in 3.0, and Imath and Half moved out.
|
2023-08-17 03:15:56 +00:00
|
|
|
if(OPENEXR_VERSION VERSION_GREATER_EQUAL "3.0.0")
|
|
|
|
set(_openexr_FIND_COMPONENTS
|
2022-02-16 16:38:44 +00:00
|
|
|
Iex
|
|
|
|
OpenEXR
|
|
|
|
OpenEXRCore
|
2022-04-19 16:09:05 +00:00
|
|
|
IlmThread
|
2022-02-16 16:38:44 +00:00
|
|
|
)
|
2023-08-17 03:15:56 +00:00
|
|
|
else()
|
|
|
|
set(_openexr_FIND_COMPONENTS
|
2022-02-16 16:38:44 +00:00
|
|
|
Half
|
|
|
|
Iex
|
|
|
|
IlmImf
|
|
|
|
IlmThread
|
|
|
|
Imath
|
|
|
|
)
|
2023-08-17 03:15:56 +00:00
|
|
|
endif()
|
2022-02-16 16:38:44 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
set(_openexr_LIBRARIES)
|
|
|
|
foreach(COMPONENT ${_openexr_FIND_COMPONENTS})
|
|
|
|
string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
|
2011-06-15 12:09:02 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
find_library(OPENEXR_${UPPERCOMPONENT}_LIBRARY
|
2011-06-20 02:54:56 +00:00
|
|
|
NAMES
|
2018-06-10 06:12:13 +00:00
|
|
|
${COMPONENT}-${_openexr_libs_ver} ${COMPONENT}
|
2020-05-12 08:46:16 +00:00
|
|
|
NAMES_PER_DIR
|
2011-06-20 02:54:56 +00:00
|
|
|
HINTS
|
|
|
|
${_openexr_SEARCH_DIRS}
|
|
|
|
PATH_SUFFIXES
|
|
|
|
lib64 lib
|
|
|
|
)
|
2023-08-17 03:15:56 +00:00
|
|
|
list(APPEND _openexr_LIBRARIES "${OPENEXR_${UPPERCOMPONENT}_LIBRARY}")
|
|
|
|
endforeach()
|
2011-06-15 12:09:02 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
unset(_openexr_libs_ver)
|
2014-01-14 19:36:53 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
if(OPENEXR_VERSION VERSION_GREATER_EQUAL "3.0.0")
|
2022-02-16 16:38:44 +00:00
|
|
|
# For OpenEXR 3.x, we also need to find the now separate Imath library.
|
2023-04-03 07:50:50 +00:00
|
|
|
# For simplicity we also add it to the OpenEXR includes and libraries,
|
|
|
|
# as it's simpler to support both 2.x and 3.x this way.
|
2022-02-16 16:38:44 +00:00
|
|
|
|
|
|
|
# Find include directory
|
2023-08-17 03:15:56 +00:00
|
|
|
find_path(IMATH_INCLUDE_DIR
|
2022-02-16 16:38:44 +00:00
|
|
|
NAMES
|
|
|
|
Imath/ImathMath.h
|
|
|
|
HINTS
|
|
|
|
${_openexr_SEARCH_DIRS}
|
|
|
|
PATH_SUFFIXES
|
|
|
|
include
|
|
|
|
)
|
|
|
|
|
|
|
|
# Find version
|
2023-08-17 03:15:56 +00:00
|
|
|
find_file(_imath_config
|
2022-02-16 16:38:44 +00:00
|
|
|
NAMES
|
|
|
|
ImathConfig.h
|
|
|
|
PATHS
|
|
|
|
${IMATH_INCLUDE_DIR}/Imath
|
|
|
|
NO_DEFAULT_PATH
|
|
|
|
)
|
|
|
|
|
|
|
|
# Find line with version, extract string, and format for library suffix.
|
2023-08-17 03:15:56 +00:00
|
|
|
file(STRINGS "${_imath_config}" _imath_build_specification
|
2022-02-16 16:38:44 +00:00
|
|
|
REGEX "^[ \t]*#define[ \t]+IMATH_VERSION_STRING[ \t]+\"[.0-9]+\".*$")
|
2023-08-17 03:15:56 +00:00
|
|
|
string(REGEX REPLACE ".*#define[ \t]+IMATH_VERSION_STRING[ \t]+\"([.0-9]+)\".*"
|
2022-02-16 16:38:44 +00:00
|
|
|
"\\1" _imath_libs_ver ${_imath_build_specification})
|
2023-08-17 03:15:56 +00:00
|
|
|
string(REGEX REPLACE "([0-9]+)[.]([0-9]+).*" "\\1_\\2" _imath_libs_ver ${_imath_libs_ver})
|
2022-02-16 16:38:44 +00:00
|
|
|
|
|
|
|
# Find library, with or without version number.
|
2023-08-17 03:15:56 +00:00
|
|
|
find_library(IMATH_LIBRARY
|
2022-02-16 16:38:44 +00:00
|
|
|
NAMES
|
|
|
|
Imath-${_imath_libs_ver} Imath
|
|
|
|
NAMES_PER_DIR
|
|
|
|
HINTS
|
|
|
|
${_openexr_SEARCH_DIRS}
|
|
|
|
PATH_SUFFIXES
|
|
|
|
lib64 lib
|
|
|
|
)
|
2023-08-17 03:15:56 +00:00
|
|
|
list(APPEND _openexr_LIBRARIES "${IMATH_LIBRARY}")
|
2022-02-16 16:38:44 +00:00
|
|
|
|
|
|
|
# In cmake version 3.21 and up, we can instead use the NO_CACHE option for
|
|
|
|
# FIND_FILE so we don't need to clear it from the cache here.
|
2023-08-17 03:15:56 +00:00
|
|
|
unset(_imath_config CACHE)
|
|
|
|
unset(_imath_libs_ver)
|
|
|
|
unset(_imath_build_specification)
|
|
|
|
endif()
|
2022-02-16 16:38:44 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
if(OPENEXR_VERSION VERSION_GREATER_EQUAL "3.0.0")
|
2024-01-14 00:36:47 +00:00
|
|
|
set(IMATH_LIBRARIES ${IMATH_LIBRARY})
|
2023-08-17 03:15:56 +00:00
|
|
|
else()
|
2024-01-14 00:36:47 +00:00
|
|
|
set(IMATH_LIBRARIES ${OPENEXR_IMATH_LIBRARY})
|
2023-08-17 03:15:56 +00:00
|
|
|
endif()
|
2023-04-03 07:50:50 +00:00
|
|
|
|
2018-06-10 06:12:13 +00:00
|
|
|
# handle the QUIETLY and REQUIRED arguments and set OPENEXR_FOUND to TRUE if
|
2011-06-15 12:09:02 +00:00
|
|
|
# all listed variables are TRUE
|
2023-08-17 03:15:56 +00:00
|
|
|
include(FindPackageHandleStandardArgs)
|
|
|
|
find_package_handle_standard_args(OpenEXR DEFAULT_MSG
|
2011-06-16 02:48:07 +00:00
|
|
|
_openexr_LIBRARIES OPENEXR_INCLUDE_DIR)
|
2011-06-15 12:09:02 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
if(OPENEXR_FOUND)
|
|
|
|
set(OPENEXR_LIBRARIES ${_openexr_LIBRARIES})
|
2022-02-16 16:38:44 +00:00
|
|
|
# Both include paths are needed because of dummy OSL headers mixing
|
|
|
|
# #include <OpenEXR/foo.h> and #include <foo.h>, as well as Alembic
|
|
|
|
# include <half.h> directly.
|
2023-08-17 03:15:56 +00:00
|
|
|
set(OPENEXR_INCLUDE_DIRS
|
2022-02-16 16:38:44 +00:00
|
|
|
${OPENEXR_INCLUDE_DIR}
|
|
|
|
${OPENEXR_INCLUDE_DIR}/OpenEXR)
|
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
if(OPENEXR_VERSION VERSION_GREATER_EQUAL "3.0.0")
|
|
|
|
list(APPEND OPENEXR_INCLUDE_DIRS
|
2022-02-16 16:38:44 +00:00
|
|
|
${IMATH_INCLUDE_DIR}
|
|
|
|
${IMATH_INCLUDE_DIR}/Imath)
|
2023-08-17 03:15:56 +00:00
|
|
|
endif()
|
2023-12-22 10:25:30 +00:00
|
|
|
|
|
|
|
set(IMATH_INCLUDE_DIRS
|
|
|
|
${IMATH_INCLUDE_DIR})
|
2023-08-17 03:15:56 +00:00
|
|
|
endif()
|
2011-06-15 12:09:02 +00:00
|
|
|
|
2023-08-17 03:15:56 +00:00
|
|
|
mark_as_advanced(
|
2014-05-05 20:03:52 +00:00
|
|
|
OPENEXR_INCLUDE_DIR
|
|
|
|
OPENEXR_VERSION
|
2022-02-16 16:38:44 +00:00
|
|
|
IMATH_INCLUDE_DIR
|
|
|
|
IMATH_LIBRARY
|
2023-04-03 07:50:50 +00:00
|
|
|
IMATH_LIBRARIES
|
2014-05-05 20:03:52 +00:00
|
|
|
)
|
2023-08-17 03:15:56 +00:00
|
|
|
foreach(COMPONENT ${_openexr_FIND_COMPONENTS})
|
|
|
|
string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
|
|
|
|
mark_as_advanced(OPENEXR_${UPPERCOMPONENT}_LIBRARY)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
unset(COMPONENT)
|
|
|
|
unset(UPPERCOMPONENT)
|
|
|
|
unset(_openexr_FIND_COMPONENTS)
|
|
|
|
unset(_openexr_LIBRARIES)
|
|
|
|
unset(_openexr_SEARCH_DIRS)
|