Manipulator: limit UI for locked views
[blender.git] / build_files / build_environment / patches / cmake / modules / FindOpenEXR.cmake
1 # Module to find OpenEXR.
2 #
3 # This module will first look into the directories defined by the variables:
4 #   - OPENEXR_HOME, OPENEXR_VERSION, OPENEXR_LIB_AREA
5 #
6 # It also supports non-standard names for the library components.
7 #
8 # To use a custom OpenEXR
9 #   - Set the variable OPENEXR_CUSTOM to True
10 #   - Set the variable OPENEXR_CUSTOM_LIBRARY to the name of the library to
11 #     use, e.g. "SpiIlmImf"
12 #   - Optionally set the variable OPENEXR_CUSTOM_INCLUDE_DIR to any
13 #     particularly weird place that the OpenEXR/*.h files may be found
14 #   - Optionally set the variable OPENEXR_CUSTOM_LIB_DIR to any
15 #     particularly weird place that the libraries files may be found
16 #
17 # This module defines the following variables:
18 #
19 # OPENEXR_INCLUDE_DIR - where to find ImfRgbaFile.h, OpenEXRConfig, etc.
20 # OPENEXR_LIBRARIES   - list of libraries to link against when using OpenEXR.
21 #                       This list does NOT include the IlmBase libraries.
22 #                       These are defined by the FindIlmBase module.
23 # OPENEXR_FOUND       - True if OpenEXR was found.
24
25 # Other standarnd issue macros
26 include (SelectLibraryConfigurations)
27 include (FindPackageHandleStandardArgs)
28 include (FindPackageMessage)
29
30 if( OPENEXR_USE_STATIC_LIBS )
31   set( _openexr_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
32   if(WIN32)
33     set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
34   else()
35     set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
36   endif()
37 endif()
38
39 # Macro to assemble a helper state variable
40 macro (SET_STATE_VAR varname)
41   set (tmp_lst
42     ${OPENEXR_CUSTOM} | ${OPENEXR_CUSTOM_LIBRARY} |
43     ${OPENEXR_HOME} | ${OPENEXR_VERSION} | ${OPENEXR_LIB_AREA}
44   )
45   set (${varname} "${tmp_lst}")
46   unset (tmp_lst)
47 endmacro ()
48
49 # To enforce that find_* functions do not use inadvertently existing versions
50 if (OPENEXR_CUSTOM)
51   set (OPENEXR_FIND_OPTIONS "NO_DEFAULT_PATH")
52 endif ()
53
54 # Macro to search for an include directory
55 macro (PREFIX_FIND_INCLUDE_DIR prefix includefile libpath_var)
56   string (TOUPPER ${prefix}_INCLUDE_DIR tmp_varname)
57   find_path(${tmp_varname} ${includefile}
58     HINTS ${${libpath_var}}
59     PATH_SUFFIXES include
60     ${OPENEXR_FIND_OPTIONS}
61   )
62   if (${tmp_varname})
63     mark_as_advanced (${tmp_varname})
64   endif ()
65   unset (tmp_varname)
66 endmacro ()
67
68
69 # Macro to search for the given library and adds the cached
70 # variable names to the specified list
71 macro (PREFIX_FIND_LIB prefix libname libpath_var liblist_var cachelist_var)
72   string (TOUPPER ${prefix}_${libname} tmp_prefix)
73   # Handle new library names for OpenEXR 2.1 build via cmake
74   string(REPLACE "." "_" _ILMBASE_VERSION ${ILMBASE_VERSION})
75   string(SUBSTRING ${_ILMBASE_VERSION} 0 3 _ILMBASE_VERSION )
76   find_library(${tmp_prefix}_LIBRARY_RELEASE
77     NAMES ${libname} ${libname}-${_ILMBASE_VERSION}
78     HINTS ${${libpath_var}}
79     PATH_SUFFIXES lib
80     ${OPENEXR_FIND_OPTIONS}
81   )
82   find_library(${tmp_prefix}_LIBRARY_DEBUG
83     NAMES ${libname}d ${libname}_d ${libname}debug ${libname}_debug
84     HINTS ${${libpath_var}}
85     PATH_SUFFIXES lib
86     ${OPENEXR_FIND_OPTIONS}
87   )
88   # Properly define ${tmp_prefix}_LIBRARY (cached) and ${tmp_prefix}_LIBRARIES
89   select_library_configurations (${tmp_prefix})
90   list (APPEND ${liblist_var} ${tmp_prefix}_LIBRARIES)
91
92   # Add to the list of variables which should be reset
93   list (APPEND ${cachelist_var}
94     ${tmp_prefix}_LIBRARY
95     ${tmp_prefix}_LIBRARY_RELEASE
96     ${tmp_prefix}_LIBRARY_DEBUG)
97   mark_as_advanced (
98     ${tmp_prefix}_LIBRARY
99     ${tmp_prefix}_LIBRARY_RELEASE
100     ${tmp_prefix}_LIBRARY_DEBUG)
101   unset (tmp_prefix)
102 endmacro ()
103
104
105 # Encode the current state of the external variables into a string
106 SET_STATE_VAR (OPENEXR_CURRENT_STATE)
107
108 # If the state has changed, clear the cached variables
109 if (OPENEXR_CACHED_STATE AND
110     NOT OPENEXR_CACHED_STATE STREQUAL OPENEXR_CURRENT_STATE)
111   foreach (libvar ${OPENEXR_CACHED_VARS})
112     unset (${libvar} CACHE)
113   endforeach ()
114 endif ()
115
116 # Generic search paths
117 set (OpenEXR_generic_include_paths
118   ${OPENEXR_CUSTOM_INCLUDE_DIR}
119   /usr/include
120   /usr/include/${CMAKE_LIBRARY_ARCHITECTURE}
121   /usr/local/include
122   /sw/include
123   /opt/local/include)
124 set (OpenEXR_generic_library_paths
125   ${OPENEXR_CUSTOM_LIB_DIR}
126   /usr/lib
127   /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}
128   /usr/local/lib
129   /usr/local/lib/${CMAKE_LIBRARY_ARCHITECTURE}
130   /sw/lib
131   /opt/local/lib)
132
133 # Search paths for the OpenEXR files
134 if (OPENEXR_HOME)
135   set (OpenEXR_library_paths
136     ${OPENEXR_HOME}/lib
137     ${OPENEXR_HOME}/lib64)
138   if (OPENEXR_VERSION)
139     set (OpenEXR_include_paths
140       ${OPENEXR_HOME}/openexr-${OPENEXR_VERSION}/include
141       ${OPENEXR_HOME}/include/openexr-${OPENEXR_VERSION})
142     list (APPEND OpenEXR_library_paths
143       ${OPENEXR_HOME}/openexr-${OPENEXR_VERSION}/lib
144       ${OPENEXR_HOME}/lib/openexr-${OPENEXR_VERSION})
145   endif()
146   list (APPEND OpenEXR_include_paths ${OPENEXR_HOME}/include)
147   if (OPENEXR_LIB_AREA)
148     list (INSERT OpenEXR_library_paths 2 ${OPENEXR_LIB_AREA})
149   endif ()
150 endif ()
151 if (ILMBASE_HOME AND OPENEXR_VERSION)
152   list (APPEND OpenEXR_include_paths
153     ${ILMBASE_HOME}/include/openexr-${OPENEXR_VERSION})
154 endif()
155 list (APPEND OpenEXR_include_paths ${OpenEXR_generic_include_paths})
156 list (APPEND OpenEXR_library_paths ${OpenEXR_generic_library_paths})
157
158 # Locate the header files
159 PREFIX_FIND_INCLUDE_DIR (OpenEXR
160   OpenEXR/ImfArray.h OpenEXR_include_paths)
161
162 if (OPENEXR_INCLUDE_DIR)
163   # Get the version from config file, if not already set.
164   if (NOT OPENEXR_VERSION)
165     FILE(STRINGS "${OPENEXR_INCLUDE_DIR}/OpenEXR/OpenEXRConfig.h" OPENEXR_BUILD_SPECIFICATION
166          REGEX "^[ \t]*#define[ \t]+OPENEXR_VERSION_STRING[ \t]+\"[.0-9]+\".*$")
167
168     if(OPENEXR_BUILD_SPECIFICATION)
169       if (NOT OpenEXR_FIND_QUIETLY)
170         message(STATUS "${OPENEXR_BUILD_SPECIFICATION}")
171       endif ()
172       string(REGEX REPLACE ".*#define[ \t]+OPENEXR_VERSION_STRING[ \t]+\"([.0-9]+)\".*"
173              "\\1" XYZ ${OPENEXR_BUILD_SPECIFICATION})
174       set("OPENEXR_VERSION" ${XYZ} CACHE STRING "Version of OpenEXR lib")
175     else()
176       # Old versions (before 2.0?) do not have any version string, just assuming 2.0 should be fine though. 
177       message(WARNING "Could not determine ILMBase library version, assuming 2.0.")
178       set("OPENEXR_VERSION" "2.0" CACHE STRING "Version of OpenEXR lib")
179     endif()
180   endif()
181 endif ()
182
183 if (OPENEXR_CUSTOM)
184   if (NOT OPENEXR_CUSTOM_LIBRARY)
185     message (FATAL_ERROR "Custom OpenEXR library requested but OPENEXR_CUSTOM_LIBRARY is not set.")
186   endif()
187   set (OpenEXR_Library ${OPENEXR_CUSTOM_LIBRARY})
188 else ()
189 #elseif (${OPENEXR_VERSION} VERSION_LESS "2.1")
190   set (OpenEXR_Library IlmImf)
191 #else ()
192 #  string(REGEX REPLACE "([0-9]+)[.]([0-9]+).*" "\\1_\\2" _openexr_libs_ver ${OPENEXR_VERSION})
193 #  set (OpenEXR_Library IlmImf-${_openexr_libs_ver})
194 endif ()
195
196 # Locate the OpenEXR library
197 set (OpenEXR_libvars "")
198 set (OpenEXR_cachevars "")
199 PREFIX_FIND_LIB (OpenEXR ${OpenEXR_Library}
200   OpenEXR_library_paths OpenEXR_libvars OpenEXR_cachevars)
201
202 # Create the list of variables that might need to be cleared
203 set (OPENEXR_CACHED_VARS
204   OPENEXR_INCLUDE_DIR ${OpenEXR_cachevars}
205   CACHE INTERNAL "Variables set by FindOpenEXR.cmake" FORCE)
206
207 # Store the current state so that variables might be cleared if required
208 set (OPENEXR_CACHED_STATE ${OPENEXR_CURRENT_STATE}
209   CACHE INTERNAL "State last seen by FindOpenEXR.cmake" FORCE)
210
211 # Always link explicitly with zlib
212 set (OPENEXR_ZLIB ${ZLIB_LIBRARIES})
213
214 # Use the standard function to handle OPENEXR_FOUND
215 FIND_PACKAGE_HANDLE_STANDARD_ARGS (OpenEXR DEFAULT_MSG
216   OPENEXR_INCLUDE_DIR ${OpenEXR_libvars})
217
218 if (OPENEXR_FOUND)
219   set (OPENEXR_LIBRARIES "")
220   foreach (tmplib ${OpenEXR_libvars})
221     list (APPEND OPENEXR_LIBRARIES ${${tmplib}})
222   endforeach ()
223   list (APPEND OPENEXR_LIBRARIES ${ZLIB_LIBRARIES})
224   if (NOT OpenEXR_FIND_QUIETLY)
225     FIND_PACKAGE_MESSAGE (OPENEXR
226       "Found OpenEXR: ${OPENEXR_LIBRARIES}"
227       "[${OPENEXR_INCLUDE_DIR}][${OPENEXR_LIBRARIES}][${OPENEXR_CURRENT_STATE}]"
228       )
229   endif ()
230 endif ()
231
232 # Restore the original find library ordering
233 if( OPENEXR_USE_STATIC_LIBS )
234   set(CMAKE_FIND_LIBRARY_SUFFIXES ${_openexr_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
235 endif()
236
237 # Unset the helper variables to avoid pollution
238 unset (OPENEXR_CURRENT_STATE)
239 unset (OpenEXR_include_paths)
240 unset (OpenEXR_library_paths)
241 unset (OpenEXR_generic_include_paths)
242 unset (OpenEXR_generic_library_paths)
243 unset (OpenEXR_libvars)
244 unset (OpenEXR_cachevars)