Warning, /graphics/krita/cmake/modules/FindOpenEXR.cmake is written in an unsupported language. File is not indexed.

0001 # SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me>
0002 # SPDX-FileCopyrightText: 2013-2014 Alex Merry <alex.merry@kdemail.net>
0003 # SPDX-FileCopyrightText: 2006 Alexander Neundorf <neundorf@kde.org>
0004 #
0005 # SPDX-License-Identifier: BSD-3-Clause
0006 
0007 #[=======================================================================[.rst:
0008 FindOpenEXR
0009 -----------
0010 
0011 Try to find the OpenEXR libraries.
0012 
0013 This will define the following variables:
0014 
0015 ``OpenEXR_FOUND``
0016     True if OpenEXR is available
0017 ``OpenEXR_LIBRARIES``
0018     Link to these to use OpenEXR
0019 ``OpenEXR_INCLUDE_DIRS``
0020     Include directory for OpenEXR
0021 ``OpenEXR_DEFINITIONS``
0022     Compiler flags required to link against OpenEXR
0023 
0024 and the following imported targets:
0025 
0026 ``OpenEXR::IlmImf``
0027     The OpenEXR core library
0028 
0029 However, if OpenEXR 3 or higher is found, this target will instead be an
0030 alias to:
0031 
0032 ``OpenEXR::OpenEXR``
0033     The OpenEXR version 3 core library
0034 
0035 If OpenEXR's Config module is found, this Find module will defer to it.
0036 
0037 In general we recommend using the imported target, as it is easier to use.
0038 Bear in mind, however, that if the target is in the link interface of an
0039 exported library, it must be made available by the package config file.
0040 
0041 For reference on how to migrate from OpenEXR 2 to 3, which splits the Imath 
0042 library, please see "OpenEXR/Imath 2.x to 3.x Porting Guide" at the Imath 
0043 repository on [GitHub](https://github.com/AcademySoftwareFoundation/Imath/blob/master/docs/PortingGuide2-3.md).
0044 
0045 Since pre-1.0.0.
0046 #]=======================================================================]
0047 
0048 include(ECMFindModuleHelpersStub)
0049 
0050 ecm_find_package_version_check(OpenEXR)
0051 
0052 # use pkg-config to get the directories and then use these values
0053 # in the FIND_PATH() and FIND_LIBRARY() calls
0054 find_package(PkgConfig QUIET)
0055 pkg_check_modules(PC_OpenEXR QUIET OpenEXR)
0056 
0057 # Attempt to load OpenEXR's Find module
0058 set(PC_OpenEXR_CONFIG_DIR CACHE STRING "PkgConfig path for locating the package modules")
0059 foreach(_dir ${CMAKE_PREFIX_PATH})
0060     list(APPEND PC_OpenEXR_CONFIG_DIR ${_dir}/lib/cmake/OpenEXR)
0061 endforeach()
0062 mark_as_advanced(PC_OpenEXR_CONFIG_DIR)
0063 
0064 # If there is a CMake config, use it.
0065 find_package(OpenEXR QUIET NO_MODULE
0066     HINTS ${PC_OpenEXR_CONFIG_DIR} /usr/lib/cmake/OpenEXR /usr/local/lib/cmake/OpenEXR
0067 )
0068 
0069 if(OpenEXR_FOUND)
0070    include(FindPackageHandleStandardArgs)
0071    find_package_handle_standard_args(OpenEXR HANDLE_COMPONENTS CONFIG_MODE)
0072 
0073    if (OpenEXR_VERSION VERSION_GREATER "3.0.0")
0074       add_library(OpenEXR::IlmImf ALIAS OpenEXR::OpenEXR)
0075    endif()
0076 else()
0077    # Attempt a manual lookup.
0078 
0079    pkg_get_variable(PC_OpenEXR_LIBSUFFIX OpenEXR "libsuffix")
0080 
0081    set(OpenEXR_DEFINITIONS ${PC_OpenEXR_CFLAGS_OTHER})
0082 
0083    find_path(OpenEXR_INCLUDE_DIR ImfRgbaFile.h
0084       PATHS
0085       ${PC_OpenEXR_INCLUDEDIR}
0086       ${PC_OpenEXR_INCLUDE_DIRS}
0087       PATH_SUFFIXES OpenEXR
0088    )
0089 
0090    if (OpenEXR_INCLUDE_DIR AND EXISTS "${OpenEXR_INCLUDE_DIR}/OpenEXRConfig.h")
0091       file(STRINGS "${OpenEXR_INCLUDE_DIR}/OpenEXRConfig.h" openexr_version_str
0092          REGEX "^#define[\t ]+OPENEXR_VERSION_STRING[\t ]+\"[^\"]*\"")
0093       string(REGEX REPLACE "^#define[\t ]+OPENEXR_VERSION_STRING[\t ]+\"([^\"]*).*"
0094             "\\1" OpenEXR_VERSION_STRING "${openexr_version_str}")
0095       unset(openexr_version_str)
0096 
0097       # These must be parsed manually in case we are in Windows
0098       # and have no access to pkg-config.
0099 
0100       file(STRINGS "${OpenEXR_INCLUDE_DIR}/OpenEXRConfig.h" openexr_version_str
0101          REGEX "^#define[\t ]+OPENEXR_VERSION_MAJOR[\t ]+\"[^\"]*\"")
0102       string(REGEX REPLACE "^#define[\t ]+OPENEXR_VERSION_MAJOR[\t ]+\"([^\"]*).*"
0103             "\\1" OpenEXR_VERSION_MAJOR "${openexr_version_str}")
0104       unset(openexr_version_str)
0105 
0106       file(STRINGS "${OpenEXR_INCLUDE_DIR}/OpenEXRConfig.h" openexr_version_str
0107          REGEX "^#define[\t ]+OPENEXR_VERSION_MINOR[\t ]+\"[^\"]*\"")
0108       string(REGEX REPLACE "^#define[\t ]+OPENEXR_VERSION_MINOR[\t ]+\"([^\"]*).*"
0109             "\\1" OpenEXR_VERSION_MINOR "${openexr_version_str}")
0110       unset(openexr_version_str)
0111 
0112       file(STRINGS "${OpenEXR_INCLUDE_DIR}/OpenEXRConfig.h" openexr_version_str
0113          REGEX "^#define[\t ]+OPENEXR_VERSION_PATCH[\t ]+\"[^\"]*\"")
0114       string(REGEX REPLACE "^#define[\t ]+OPENEXR_VERSION_PATCH[\t ]+\"([^\"]*).*"
0115             "\\1" OpenEXR_VERSION_PATCH "${openexr_version_str}")
0116       unset(openexr_version_str)
0117    endif()
0118 
0119    if(OpenEXR_VERSION_STRING VERSION_LESS "3.0.0")
0120       find_library(OpenEXR_HALF_LIBRARY
0121          PATHS
0122          ${PC_OpenEXR_LIBDIR}
0123          ${PC_OpenEXR_LIBRARY_DIRS}
0124          NAMES
0125             Half-${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}
0126             Half-${PC_OpenEXR_LIBSUFFIX}
0127             Half
0128       )
0129       find_library(OpenEXR_IEX_LIBRARY
0130          PATHS
0131          ${PC_OpenEXR_LIBDIR}
0132          ${PC_OpenEXR_LIBRARY_DIRS}
0133          NAMES
0134             Iex-${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}
0135             Iex-${PC_OpenEXR_LIBSUFFIX}
0136             Iex
0137       )
0138       find_library(OpenEXR_IEXMATH_LIBRARY
0139          PATHS
0140          ${PC_OpenEXR_LIBDIR}
0141          ${PC_OpenEXR_LIBRARY_DIRS}
0142          NAMES
0143             IexMath-${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}
0144             IexMath-${PC_OpenEXR_LIBSUFFIX}
0145             IexMath
0146       )
0147       find_library(OpenEXR_IMATH_LIBRARY
0148          PATHS
0149          ${PC_OpenEXR_LIBDIR}
0150          ${PC_OpenEXR_LIBRARY_DIRS}
0151          NAMES
0152             Imath-${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}
0153             Imath-${PC_OpenEXR_LIBSUFFIX}
0154             Imath
0155       )
0156       find_library(OpenEXR_ILMTHREAD_LIBRARY
0157          PATHS
0158          ${PC_OpenEXR_LIBDIR}
0159          ${PC_OpenEXR_LIBRARY_DIRS}
0160          NAMES
0161             IlmThread-${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}
0162             IlmThread-${PC_OpenEXR_LIBSUFFIX}
0163             IlmThread
0164       )
0165       # 2.2.0+ 
0166       find_library(OpenEXR_ILMIMFUTIL_LIBRARY
0167          PATHS
0168          ${PC_OpenEXR_LIBDIR}
0169          ${PC_OpenEXR_LIBRARY_DIRS}
0170          NAMES
0171             IlmImfUtil-${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}
0172             IlmImfUtilx-${PC_OpenEXR_LIBSUFFIX}
0173             IlmImfUtil
0174       )
0175       # This is the actual OpenEXR library
0176       find_library(OpenEXR_ILMIMF_LIBRARY
0177          PATHS
0178          ${PC_OpenEXR_LIBDIR}
0179          ${PC_OpenEXR_LIBRARY_DIRS}
0180          NAMES
0181             IlmImf-${OpenEXR_VERSION_MAJOR}_${OpenEXR_VERSION_MINOR}
0182             IlmImf-${PC_OpenEXR_LIBSUFFIX}
0183             IlmImf
0184       )
0185 
0186       set(_OpenEXR_deps
0187          ${OpenEXR_HALF_LIBRARY}
0188          ${OpenEXR_IEX_LIBRARY}
0189          ${OpenEXR_IEXMATH_LIBRARY}
0190          ${OpenEXR_IMATH_LIBRARY}
0191          ${OpenEXR_ILMTHREAD_LIBRARY}
0192          ${OpenEXR_ILMIMFUTIL_LIBRARY})
0193 
0194       set(OpenEXR_LIBRARIES
0195          ${_OpenEXR_deps}
0196          ${OpenEXR_ILMIMF_LIBRARY})
0197 
0198       # find_package_handle_standard_args reports the value of the first variable
0199       # on success, so make sure this is the actual OpenEXR library
0200       find_package_handle_standard_args(OpenEXR
0201          FOUND_VAR OpenEXR_FOUND
0202          REQUIRED_VARS
0203             OpenEXR_ILMIMF_LIBRARY
0204             OpenEXR_HALF_LIBRARY
0205             OpenEXR_IEX_LIBRARY
0206             OpenEXR_IEXMATH_LIBRARY
0207             OpenEXR_IMATH_LIBRARY
0208             OpenEXR_ILMTHREAD_LIBRARY
0209             OpenEXR_ILMIMFUTIL_LIBRARY
0210             OpenEXR_INCLUDE_DIR
0211          VERSION_VAR OpenEXR_VERSION_STRING)
0212 
0213       set(OpenEXR_INCLUDE_DIRS ${OpenEXR_INCLUDE_DIR})
0214 
0215       mark_as_advanced(
0216          OpenEXR_INCLUDE_DIR
0217          OpenEXR_LIBRARIES
0218          OpenEXR_DEFINITIONS
0219          OpenEXR_ILMIMF_LIBRARY
0220          OpenEXR_ILMIMFUTIL_LIBRARY
0221          OpenEXR_ILMTHREAD_LIBRARY
0222          OpenEXR_IMATH_LIBRARY
0223          OpenEXR_IEX_LIBRARY
0224          OpenEXR_IEXMATH_LIBRARY
0225          OpenEXR_HALF_LIBRARY
0226       )
0227 
0228       if(OpenEXR_FOUND AND NOT TARGET OpenEXR::IlmImf)
0229          add_library(OpenEXR::IlmImf UNKNOWN IMPORTED)
0230          set_target_properties(OpenEXR::IlmImf PROPERTIES
0231             IMPORTED_LOCATION "${OpenEXR_ILMIMF_LIBRARY}"
0232             INTERFACE_COMPILE_OPTIONS "${OpenEXR_DEFINITIONS}"
0233             INTERFACE_INCLUDE_DIRECTORIES "${OpenEXR_INCLUDE_DIR}"
0234             INTERFACE_LINK_LIBRARIES "${_OpenEXR_deps}"
0235          )
0236       endif()
0237    else()
0238       # Attempt a manual lookup of Imath.
0239 
0240       pkg_check_modules(PC_Imath QUIET Imath)
0241 
0242       pkg_get_variable(PC_Imath_LIBSUFFIX Imath "libsuffix")
0243 
0244       set(Imath_DEFINITIONS ${PC_Imath_CFLAGS_OTHER})
0245 
0246       find_path(Imath_INCLUDE_DIR ImfConfig.h
0247          PATHS
0248          ${PC_Imath_INCLUDEDIR}
0249          ${PC_Imath_INCLUDE_DIRS}
0250          PATH_SUFFIXES Imath
0251       )
0252 
0253       if (Imath_INCLUDE_DIR AND EXISTS "${Imath_INCLUDE_DIR}/ImfConfig.h")
0254          file(STRINGS "${Imath_INCLUDE_DIR}/ImfConfig.h" imath_version_str
0255             REGEX "^#define[\t ]+IMATH_VERSION_STRING[\t ]+\"[^\"]*\"")
0256          string(REGEX REPLACE "^#define[\t ]+IMATH_VERSION_STRING[\t ]+\"([^\"]*).*"
0257                "\\1" Imath_VERSION_STRING "${imath_version_str}")
0258          unset(imath_version_str)
0259 
0260          # These must be parsed manually in case we are in Windows
0261          # and have no access to pkg-config.
0262 
0263          file(STRINGS "${Imath_INCLUDE_DIR}/ImfConfig.h" imath_version_str
0264             REGEX "^#define[\t ]+IMATH_VERSION_MAJOR[\t ]+\"[^\"]*\"")
0265          string(REGEX REPLACE "^#define[\t ]+IMATH_VERSION_MAJOR[\t ]+\"([^\"]*).*"
0266                "\\1" Imath_VERSION_MAJOR "${imath_version_str}")
0267          unset(imath_version_str)
0268 
0269          file(STRINGS "${Imath_INCLUDE_DIR}/ImfConfig.h" imath_version_str
0270             REGEX "^#define[\t ]+IMATH_VERSION_MINOR[\t ]+\"[^\"]*\"")
0271          string(REGEX REPLACE "^#define[\t ]+IMATH_VERSION_MINOR[\t ]+\"([^\"]*).*"
0272                "\\1" Imath_VERSION_MINOR "${imath_version_str}")
0273          unset(imath_version_str)
0274 
0275          file(STRINGS "${Imath_INCLUDE_DIR}/ImfConfig.h" imath_version_str
0276             REGEX "^#define[\t ]+IMATH_VERSION_PATCH[\t ]+\"[^\"]*\"")
0277          string(REGEX REPLACE "^#define[\t ]+IMATH_VERSION_MAJOR[\t ]+\"([^\"]*).*"
0278                "\\1" Imath_VERSION_PATCH "${imath_version_str}")
0279          unset(imath_version_str)
0280       endif()
0281 
0282       find_library(Imath_LIBRARY
0283          PATHS
0284          ${PC_Imath_LIBDIR}
0285          ${PC_Imath_LIBRARY_DIRS}
0286          NAMES
0287             Imath-${Imath_VERSION_MAJOR}_${Imath_VERSION_MINOR}
0288             Imath-${PC_Imath_LIBSUFFIX}
0289             Imath
0290       )
0291       find_library(OpenEXR_IEX_LIBRARY NAMES Iex
0292          PATHS
0293          ${PC_OpenEXR_LIBDIR}
0294          ${PC_OpenEXR_LIBRARY_DIRS}
0295          NAMES
0296             Iex-${Imath_VERSION_MAJOR}_${Imath_VERSION_MINOR}
0297             Iex-${PC_Imath_LIBSUFFIX}
0298             Iex
0299       )
0300       find_library(OpenEXR_ILMTHREAD_LIBRARY NAMES IlmThread
0301          PATHS
0302          ${PC_OpenEXR_LIBDIR}
0303          ${PC_OpenEXR_LIBRARY_DIRS}
0304          NAMES
0305             IlmThread-${Imath_VERSION_MAJOR}_${Imath_VERSION_MINOR}
0306             IlmThread-${PC_Imath_LIBSUFFIX}
0307             IlmThread
0308       )
0309       find_library(OpenEXR_OpenEXRUTIL_LIBRARY NAMES OpenEXRUtil
0310          PATHS
0311          ${PC_OpenEXR_LIBDIR}
0312          ${PC_OpenEXR_LIBRARY_DIRS}
0313          NAMES
0314             OpenEXRUtil-${Imath_VERSION_MAJOR}_${Imath_VERSION_MINOR}
0315             OpenEXRUtil-${PC_Imath_LIBSUFFIX}
0316             OpenEXRUtil
0317       )
0318       find_library(OpenEXR_OpenEXRCORE_LIBRARY NAMES OpenEXRCore
0319          PATHS
0320          ${PC_OpenEXR_LIBDIR}
0321          ${PC_OpenEXR_LIBRARY_DIRS}
0322          NAMES
0323             OpenEXRCore-${Imath_VERSION_MAJOR}_${Imath_VERSION_MINOR}
0324             OpenEXRCore-${PC_Imath_LIBSUFFIX}
0325             OpenEXRCore
0326       )
0327       # This is the actual OpenEXR library
0328       find_library(OpenEXR_OPENEXR_LIBRARY NAMES OpenEXR
0329          PATHS
0330          ${PC_OpenEXR_LIBDIR}
0331          ${PC_OpenEXR_LIBRARY_DIRS}
0332          NAMES
0333             OpenEXR-${Imath_VERSION_MAJOR}_${Imath_VERSION_MINOR}
0334             OpenEXR-${PC_Imath_LIBSUFFIX}
0335             OpenEXR
0336       )
0337 
0338       set(_OpenEXR_deps
0339          ${Imath_LIBRARY}
0340          ${OpenEXR_IEX_LIBRARY}
0341          ${OpenEXR_ILMTHREAD_LIBRARY}
0342          ${OpenEXR_OpenEXRUTIL_LIBRARY}
0343          ${OpenEXR_OpenEXRCORE_LIBRARY})
0344 
0345       set(OpenEXR_LIBRARIES
0346          ${_OpenEXR_deps}
0347          ${OpenEXR_OPENEXR_LIBRARY})
0348 
0349       # find_package_handle_standard_args reports the value of the first variable
0350       # on success, so make sure this is the actual OpenEXR library
0351       find_package_handle_standard_args(OpenEXR
0352          FOUND_VAR OpenEXR_FOUND
0353          REQUIRED_VARS
0354             Imath_LIBRARY
0355             OpenEXR_IEX_LIBRARY
0356             OpenEXR_ILMTHREAD_LIBRARY
0357             OpenEXR_OpenEXRUTIL_LIBRARY
0358             OpenEXR_OpenEXRCORE_LIBRARY
0359             OpenEXR_OPENEXR_LIBRARY
0360             OpenEXR_INCLUDE_DIR
0361          VERSION_VAR OpenEXR_VERSION_STRING)
0362 
0363       set(OpenEXR_INCLUDE_DIRS ${OpenEXR_INCLUDE_DIR} ${Imath_INCLUDE_DIR})
0364 
0365       mark_as_advanced(
0366          Imath_INCLUDE_DIR
0367          OpenEXR_INCLUDE_DIR
0368          Imath_LIBRARY
0369          OpenEXR_IEX_LIBRARY
0370          OpenEXR_ILMTHREAD_LIBRARY
0371          OpenEXR_OpenEXRUTIL_LIBRARY
0372          OpenEXR_OpenEXRCORE_LIBRARY
0373          OpenEXR_OPENEXR_LIBRARY
0374       )
0375 
0376       if(OpenEXR_FOUND AND NOT TARGET OpenEXR::OpenEXR)
0377          add_library(OpenEXR::OpenEXR UNKNOWN IMPORTED)
0378          set_target_properties(OpenEXR::OpenEXR PROPERTIES
0379             IMPORTED_LOCATION "${OpenEXR_OPENEXR_LIBRARY}"
0380             INTERFACE_COMPILE_OPTIONS "${OpenEXR_DEFINITIONS}"
0381             INTERFACE_INCLUDE_DIRECTORIES "${OpenEXR_INCLUDE_DIRS}"
0382             INTERFACE_LINK_LIBRARIES "${_OpenEXR_deps}"
0383          )
0384          add_library(OpenEXR::IlmImf ALIAS OpenEXR::OpenEXR)
0385       endif()
0386    endif()
0387 endif()
0388 
0389 include(FeatureSummary)
0390 set_package_properties(OpenEXR PROPERTIES
0391    URL https://www.openexr.com/
0392    DESCRIPTION "A library for handling OpenEXR high dynamic-range image files")