| •1 |
# SPDX-License-Identifier: BSD-3-Clause |
| 2 |
# Copyright 2011 Blender Foundation. |
| 3 |
|
| 4 |
# - Find OpenEXR library |
| 5 |
# Find the native OpenEXR includes and library |
| 6 |
# This module defines |
| 7 |
# OPENEXR_INCLUDE_DIRS, where to find ImfXdr.h, etc. Set when |
| 8 |
# OPENEXR_INCLUDE_DIR is found. |
| 9 |
# OPENEXR_LIBRARIES, libraries to link against to use OpenEXR. |
| 10 |
# OPENEXR_ROOT_DIR, The base directory to search for OpenEXR. |
| 11 |
# This can also be an environment variable. |
| 12 |
# OPENEXR_FOUND, If false, do not try to use OpenEXR. |
| 13 |
# |
| 14 |
# For individual library access these advanced settings are available |
| 15 |
# OPENEXR_HALF_LIBRARY, Path to Half library |
| 16 |
# OPENEXR_IEX_LIBRARY, Path to Half library |
| 17 |
# OPENEXR_ILMIMF_LIBRARY, Path to Ilmimf library |
| 18 |
# OPENEXR_ILMTHREAD_LIBRARY, Path to IlmThread library |
| 19 |
# OPENEXR_IMATH_LIBRARY, Path to Imath library |
| 20 |
# |
| 21 |
# also defined, but not for general use are |
| 22 |
# OPENEXR_LIBRARY, where to find the OpenEXR library. |
| 23 |
|
| 24 |
# If OPENEXR_ROOT_DIR was defined in the environment, use it. |
| 25 |
IF(NOT OPENEXR_ROOT_DIR AND NOT $ENV{OPENEXR_ROOT_DIR} STREQUAL "") |
| 26 |
SET(OPENEXR_ROOT_DIR $ENV{OPENEXR_ROOT_DIR}) |
| 27 |
ENDIF() |
| 28 |
|
| •29 |
# Old versions (before 2.0?) do not have any version string, just assuming this should be fine though. |
| 30 |
SET(_openexr_libs_ver_init "2.0") |
| 31 |
|
| 32 |
SET(_openexr_SEARCH_DIRS |
| 33 |
${OPENEXR_ROOT_DIR} |
| •34 |
/opt/lib/openexr |
| 35 |
) |
| 36 |
|
| 37 |
FIND_PATH(OPENEXR_INCLUDE_DIR |
| 38 |
NAMES |
| 39 |
OpenEXR/ImfXdr.h |
| 40 |
HINTS |
| 41 |
${_openexr_SEARCH_DIRS} |
| 42 |
PATH_SUFFIXES |
| 43 |
include |
| 44 |
) |
| 45 |
|
| •46 |
# If the headers were found, get the version from config file, if not already set. |
| 47 |
IF(OPENEXR_INCLUDE_DIR) |
| 48 |
IF(NOT OPENEXR_VERSION) |
| 49 |
|
| 50 |
FIND_FILE(_openexr_CONFIG |
| 51 |
NAMES |
| 52 |
OpenEXRConfig.h |
| 53 |
PATHS |
| 54 |
"${OPENEXR_INCLUDE_DIR}" |
| 55 |
"${OPENEXR_INCLUDE_DIR}/OpenEXR" |
| 56 |
NO_DEFAULT_PATH |
| 57 |
) |
| 58 |
|
| 59 |
IF(_openexr_CONFIG) |
| 60 |
FILE(STRINGS "${_openexr_CONFIG}" OPENEXR_BUILD_SPECIFICATION |
| 61 |
REGEX "^[ \t]*#define[ \t]+OPENEXR_VERSION_STRING[ \t]+\"[.0-9]+\".*$") |
| 62 |
ELSE() |
| 63 |
MESSAGE(WARNING "Could not find \"OpenEXRConfig.h\" in \"${OPENEXR_INCLUDE_DIR}\"") |
| 64 |
ENDIF() |
| 65 |
|
| 66 |
IF(OPENEXR_BUILD_SPECIFICATION) |
| 67 |
MESSAGE(STATUS "${OPENEXR_BUILD_SPECIFICATION}") |
| 68 |
STRING(REGEX REPLACE ".*#define[ \t]+OPENEXR_VERSION_STRING[ \t]+\"([.0-9]+)\".*" |
| 69 |
"\\1" _openexr_libs_ver_init ${OPENEXR_BUILD_SPECIFICATION}) |
| 70 |
ELSE() |
| 71 |
MESSAGE(WARNING "Could not determine ILMBase library version, assuming ${_openexr_libs_ver_init}.") |
| 72 |
ENDIF() |
| 73 |
|
| 74 |
UNSET(_openexr_CONFIG CACHE) |
| 75 |
|
| 76 |
ENDIF() |
| 77 |
ENDIF() |
| 78 |
|
| 79 |
SET("OPENEXR_VERSION" ${_openexr_libs_ver_init} CACHE STRING "Version of OpenEXR lib") |
| 80 |
UNSET(_openexr_libs_ver_init) |
| 81 |
|
| 82 |
STRING(REGEX REPLACE "([0-9]+)[.]([0-9]+).*" "\\1_\\2" _openexr_libs_ver ${OPENEXR_VERSION}) |
| 83 |
|
| 84 |
# Different library names in 3.0, and Imath and Half moved out. |
| 85 |
IF(OPENEXR_VERSION VERSION_GREATER_EQUAL "3.0.0") |
| 86 |
SET(_openexr_FIND_COMPONENTS |
| 87 |
Iex |
| 88 |
OpenEXR |
| 89 |
OpenEXRCore |
| 90 |
IlmThread |
| 91 |
) |
| 92 |
ELSE() |
| 93 |
SET(_openexr_FIND_COMPONENTS |
| 94 |
Half |
| 95 |
Iex |
| 96 |
IlmImf |
| 97 |
IlmThread |
| 98 |
Imath |
| 99 |
) |
| 100 |
ENDIF() |
| 101 |
|
| 102 |
SET(_openexr_LIBRARIES) |
| 103 |
FOREACH(COMPONENT ${_openexr_FIND_COMPONENTS}) |
| 104 |
STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT) |
| 105 |
|
| 106 |
FIND_LIBRARY(OPENEXR_${UPPERCOMPONENT}_LIBRARY |
| 107 |
NAMES |
| •108 |
${COMPONENT}-${_openexr_libs_ver} ${COMPONENT} |
| 109 |
NAMES_PER_DIR |
| 110 |
HINTS |
| 111 |
${_openexr_SEARCH_DIRS} |
| 112 |
PATH_SUFFIXES |
| 113 |
lib64 lib |
| 114 |
) |
| 115 |
LIST(APPEND _openexr_LIBRARIES "${OPENEXR_${UPPERCOMPONENT}_LIBRARY}") |
| 116 |
ENDFOREACH() |
| 117 |
|
| •118 |
UNSET(_openexr_libs_ver) |
| 119 |
|
| 120 |
IF(OPENEXR_VERSION VERSION_GREATER_EQUAL "3.0.0") |
| 121 |
# For OpenEXR 3.x, we also need to find the now separate Imath library. |
| 122 |
# For simplicity we add it to the OpenEXR includes and libraries, as we |
| 123 |
# have no direct dependency on Imath and it's simpler to support both |
| 124 |
# 2.x and 3.x this way. |
| 125 |
|
| 126 |
# Find include directory |
| 127 |
FIND_PATH(IMATH_INCLUDE_DIR |
| 128 |
NAMES |
| 129 |
Imath/ImathMath.h |
| 130 |
HINTS |
| 131 |
${_openexr_SEARCH_DIRS} |
| 132 |
PATH_SUFFIXES |
| 133 |
include |
| 134 |
) |
| 135 |
|
| 136 |
# Find version |
| 137 |
FIND_FILE(_imath_config |
| 138 |
NAMES |
| 139 |
ImathConfig.h |
| 140 |
PATHS |
| 141 |
${IMATH_INCLUDE_DIR}/Imath |
| 142 |
NO_DEFAULT_PATH |
| 143 |
) |
| 144 |
|
| 145 |
# Find line with version, extract string, and format for library suffix. |
| 146 |
FILE(STRINGS "${_imath_config}" _imath_build_specification |
| 147 |
REGEX "^[ \t]*#define[ \t]+IMATH_VERSION_STRING[ \t]+\"[.0-9]+\".*$") |
| 148 |
STRING(REGEX REPLACE ".*#define[ \t]+IMATH_VERSION_STRING[ \t]+\"([.0-9]+)\".*" |
| 149 |
"\\1" _imath_libs_ver ${_imath_build_specification}) |
| 150 |
STRING(REGEX REPLACE "([0-9]+)[.]([0-9]+).*" "\\1_\\2" _imath_libs_ver ${_imath_libs_ver}) |
| 151 |
|
| 152 |
# Find library, with or without version number. |
| 153 |
FIND_LIBRARY(IMATH_LIBRARY |
| 154 |
NAMES |
| 155 |
Imath-${_imath_libs_ver} Imath |
| 156 |
NAMES_PER_DIR |
| 157 |
HINTS |
| 158 |
${_openexr_SEARCH_DIRS} |
| 159 |
PATH_SUFFIXES |
| 160 |
lib64 lib |
| 161 |
) |
| 162 |
LIST(APPEND _openexr_LIBRARIES "${IMATH_LIBRARY}") |
| 163 |
|
| 164 |
# In cmake version 3.21 and up, we can instead use the NO_CACHE option for |
| 165 |
# FIND_FILE so we don't need to clear it from the cache here. |
| 166 |
UNSET(_imath_config CACHE) |
| 167 |
UNSET(_imath_libs_ver) |
| 168 |
UNSET(_imath_build_specification) |
| 169 |
ENDIF() |
| 170 |
|
| 171 |
# handle the QUIETLY and REQUIRED arguments and set OPENEXR_FOUND to TRUE if |
| 172 |
# all listed variables are TRUE |
| 173 |
INCLUDE(FindPackageHandleStandardArgs) |
| 174 |
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenEXR DEFAULT_MSG |
| 175 |
_openexr_LIBRARIES OPENEXR_INCLUDE_DIR) |
| 176 |
|
| 177 |
IF(OPENEXR_FOUND) |
| 178 |
SET(OPENEXR_LIBRARIES ${_openexr_LIBRARIES}) |
| •179 |
# Both include paths are needed because of dummy OSL headers mixing |
| 180 |
# #include <OpenEXR/foo.h> and #include <foo.h>, as well as Alembic |
| 181 |
# include <half.h> directly. |
| 182 |
SET(OPENEXR_INCLUDE_DIRS |
| 183 |
${OPENEXR_INCLUDE_DIR} |
| 184 |
${OPENEXR_INCLUDE_DIR}/OpenEXR) |
| 185 |
|
| 186 |
IF(OPENEXR_VERSION VERSION_GREATER_EQUAL "3.0.0") |
| 187 |
LIST(APPEND OPENEXR_INCLUDE_DIRS |
| 188 |
${IMATH_INCLUDE_DIR} |
| 189 |
${IMATH_INCLUDE_DIR}/Imath) |
| 190 |
ENDIF() |
| 191 |
ENDIF() |
| 192 |
|
| •193 |
MARK_AS_ADVANCED( |
| 194 |
OPENEXR_INCLUDE_DIR |
| 195 |
OPENEXR_VERSION |
| 196 |
IMATH_INCLUDE_DIR |
| 197 |
IMATH_LIBRARY |
| 198 |
) |
| 199 |
FOREACH(COMPONENT ${_openexr_FIND_COMPONENTS}) |
| 200 |
STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT) |
| 201 |
MARK_AS_ADVANCED(OPENEXR_${UPPERCOMPONENT}_LIBRARY) |
| 202 |
ENDFOREACH() |
| •203 |
|
| 204 |
UNSET(COMPONENT) |
| 205 |
UNSET(UPPERCOMPONENT) |
| 206 |
UNSET(_openexr_FIND_COMPONENTS) |
| 207 |
UNSET(_openexr_LIBRARIES) |
| 208 |
UNSET(_openexr_SEARCH_DIRS) |