Manipulator: limit UI for locked views
[blender.git] / build_files / build_environment / patches / cmake / modules / FindIlmBase.cmake
1 # Module to find IlmBase
2 #
3 # This module will first look into the directories defined by the variables:
4 #   - ILMBASE_HOME, ILMBASE_VERSION, ILMBASE_LIB_AREA
5 #
6 # It also supports non-standard names for the library components.
7 #
8 # To use a custom IlmBase:
9 #   - Set the variable ILMBASE_CUSTOM to True
10 #   - Set the variable ILMBASE_CUSTOM_LIBRARIES to a list of the libraries to
11 #     use, e.g. "SpiImath SpiHalf SpiIlmThread SpiIex"
12 #   - Optionally set the variable ILMBASE_CUSTOM_INCLUDE_DIR to any
13 #     particularly weird place that the OpenEXR/*.h files may be found
14 #   - Optionally set the variable ILMBASE_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 # ILMBASE_INCLUDE_DIR - where to find half.h, IlmBaseConfig.h, etc.
20 # ILMBASE_LIBRARIES   - list of libraries to link against when using IlmBase.
21 # ILMBASE_FOUND       - True if IlmBase was found.
22
23 # Other standarnd issue macros
24 include (FindPackageHandleStandardArgs)
25 include (FindPackageMessage)
26 include (SelectLibraryConfigurations)
27
28
29 if( ILMBASE_USE_STATIC_LIBS )
30   set( _ilmbase_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
31   if(WIN32)
32     set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
33   else()
34     set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
35   endif()
36 endif()
37
38 # Macro to assemble a helper state variable
39 macro (SET_STATE_VAR varname)
40   set (tmp_ilmbaselibs ${ILMBASE_CUSTOM_LIBRARIES})
41   separate_arguments (tmp_ilmbaselibs)
42   set (tmp_lst
43     ${ILMBASE_CUSTOM} | ${tmp_ilmbaselibs} |
44     ${ILMBASE_HOME} | ${ILMBASE_VERSION} | ${ILMBASE_LIB_AREA}
45   )
46   set (${varname} "${tmp_lst}")
47   unset (tmp_ilmbaselibs)
48   unset (tmp_lst)
49 endmacro ()
50
51 # To enforce that find_* functions do not use inadvertently existing versions
52 if (ILMBASE_CUSTOM)
53   set (ILMBASE_FIND_OPTIONS "NO_DEFAULT_PATH")
54 endif ()
55
56 # Macro to search for an include directory
57 macro (PREFIX_FIND_INCLUDE_DIR prefix includefile libpath_var)
58   string (TOUPPER ${prefix}_INCLUDE_DIR tmp_varname)
59   find_path(${tmp_varname} ${includefile}
60     HINTS ${${libpath_var}}
61     PATH_SUFFIXES include
62     ${ILMBASE_FIND_OPTIONS}
63   )
64   if (${tmp_varname})
65     mark_as_advanced (${tmp_varname})
66   endif ()
67   unset (tmp_varname)
68 endmacro ()
69
70
71 # Macro to search for the given library and adds the cached
72 # variable names to the specified list
73 macro (PREFIX_FIND_LIB prefix libname libpath_var liblist_var cachelist_var)
74   string (TOUPPER ${prefix}_${libname} tmp_prefix)
75   # Handle new library names for OpenEXR 2.1 build via cmake
76   string(REPLACE "." "_" _ILMBASE_VERSION ${ILMBASE_VERSION})
77   string(SUBSTRING ${_ILMBASE_VERSION} 0 3 _ILMBASE_VERSION )
78   
79   find_library(${tmp_prefix}_LIBRARY_RELEASE
80     NAMES ${libname} ${libname}-${_ILMBASE_VERSION}
81     HINTS ${${libpath_var}}
82     PATH_SUFFIXES lib
83     ${ILMBASE_FIND_OPTIONS}
84   )
85   find_library(${tmp_prefix}_LIBRARY_DEBUG
86     NAMES ${libname}d ${libname}_d ${libname}debug ${libname}_debug
87     HINTS ${${libpath_var}}
88     PATH_SUFFIXES lib
89     ${ILMBASE_FIND_OPTIONS}
90   )
91   # Properly define ${tmp_prefix}_LIBRARY (cached) and ${tmp_prefix}_LIBRARIES
92   select_library_configurations (${tmp_prefix})
93   list (APPEND ${liblist_var} ${tmp_prefix}_LIBRARIES)
94
95   # Add to the list of variables which should be reset
96   list (APPEND ${cachelist_var}
97     ${tmp_prefix}_LIBRARY
98     ${tmp_prefix}_LIBRARY_RELEASE
99     ${tmp_prefix}_LIBRARY_DEBUG)
100   mark_as_advanced (
101     ${tmp_prefix}_LIBRARY
102     ${tmp_prefix}_LIBRARY_RELEASE
103     ${tmp_prefix}_LIBRARY_DEBUG)
104   unset (tmp_prefix)
105 endmacro ()
106
107
108 # Encode the current state of the external variables into a string
109 SET_STATE_VAR (ILMBASE_CURRENT_STATE)
110
111 # If the state has changed, clear the cached variables
112 if (ILMBASE_CACHED_STATE AND
113     NOT ILMBASE_CACHED_STATE STREQUAL ILMBASE_CURRENT_STATE)
114
115   foreach (libvar ${ILMBASE_CACHED_VARS})
116     unset (${libvar} CACHE)
117   endforeach ()
118 endif ()
119
120
121 # Generic search paths
122 set (IlmBase_generic_include_paths
123   ${ILMBASE_CUSTOM_INCLUDE_DIR}
124   /usr/include
125   /usr/include/${CMAKE_LIBRARY_ARCHITECTURE}
126   /usr/local/include
127   /sw/include
128   /opt/local/include)
129 set (IlmBase_generic_library_paths
130   ${ILMBASE_CUSTOM_LIB_DIR}
131   /usr/lib
132   /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}
133   /usr/local/lib
134   /usr/local/lib/${CMAKE_LIBRARY_ARCHITECTURE}
135   /sw/lib
136   /opt/local/lib)
137
138 # Search paths for the IlmBase files
139 if (ILMBASE_HOME)
140   if (ILMBASE_VERSION)
141     set (IlmBase_include_paths
142       ${ILMBASE_HOME}/ilmbase-${ILMBASE_VERSION}/include
143       ${ILMBASE_HOME}/include/ilmbase-${ILMBASE_VERSION})
144     set (IlmBase_library_paths
145       ${ILMBASE_HOME}/ilmbase-${ILMBASE_VERSION}/lib
146       ${ILMBASE_HOME}/lib/ilmbase-${ILMBASE_VERSION})
147   endif()
148   list (APPEND IlmBase_include_paths ${ILMBASE_HOME}/include)
149   set (IlmBase_library_paths
150     ${ILMBASE_HOME}/lib
151     ${ILMBASE_HOME}/lib64
152     ${ILMBASE_LIB_AREA}
153     ${IlmBase_library_paths})
154 endif ()
155 list (APPEND IlmBase_include_paths ${IlmBase_generic_include_paths})
156 list (APPEND IlmBase_library_paths ${IlmBase_generic_library_paths})
157
158 # Locate the header files
159 PREFIX_FIND_INCLUDE_DIR (IlmBase
160   OpenEXR/IlmBaseConfig.h IlmBase_include_paths)
161
162 if (ILMBASE_INCLUDE_DIR)
163   # Get the version from config file, if not already set.
164   if (NOT ILMBASE_VERSION)
165     FILE(STRINGS "${ILMBASE_INCLUDE_DIR}/OpenEXR/IlmBaseConfig.h" ILMBASE_BUILD_SPECIFICATION
166          REGEX "^[ \t]*#define[ \t]+ILMBASE_VERSION_STRING[ \t]+\"[.0-9]+\".*$")
167
168     if(ILMBASE_BUILD_SPECIFICATION)
169       if (NOT IlmBase_FIND_QUIETLY)
170         message(STATUS "${ILMBASE_BUILD_SPECIFICATION}")
171       endif ()
172       string(REGEX REPLACE ".*#define[ \t]+ILMBASE_VERSION_STRING[ \t]+\"([.0-9]+)\".*"
173              "\\1" XYZ ${ILMBASE_BUILD_SPECIFICATION})
174       set("ILMBASE_VERSION" ${XYZ} CACHE STRING "Version of ILMBase 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("ILMBASE_VERSION" "2.0" CACHE STRING "Version of ILMBase lib")
179     endif()
180   endif()
181 endif ()
182
183
184 if (ILMBASE_CUSTOM)
185   if (NOT ILMBASE_CUSTOM_LIBRARIES)
186     message (FATAL_ERROR "Custom IlmBase libraries requested but ILMBASE_CUSTOM_LIBRARIES is not set.")
187   endif()
188   set (IlmBase_Libraries ${ILMBASE_CUSTOM_LIBRARIES})
189   separate_arguments(IlmBase_Libraries)
190 else ()
191 #elseif (${ILMBASE_VERSION} VERSION_LESS "2.1")
192   set (IlmBase_Libraries Half Iex Imath IlmThread)
193 #else ()
194 #  string(REGEX REPLACE "([0-9]+)[.]([0-9]+).*" "\\1_\\2" _ilmbase_libs_ver ${ILMBASE_VERSION})
195 #  set (IlmBase_Libraries Half Iex-${_ilmbase_libs_ver} Imath-${_ilmbase_libs_ver} IlmThread-${_ilmbase_libs_ver})
196 endif ()
197
198
199 # Locate the IlmBase libraries
200 set (IlmBase_libvars "")
201 set (IlmBase_cachevars "")
202 foreach (ilmbase_lib ${IlmBase_Libraries})
203   PREFIX_FIND_LIB (IlmBase ${ilmbase_lib}
204     IlmBase_library_paths IlmBase_libvars IlmBase_cachevars)
205 endforeach ()
206 # Create the list of variables that might need to be cleared
207 set (ILMBASE_CACHED_VARS
208   ILMBASE_INCLUDE_DIR ${IlmBase_cachevars}
209   CACHE INTERNAL "Variables set by FindIlmBase.cmake" FORCE)
210
211 # Store the current state so that variables might be cleared if required
212 set (ILMBASE_CACHED_STATE ${ILMBASE_CURRENT_STATE}
213   CACHE INTERNAL "State last seen by FindIlmBase.cmake" FORCE)
214
215 # Link with pthreads if required
216 if (NOT WIN32 AND EXISTS ${ILMBASE_INCLUDE_DIR}/OpenEXR/IlmBaseConfig.h)
217   file (STRINGS ${ILMBASE_INCLUDE_DIR}/OpenEXR/IlmBaseConfig.h
218     ILMBASE_HAVE_PTHREAD
219     REGEX "^[ \\t]*#define[ \\t]+HAVE_PTHREAD[ \\t]1[ \\t]*\$"
220   )
221   if (ILMBASE_HAVE_PTHREAD)
222     find_package (Threads)
223     if (CMAKE_USE_PTHREADS_INIT)
224       set (ILMBASE_PTHREADS ${CMAKE_THREAD_LIBS_INIT})
225     endif ()
226   endif ()
227 endif ()
228
229 # Use the standard function to handle ILMBASE_FOUND
230 FIND_PACKAGE_HANDLE_STANDARD_ARGS (IlmBase DEFAULT_MSG
231   ILMBASE_INCLUDE_DIR ${IlmBase_libvars})
232
233 if (ILMBASE_FOUND)
234   set (ILMBASE_LIBRARIES "")
235   foreach (tmplib ${IlmBase_libvars})
236     list (APPEND ILMBASE_LIBRARIES ${${tmplib}})
237   endforeach ()
238   list (APPEND ILMBASE_LIBRARIES ${ILMBASE_PTHREADS})
239   if (NOT IlmBase_FIND_QUIETLY)
240     FIND_PACKAGE_MESSAGE (ILMBASE
241       "Found IlmBase: ${ILMBASE_LIBRARIES}"
242       "[${ILMBASE_INCLUDE_DIR}][${ILMBASE_LIBRARIES}][${ILMBASE_CURRENT_STATE}]"
243       )
244   endif ()
245 endif ()
246
247 # Restore the original find library ordering
248 if( ILMBASE_USE_STATIC_LIBS )
249   set(CMAKE_FIND_LIBRARY_SUFFIXES ${_ilmbase_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
250 endif()
251
252 # Unset the helper variables to avoid pollution
253 unset (ILMBASE_CURRENT_STATE)
254 unset (IlmBase_include_paths)
255 unset (IlmBase_library_paths)
256 unset (IlmBase_generic_include_paths)
257 unset (IlmBase_generic_library_paths)
258 unset (IlmBase_libvars)
259 unset (IlmBase_cachevars)
260 unset (ILMBASE_PTHREADS)