Skip to content

Commit

Permalink
CMake: OpenEXR related enhancements (#4840)
Browse files Browse the repository at this point in the history
* Making find OpenEXR package more robust and convenient.

It is now possible to just specify OpenEXR_ROOT for Versions < 3. Versions >= 3 need an additional Imath_ROOT as Imath is separate now. This should work without an explicitly user supplied PKG_CONFIG_PATH. Tested on openexr-2.5 and openexr-3.1.

* Adding documentation regarding build hints for external library OpenEXR
  • Loading branch information
spezialspezial authored Nov 17, 2021
1 parent 5f283e2 commit 5acdcc3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
46 changes: 35 additions & 11 deletions cmake/modules/packages/FindOpenEXR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,71 @@
# OpenEXR_INCLUDE_DIRS
# OpenEXR_LIBRARIES
#

if(OpenEXR_ROOT)
list(APPEND OpenEXR_INC_HINTS ${OpenEXR_ROOT}/include/OpenEXR)
list(APPEND OpenEXR_LIB_HINTS ${OpenEXR_ROOT}/lib)
list(APPEND CMAKE_PREFIX_PATH ${OpenEXR_ROOT})
endif()

if(Imath_ROOT)
list(APPEND Imath_INC_HINTS ${Imath_ROOT}/include/Imath)
list(APPEND Imath_LIB_HINTS ${Imath_ROOT}/lib)
list(APPEND CMAKE_PREFIX_PATH ${Imath_ROOT})
endif()

find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_check_modules(PC_OpenEXR QUIET OpenEXR)
pkg_check_modules(PC_OpenEXR QUIET OpenEXR)
if(PC_OpenEXR_FOUND)
list(APPEND OpenEXR_LIB_HINTS ${PC_OpenEXR_LIBRARY_DIRS})
list(APPEND OpenEXR_INC_HINTS ${PC_OpenEXR_INCLUDE_DIRS})
set(OpenEXR_VERSION_STRING ${PC_OpenEXR_VERSION})
endif()
endif ()

find_path(OpenEXR_INCLUDE_DIR
NAMES ImfVersion.h
HINTS ${PC_OpenEXR_INCLUDE_DIRS}
HINTS ${OpenEXR_INC_HINTS}
PATH_SUFFIXES OpenEXR)
find_path(Imath_INCLUDE_DIR
NAMES ImathMatrix.h
HINTS ${PC_OpenEXR_INCLUDE_DIRS}
HINTS ${Imath_INC_HINTS} ${OpenEXR_INCLUDE_DIR}
PATH_SUFFIXES Imath)

if(OpenEXR_INCLUDE_DIR AND NOT OpenEXR_VERSION_STRING)
# Fallback for PkgConfig not finding anything
file(READ ${OpenEXR_INCLUDE_DIR}/OpenEXRConfig.h txt)
string(REGEX MATCH "define[ \t]+OPENEXR_VERSION_STRING[ \t]+\"([0-9]+(.[0-9]+)?(.[0-9]+)?)\".*$" _ ${txt})
set(OpenEXR_VERSION_STRING ${CMAKE_MATCH_1})
endif()

if (OpenEXR_VERSION_STRING VERSION_GREATER_EQUAL 3.0)
find_library(OpenEXR_LIBRARY
NAMES OpenEXR
HINTS ${PC_OpenEXR_LIBRARY_DIRS})
HINTS ${OpenEXR_LIB_HINTS})
find_library(OpenEXR_UTIL_LIBRARY
NAMES OpenEXRUtil
HINTS ${PC_OpenEXR_LIBRARY_DIRS})
HINTS ${OpenEXR_LIB_HINTS})
find_library(OpenEXR_HALF_LIBRARY
NAMES Imath
HINTS ${PC_OpenEXR_LIBRARY_DIRS})
HINTS ${Imath_LIB_HINTS}) #Imath is considered separate since v3
find_library(OpenEXR_IEX_LIBRARY
NAMES Iex
HINTS ${PC_OpenEXR_LIBRARY_DIRS})
HINTS ${OpenEXR_LIB_HINTS})
else()
find_library(OpenEXR_LIBRARY
NAMES IlmImf
HINTS ${PC_OpenEXR_LIBRARY_DIRS})
HINTS ${OpenEXR_LIB_HINTS})
find_library(OpenEXR_UTIL_LIBRARY
NAMES IlmImfUtil
HINTS ${PC_OpenEXR_LIBRARY_DIRS})
HINTS ${OpenEXR_LIB_HINTS})
find_library(OpenEXR_HALF_LIBRARY
NAMES Half
HINTS ${PC_OpenEXR_LIBRARY_DIRS})
HINTS ${OpenEXR_LIB_HINTS})
find_library(OpenEXR_IEX_LIBRARY
NAMES Iex
HINTS ${PC_OpenEXR_LIBRARY_DIRS})
HINTS ${OpenEXR_LIB_HINTS})
endif()

find_package_handle_standard_args(OpenEXR FOUND_VAR OpenEXR_FOUND
Expand Down
23 changes: 23 additions & 0 deletions doc/source/build_hints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,35 @@ TIFF
Control whether to use internal libtiff copy. Defaults to ON when external
libtiff is not found.


TileDB
******

Specify install prefix in the ``CMAKE_PREFIX_PATH`` variable.


OpenEXR
*******

Specify ``OpenEXR_ROOT`` variable pointing to the parent directory of
/lib and /include subdirectories, i.e. /DEV/lib/openexr-3.0.
For OpenEXR >= 3 additionally specify ``Imath_ROOT`` as this is a
separate library now, i.e. /DEV/lib/imath-3.1.3

or

Specify root directory adding to the ``CMAKE_PREFIX_PATH`` variable to find OpenEXR's pkgconfig.
For example -DCMAKE_PREFIX_PATH=/DEV/lib/openexr-3.0;/DEV/lib/imath-3.1.3

or

Get real specific and set
``OpenEXR_INCLUDE_DIR``, ``Imath_INCLUDE_DIR``,
``OpenEXR_LIBRARY``, ``OpenEXR_UTIL_LIBRARY``,
``OpenEXR_HALF_LIBRARY``, ``OpenEXR_IEX_LIBRARY``
explicitly


Selection of drivers
++++++++++++++++++++

Expand Down

0 comments on commit 5acdcc3

Please sign in to comment.