replace own inline cmake include search logic for a typical FindXXX.cmake module.
[blender-staging.git] / build_files / cmake / Modules / FindOpenEXR.cmake
1 # - Find OpenEXR library (copied from FindTIFF.cmake, v 2.8.5)
2 # Find the native OpenEXR includes and library
3 # This module defines
4 #  OPENEXR_INCLUDE_DIRS, where to find ImfXdr.h, etc. Set when
5 #                        OPENEXR_INCLUDE_DIR is found.
6 #  OPENEXR_LIBRARIES, libraries to link against to use OpenEXR.
7 #  OPENEXR_ROOT_DIR, The base directory to search for OpenEXR.
8 #                    This can also be an environment variable.
9 #  OPENEXR_FOUND, If false, do not try to use OpenEXR.
10 # also defined, but not for general use are
11 #  OPENEXR_LIBRARY, where to find the OpenEXR library.
12
13 #=============================================================================
14 # Copyright 2002-2009 Kitware, Inc.
15 #
16 # Distributed under the OSI-approved BSD License (the "License");
17 # see accompanying file Copyright.txt for details.
18 #
19 # This software is distributed WITHOUT ANY WARRANTY; without even the
20 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 # See the License for more information.
22 #=============================================================================
23 # (To distribute this file outside of CMake, substitute the full
24 #  License text for the above reference.)
25
26 # If OPENEXR_ROOT_DIR was defined in the environment, use it.
27 IF(NOT OPENEXR_ROOT_DIR AND NOT $ENV{OPENEXR_ROOT_DIR} STREQUAL "")
28   SET(OPENEXR_ROOT_DIR $ENV{OPENEXR_ROOT_DIR})
29 ENDIF()
30
31 SET(_openexr_FIND_COMPONENTS
32   Half
33   IlmImf
34   Iex
35   Imath
36 )
37
38 SET(_openexr_SEARCH_DIRS
39   ${OPENEXR_ROOT_DIR}
40   /usr/local
41   /opt/csw
42 )
43
44 FIND_PATH(OPENEXR_INCLUDE_DIR ImfXdr.h
45   HINTS
46     ${_openexr_SEARCH_DIRS}
47   PATH_SUFFIXES
48     include/OpenEXR
49 )
50
51 SET(_openexr_LIBRARIES)
52 FOREACH(COMPONENT ${_openexr_FIND_COMPONENTS})
53   STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
54
55   FIND_LIBRARY(OPENEXR_${UPPERCOMPONENT}_LIBRARY NAMES ${COMPONENT}
56       HINTS ${_openexr_SEARCH_DIRS}
57       PATH_SUFFIXES lib
58       )
59   LIST(APPEND _openexr_LIBRARIES "${OPENEXR_${UPPERCOMPONENT}_LIBRARY}")
60 ENDFOREACH()
61
62 # handle the QUIETLY and REQUIRED arguments and set OPENEXR_FOUND to TRUE if 
63 # all listed variables are TRUE
64 INCLUDE(FindPackageHandleStandardArgs)
65 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenEXR  DEFAULT_MSG
66     ${_openexr_LIBRARIES} OPENEXR_INCLUDE_DIR)
67
68 IF(OPENEXR_FOUND)
69   SET(OPENEXR_LIBRARIES ${_openexr_LIBRARIES})
70   SET(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR})
71 ENDIF(OPENEXR_FOUND)
72
73 MARK_AS_ADVANCED(
74   ${_openexr_LIBRARIES}
75   OPENEXR_INCLUDE_DIR
76 )