CMake: mark vars as advanced
[blender.git] / build_files / cmake / Modules / FindOpenEXR.cmake
1 # - Find OpenEXR library
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 #
11 # For individual library access these advanced settings are available
12 #  OPENEXR_HALF_LIBRARY, Path to Half library
13 #  OPENEXR_IEX_LIBRARY, Path to Half library
14 #  OPENEXR_ILMIMF_LIBRARY, Path to Ilmimf library
15 #  OPENEXR_ILMTHREAD_LIBRARY, Path to IlmThread library
16 #  OPENEXR_IMATH_LIBRARY, Path to Imath library
17 #
18 # also defined, but not for general use are
19 #  OPENEXR_LIBRARY, where to find the OpenEXR library.
20
21 #=============================================================================
22 # Copyright 2011 Blender Foundation.
23 #
24 # Distributed under the OSI-approved BSD License (the "License");
25 # see accompanying file Copyright.txt for details.
26 #
27 # This software is distributed WITHOUT ANY WARRANTY; without even the
28 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
29 # See the License for more information.
30 #=============================================================================
31
32 # If OPENEXR_ROOT_DIR was defined in the environment, use it.
33 IF(NOT OPENEXR_ROOT_DIR AND NOT $ENV{OPENEXR_ROOT_DIR} STREQUAL "")
34   SET(OPENEXR_ROOT_DIR $ENV{OPENEXR_ROOT_DIR})
35 ENDIF()
36
37 SET(_openexr_FIND_COMPONENTS
38   Half
39   Iex
40   IlmImf
41   IlmThread
42   Imath
43 )
44
45 SET(_openexr_SEARCH_DIRS
46   ${OPENEXR_ROOT_DIR}
47   /usr/local
48   /sw # Fink
49   /opt/local # DarwinPorts
50   /opt/csw # Blastwave
51 )
52
53 FIND_PATH(OPENEXR_INCLUDE_DIR
54   NAMES
55     OpenEXR/ImfXdr.h
56   HINTS
57     ${_openexr_SEARCH_DIRS}
58   PATH_SUFFIXES
59     include
60 )
61
62 # If the headers were found, get the version from config file, if not already set.
63 IF(OPENEXR_INCLUDE_DIR)
64   IF(NOT OPENEXR_VERSION)
65
66     FIND_FILE(_openexr_CONFIG
67       NAMES
68         OpenEXRConfig.h
69       PATHS
70         "${OPENEXR_INCLUDE_DIR}"
71         "${OPENEXR_INCLUDE_DIR}/OpenEXR"
72       NO_DEFAULT_PATH
73     )
74
75     IF(_openexr_CONFIG)
76       FILE(STRINGS "${_openexr_CONFIG}" OPENEXR_BUILD_SPECIFICATION
77            REGEX "^[ \t]*#define[ \t]+OPENEXR_VERSION_STRING[ \t]+\"[.0-9]+\".*$")
78     ELSE()
79       MESSAGE(WARNING "Could not find \"OpenEXRConfig.h\" in \"${OPENEXR_INCLUDE_DIR}\"")
80     ENDIF()
81
82     IF(OPENEXR_BUILD_SPECIFICATION)
83       MESSAGE(STATUS "${OPENEXR_BUILD_SPECIFICATION}")
84       STRING(REGEX REPLACE ".*#define[ \t]+OPENEXR_VERSION_STRING[ \t]+\"([.0-9]+)\".*"
85              "\\1" XYZ ${OPENEXR_BUILD_SPECIFICATION})
86       SET("OPENEXR_VERSION" ${XYZ} CACHE STRING "Version of OpenEXR lib")
87     ELSE()
88       # Old versions (before 2.0?) do not have any version string, just assuming 2.0 should be fine though. 
89       MESSAGE(WARNING "Could not determine ILMBase library version, assuming 2.0.")
90       SET("OPENEXR_VERSION" "2.0" CACHE STRING "Version of OpenEXR lib")
91     ENDIF()
92
93     UNSET(_openexr_CONFIG CACHE)
94
95   ENDIF()
96 ENDIF()
97
98 STRING(REGEX REPLACE "([0-9]+)[.]([0-9]+).*" "\\1_\\2" _openexr_libs_ver ${OPENEXR_VERSION})
99
100 SET(_openexr_LIBRARIES)
101 FOREACH(COMPONENT ${_openexr_FIND_COMPONENTS})
102   STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
103
104   FIND_LIBRARY(OPENEXR_${UPPERCOMPONENT}_LIBRARY
105     NAMES
106       ${COMPONENT}-${_openexr_libs_ver} ${COMPONENT} 
107     HINTS
108       ${_openexr_SEARCH_DIRS}
109     PATH_SUFFIXES
110       lib64 lib
111     )
112   LIST(APPEND _openexr_LIBRARIES "${OPENEXR_${UPPERCOMPONENT}_LIBRARY}")
113 ENDFOREACH()
114
115 UNSET(_openexr_libs_ver)
116
117 # handle the QUIETLY and REQUIRED arguments and set OPENEXR_FOUND to TRUE if 
118 # all listed variables are TRUE
119 INCLUDE(FindPackageHandleStandardArgs)
120 FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenEXR  DEFAULT_MSG
121     _openexr_LIBRARIES OPENEXR_INCLUDE_DIR)
122
123 IF(OPENEXR_FOUND)
124   SET(OPENEXR_LIBRARIES ${_openexr_LIBRARIES})
125   # Both include paths are needed because of dummy OSL headers mixing #include <OpenEXR/foo.h> and #include <foo.h> :(
126   SET(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR_INCLUDE_DIR}/OpenEXR)
127 ENDIF()
128
129 MARK_AS_ADVANCED(
130   OPENEXR_INCLUDE_DIR
131   OPENEXR_VERSION
132 )
133 FOREACH(COMPONENT ${_openexr_FIND_COMPONENTS})
134   STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
135   MARK_AS_ADVANCED(OPENEXR_${UPPERCOMPONENT}_LIBRARY)
136 ENDFOREACH()