CMake: Add a flag to explicitly disable SSE/SSE2 intrinsics
[blender.git] / CMakeLists.txt
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # The Original Code is Copyright (C) 2006, Blender Foundation
18 # All rights reserved.
19 #
20 # The Original Code is: all of this file.
21 #
22 # Contributor(s): Jacques Beaurain.
23 #
24 # ***** END GPL LICENSE BLOCK *****
25
26 #-----------------------------------------------------------------------------
27 # We don't allow in-source builds. This causes no end of troubles because
28 # all out-of-source builds will use the CMakeCache.txt file there and even
29 # build the libs and objects in it.
30
31 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
32         if(NOT DEFINED WITH_IN_SOURCE_BUILD)
33                 message(FATAL_ERROR
34                         "CMake generation for blender is not allowed within the source directory!"
35                         "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
36                         "\n "
37                         "\n rm CMakeCache.txt"
38                         "\n cd .."
39                         "\n mkdir cmake-make"
40                         "\n cd cmake-make"
41                         "\n cmake ../blender"
42                         "\n "
43                         "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
44                 )
45         endif()
46 endif()
47
48 cmake_minimum_required(VERSION 2.8)
49
50 if(NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
51         # keep until CMake-3.0 is min requirement
52         cmake_policy(SET CMP0043 OLD)
53 endif()
54
55 if(NOT EXECUTABLE_OUTPUT_PATH)
56         set(FIRST_RUN "TRUE")
57 endif()
58
59 # this starts out unset
60 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
61
62 # avoid having empty buildtype
63 set(CMAKE_BUILD_TYPE_INIT "Release")
64
65 # quiet output for Makefiles, 'make -s' helps too
66 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
67
68 # global compile definitions since add_definitions() adds for all.
69 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
70 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
71 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
72 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
73
74
75 #-----------------------------------------------------------------------------
76 # Set policy
77
78 # see "cmake --help-policy CMP0003"
79 # So library linking is more sane
80 cmake_policy(SET CMP0003 NEW)
81
82 # So BUILDINFO and BLENDERPATH strings are automatically quoted
83 cmake_policy(SET CMP0005 NEW)
84
85 # So syntax problems are errors
86 cmake_policy(SET CMP0010 NEW)
87
88 # Input directories must have CMakeLists.txt
89 cmake_policy(SET CMP0014 NEW)
90
91 #-----------------------------------------------------------------------------
92 # Load some macros.
93 include(build_files/cmake/macros.cmake)
94
95
96 #-----------------------------------------------------------------------------
97 # Initialize project.
98
99 blender_project_hack_pre()
100
101 project(Blender)
102
103 blender_project_hack_post()
104
105 enable_testing()
106
107 #-----------------------------------------------------------------------------
108 # Redirect output files
109
110 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
111 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
112 set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests CACHE INTERNAL "" FORCE)
113
114 #-----------------------------------------------------------------------------
115 # Set default config options
116
117 get_blender_version()
118
119
120 # Blender internal features
121 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
122 mark_as_advanced(WITH_BLENDER)
123
124 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
125
126 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
127 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON) 
128 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
129 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distributions see this as a security issue, rather than have them patch it, make a build option.
130 set(WITH_PYTHON_SECURITY ON CACHE BOOL "ON" FORCE) # temp force on. 
131
132 option(WITH_PYTHON_SAFETY "Enable internal API error checking to track invalid data to prevent crash on access (at the expense of some effeciency, only enable for development)." OFF)
133 option(WITH_PYTHON_MODULE "Enable building as a python module which runs without a user interface, like running regular blender in background mode (experimental, only enable for development)" OFF)
134 if(APPLE)
135         option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
136 endif()
137
138 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
139 if(${CMAKE_VERSION} VERSION_LESS 2.8.8)
140         # add_library OBJECT arg unsupported
141         set(WITH_BUILDINFO OFF)
142 endif()
143
144 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
145 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
146 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" ON)
147 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
148 option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
149 mark_as_advanced(WITH_SYSTEM_BULLET)
150 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
151 option(WITH_PLAYER        "Build Player" OFF)
152 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ON)
153 option(WITH_COMPOSITOR    "Enable the tile based nodal compositor" ON)
154
155 # GHOST Windowing Library Options
156 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
157 mark_as_advanced(WITH_GHOST_DEBUG)
158
159 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
160 mark_as_advanced(WITH_GHOST_SDL)
161
162 # Misc...
163 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
164 mark_as_advanced(WITH_HEADLESS)
165
166 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
167 mark_as_advanced(WITH_AUDASPACE)
168
169 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
170
171 if(UNIX AND NOT APPLE)
172         set(WITH_X11 ON)
173 endif()
174
175 if(WITH_X11)
176         option(WITH_X11_XINPUT    "Enable X11 Xinput (tablet support and unicode input)"  ON)
177         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"                       ON)
178         option(WITH_GHOST_XDND    "Enable drag'n'drop support on X11 using XDND protocol" ON)
179 endif()
180
181 if(UNIX AND NOT APPLE)
182         option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" ON)
183         option(WITH_SYSTEM_GLES "Use OpenGL ES library provided by the operating system"           ON)
184 else()
185         # not an option for other OS's
186         set(WITH_SYSTEM_GLEW OFF)
187         set(WITH_SYSTEM_GLES OFF)
188 endif()
189
190
191 # (unix defaults to System OpenJPEG On)
192 if(UNIX AND NOT APPLE)
193         set(PLATFORM_DEFAULT ON)
194 else()
195         set(PLATFORM_DEFAULT OFF)
196 endif()
197 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" ${PLATFORM_DEFAULT})
198 unset(PLATFORM_DEFAULT)
199
200
201 # Modifiers
202 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
203 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
204 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
205 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
206 # option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)  # this is now only available in a branch
207 # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
208 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
209
210 # Image format support
211 option(WITH_OPENIMAGEIO         "Enable OpenImageIO Support (http://www.openimageio.org)" OFF)
212 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
213 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
214 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
215 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
216 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
217 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
218 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
219 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
220
221 # Audio/Video format support
222 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
223 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
224 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
225
226 if(APPLE)
227         option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ON)
228         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" ON)
229 else()
230         option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
231 endif()
232
233 # 3D format support
234 # Disable opencollada when we don't have precompiled libs
235 if(APPLE OR WIN32)
236         option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)" ON)
237 else()
238         option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)" OFF)
239 endif()
240
241 # Sound output
242 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
243 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
244 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
245 if(UNIX AND NOT APPLE)
246         option(WITH_JACK_DYNLOAD  "Enable runtime dynamic Jack libraries loading" OFF)
247 endif()
248
249 # Compression
250 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
251 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
252
253 # Camera/motion tracking
254 option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
255 option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." ON)
256
257 # Freestyle
258 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
259
260 # Misc
261 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
262 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
263 option(WITH_OPENNL        "Enable use of Open Numerical Library" ON)
264 if(UNIX AND NOT APPLE)
265         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
266         option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
267         if(WITH_STATIC_LIBS)
268                 option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
269                 mark_as_advanced(WITH_BOOST_ICU)
270         endif()
271 endif()
272 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
273 option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
274 set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
275 mark_as_advanced(PYTHON_NUMPY_PATH)
276 option(WITH_CPU_SSE              "Enable SIMD instruction if they're detected on the host machine" ON)
277 mark_as_advanced(WITH_CPU_SSE)
278
279 if(UNIX AND NOT APPLE)
280         option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
281         set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
282         mark_as_advanced(PYTHON_REQUESTS_PATH)
283 endif()
284
285 # Cycles
286 option(WITH_CYCLES                                      "Enable cycles Render Engine" ON)
287 option(WITH_CYCLES_STANDALONE           "Build cycles standalone application" OFF)
288 option(WITH_CYCLES_STANDALONE_GUI       "Build cycles standalone with GUI" OFF)
289 option(WITH_CYCLES_OSL                          "Build Cycles with OSL support" OFF)
290 option(WITH_CYCLES_CUDA_BINARIES        "Build cycles CUDA binaries" OFF)
291 set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_50 CACHE STRING "CUDA architectures to build binaries for")
292 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
293 unset(PLATFORM_DEFAULT)
294 option(WITH_CYCLES_LOGGING      "Build cycles with logging support" OFF)
295 option(WITH_CYCLES_DEBUG        "Build cycles with with extra debug capabilties" OFF)
296 mark_as_advanced(WITH_CYCLES_LOGGING)
297 mark_as_advanced(WITH_CYCLES_DEBUG)
298
299 # LLVM
300 option(WITH_LLVM                                        "Use LLVM" OFF)
301 if(APPLE)
302         option(LLVM_STATIC                                      "Link with LLVM static libraries" ON) # we prefer static llvm build on Apple, dyn build possible though
303 else()
304         option(LLVM_STATIC                                      "Link with LLVM static libraries" OFF)
305 endif()
306 mark_as_advanced(LLVM_STATIC)
307
308 # disable for now, but plan to support on all platforms eventually
309 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
310 mark_as_advanced(WITH_MEM_JEMALLOC)
311
312 # currently only used for BLI_mempool
313 option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
314 mark_as_advanced(WITH_MEM_VALGRIND)
315
316 # Debug
317 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
318 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
319
320 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
321 mark_as_advanced(WITH_ASSERT_ABORT)
322
323 option(WITH_BOOST                                       "Enable features depending on boost" ON)
324
325 if(CMAKE_COMPILER_IS_GNUCC)
326         option(WITH_GCC_MUDFLAP                 "Enable mudflap" OFF)
327         mark_as_advanced(WITH_GCC_MUDFLAP)
328 endif()
329
330 # Unit testsing
331 option(WITH_GTESTS "Enable GTest unit testing" OFF)
332
333 # OpenGL
334
335 option(WITH_GLEW_MX             "Support multiple GLEW contexts (experimental)"                                                                     OFF )
336 option(WITH_GLEW_ES             "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
337 option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)"       OFF)
338 option(WITH_GL_PROFILE_COMPAT   "Support using the OpenGL 'compatibility' profile. (deprecated)"                                                    ON )
339 option(WITH_GL_PROFILE_CORE     "Support using the OpenGL 3.2+ 'core' profile."                                                                     OFF)
340 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (thru either EGL or the AGL/WGL/XGL 'es20' profile)"                                  OFF)
341
342 mark_as_advanced(
343         WITH_GLEW_MX
344         WITH_GLEW_ES
345         WITH_GL_EGL
346         WITH_GL_PROFILE_COMPAT
347         WITH_GL_PROFILE_CORE
348         WITH_GL_PROFILE_ES20
349 )
350
351 if (WITH_GL_PROFILE_COMPAT)
352         set(WITH_GLU ON)
353 else()
354         set(WITH_GLU OFF)
355 endif()
356
357 if(WIN32)
358         option(WITH_GL_ANGLE "Link with the ANGLE library, an OpenGL ES 2.0 implementation based on Direct3D, instead of the system OpenGL library." OFF)
359         mark_as_advanced(WITH_GL_ANGLE)
360 endif()
361
362 if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
363         message(WARNING Ignoring WITH_SYSTEM_GLEW and using WITH_GLEW_ES)
364         set(WITH_SYSTEM_GLEW OFF)
365 endif()
366
367 # Apple
368
369 if(APPLE)
370         if(${CMAKE_VERSION} VERSION_LESS 3.0) # else breaks setting CMP0043 policy
371                 cmake_minimum_required(VERSION 2.8.8)
372                 cmake_policy(VERSION 2.8.8)
373         endif()
374
375         if(NOT CMAKE_OSX_ARCHITECTURES)
376                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
377                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
378                 FORCE)
379         endif()
380         
381         execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
382         if(${MAC_SYS} MATCHES 14)
383                 set(OSX_SYSTEM 10.10)
384                 # throw an error here, older cmake cannot handle 2 digit subversion!
385                 cmake_minimum_required(VERSION 3.0.0)
386         elseif(${MAC_SYS} MATCHES 13)
387                 set(OSX_SYSTEM 10.9)
388         elseif(${MAC_SYS} MATCHES 12)
389                 set(OSX_SYSTEM 10.8)
390         elseif(${MAC_SYS} MATCHES 11)
391                 set(OSX_SYSTEM 10.7)
392         elseif(${MAC_SYS} MATCHES 10)
393                 set(OSX_SYSTEM 10.6)
394         elseif(${MAC_SYS} MATCHES 9)
395                 set(OSX_SYSTEM 10.5)
396         else()
397                 set(OSX_SYSTEM unsupported)
398         endif()
399         message(STATUS "Detected system-version: " ${OSX_SYSTEM})
400         
401         # workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not take xcode-select path into accout
402         # but would always look into /Applications/Xcode.app while dev versions are named Xcode<version>-DP<preview_number>
403         execute_process(COMMAND xcode-select --print-path  OUTPUT_VARIABLE XCODE_CHECK OUTPUT_STRIP_TRAILING_WHITESPACE)
404         string(REPLACE "/Contents/Developer" "" XCODE_BUNDLE ${XCODE_CHECK}) # truncate to bundlepath in any case
405         message(STATUS "Xcode-bundle : " ${XCODE_BUNDLE})
406         
407         if(${CMAKE_GENERATOR} MATCHES "Xcode")
408         
409                 if(${XCODE_VERSION} VERSION_GREATER 4.2) # earlier xcode has no bundled developer dir, no sense in getting xcode path from
410                         string(SUBSTRING "${XCODE_CHECK}" 14 6 DP_NAME) # reduce to XCode name without dp extension
411                         if(${DP_NAME} MATCHES Xcode5)
412                                 set(XCODE_VERSION 5)
413                         endif()
414                 endif()
415
416                 ##### cmake incompatibility with xcode  4.3 and higher #####
417                 if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
418                         message(FATAL_ERROR "Xcode 4.3 and higher must be used with cmake 2.8-8 or higher")
419                 endif()
420                 ### end cmake incompatibility with xcode 4.3 and higher ###
421                 
422                 if(${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4 AND ${XCODE_VERSION} VERSION_LESS 4.3)
423                         # Xcode 4 defaults to the Apple LLVM Compiler.
424                         # Override the default compiler selection because Blender only compiles with gcc up to xcode 4.2
425                         set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
426                         message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
427                 endif()
428         else() # unix makefile generator does not fill XCODE_VERSION var, so we get it with a command
429                 execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILD_NR)
430                 string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
431                 unset(XCODE_VERS_BUILD_NR)
432         endif()
433         
434         message(STATUS "Detected Xcode-version: " ${XCODE_VERSION})
435
436         if(${XCODE_VERSION} VERSION_LESS 4.3)
437                 set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)  # use guaranteed existing sdk
438         else()
439                 # note: xcode-select path could be ambigous, cause /Applications/Xcode.app/Contents/Developer or /Applications/Xcode.app would be allowed
440                 # so i use a selfcomposed bundlepath here  
441                 set(OSX_SYSROOT_PREFIX ${XCODE_BUNDLE}/Contents/Developer/Platforms/MacOSX.platform)
442                 message(STATUS "OSX_SYSROOT_PREFIX: " ${OSX_SYSROOT_PREFIX})
443                 set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
444                 set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
445                 if(${CMAKE_GENERATOR} MATCHES "Xcode")
446                         set(CMAKE_XCODE_ATTRIBUTE_SDKROOT macosx${OSX_SYSTEM}) # to silence sdk not found warning, just overrides CMAKE_OSX_SYSROOT
447                 endif()
448         endif()
449
450         if(OSX_SYSTEM MATCHES 10.9)
451                 set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT}) # make sure syslibs and headers are looked up in sdk ( expecially for 10.9 openGL atm. )
452         endif()
453
454         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
455                 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.6" CACHE STRING "" FORCE) # 10.6 is our min. target, if you use higher sdk, weak linking happens
456         endif()
457         
458         if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
459                 # force CMAKE_OSX_DEPLOYMENT_TARGET for makefiles, will not work else ( cmake bug ? )
460                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
461                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
462                 add_definitions("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
463         endif()
464
465         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
466 endif()
467
468
469 #-----------------------------------------------------------------------------
470 # Check for conflicting/unsupported configurations
471
472 if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_STANDALONE)
473         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER or WITH_CYCLES_STANDALONE must be enabled, nothing to do!")
474 endif()
475
476 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
477         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
478 endif()
479
480 if(NOT WITH_AUDASPACE)
481         if(WITH_OPENAL)
482                 message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
483         endif()
484         if(WITH_JACK)
485                 message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
486         endif()
487         if(WITH_GAMEENGINE)
488                 message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
489         endif()
490 endif()
491
492 if(NOT WITH_SDL AND WITH_GHOST_SDL)
493         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
494 endif()
495
496 if(WITH_IMAGE_REDCODE AND ((NOT WITH_IMAGE_OPENJPEG) OR (NOT WITH_CODEC_FFMPEG)))
497         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG and WITH_CODEC_FFMPEG")
498 endif()
499
500 # python module, needs some different options
501 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
502         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
503 endif()
504
505 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
506         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
507 endif()
508
509
510 # may as well build python module without a UI
511 if(WITH_PYTHON_MODULE)
512         set(WITH_HEADLESS ON)
513 endif()
514
515 if(NOT WITH_PYTHON)
516         set(WITH_CYCLES OFF)
517 endif()
518
519 # enable boost for cycles, booleans, audaspace or i18n
520 # otherwise if the user disabled
521 if(NOT WITH_BOOST)
522         # Explicitly disabled. so disable all deps.
523         macro(set_and_warn
524                 _setting _val)
525                 if(${${_setting}})
526                         message(STATUS "'WITH_BOOST' is disabled: forceing 'set(${_setting} ${_val})'")
527                 endif()
528                 set(${_setting} ${_val})
529         endmacro()
530
531         set_and_warn(WITH_CYCLES         OFF)
532         set_and_warn(WITH_MOD_BOOLEAN    OFF)
533         set_and_warn(WITH_AUDASPACE      OFF)
534         set_and_warn(WITH_INTERNATIONAL  OFF)
535
536         set_and_warn(WITH_OPENAL         OFF)  # depends on AUDASPACE
537         set_and_warn(WITH_GAMEENGINE     OFF)  # depends on AUDASPACE
538 elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_MOD_BOOLEAN OR WITH_AUDASPACE OR WITH_INTERNATIONAL)
539         # Keep enabled
540 else()
541         # Enabled but we don't need it
542         set(WITH_BOOST OFF)
543 endif()
544
545 # auto enable openimageio for cycles
546 if(WITH_CYCLES)
547         set(WITH_OPENIMAGEIO ON)
548 endif()
549
550 # auto enable openimageio linking dependencies
551 if(WITH_OPENIMAGEIO)
552         set(WITH_IMAGE_OPENEXR ON)
553         set(WITH_IMAGE_TIFF ON)
554 endif()
555
556 # auto enable llvm for cycles_osl
557 if(WITH_CYCLES_OSL)
558         set(WITH_LLVM ON CACHE BOOL "ON" FORCE)
559 endif()
560
561 # don't store paths to libs for portable distribution
562 if(WITH_INSTALL_PORTABLE)
563         set(CMAKE_SKIP_BUILD_RPATH TRUE)
564 endif()
565
566 if(WITH_GHOST_SDL OR WITH_HEADLESS)
567         set(WITH_X11           OFF)
568         set(WITH_X11_XINPUT    OFF)
569         set(WITH_X11_XF86VMODE OFF)
570         set(WITH_GHOST_XDND    OFF)
571 endif()
572
573 if(WITH_CPU_SSE)
574         TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
575 else()
576         message(STATUS "SSE and SSE2 optimizations are DISABLED!")
577         set(COMPILER_SSE_FLAG)
578         set(COMPILER_SSE2_FLAG)
579 endif()
580
581 TEST_STDBOOL_SUPPORT()
582 if(HAVE_STDBOOL_H)
583         add_definitions(-DHAVE_STDBOOL_H)
584 endif()
585
586 #-----------------------------------------------------------------------------
587 # Check for valid directories
588 # ... a partial checkout may cause this.
589 #
590 # note: we need to check for a known subdir in both cases.
591 #       since uninitialized git submodules will give blank dirs
592
593 if(WITH_INTERNATIONAL)
594         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
595                 message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
596                                                 "This is a 'git submodule', which are known not to work with bridges to other version "
597                                                 "control systems, disabling 'WITH_INTERNATIONAL'.")
598                 set(WITH_INTERNATIONAL OFF)
599         endif()
600 endif()
601
602 if(WITH_PYTHON)
603         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
604                 message(WARNING "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
605                                                 "This is a 'git submodule', which are known not to work with bridges to other version "
606                                                 "control systems: * CONTINUING WITHOUT ADDONS *")
607         endif()
608 endif()
609
610 #-----------------------------------------------------------------------------
611 # Initialize un-cached vars, avoid unused warning
612
613 # linux only, not cached
614 set(WITH_BINRELOC OFF)
615
616 # MAXOSX only, set to avoid uninitialized
617 set(EXETYPE "")
618
619 # C/C++ flags
620 set(PLATFORM_CFLAGS)
621
622 # these are added to later on.
623 set(C_WARNINGS)
624 set(CXX_WARNINGS)
625
626 # for gcc -Wno-blah-blah
627 set(CC_REMOVE_STRICT_FLAGS)
628
629 # libraries to link the binary with passed to target_link_libraries()
630 # known as LLIBS to scons
631 set(PLATFORM_LINKLIBS "")
632
633 # Added to linker flags in setup_liblinks
634 # - CMAKE_EXE_LINKER_FLAGS
635 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
636 set(PLATFORM_LINKFLAGS "")
637 set(PLATFORM_LINKFLAGS_DEBUG "")
638
639
640 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
641 # On Unix:
642 #   cmake ../blender \
643 #         -D PYTHON_VERSION=3.4 \
644 #         -D PYTHON_INCLUDE_DIR=/opt/py34/include/python3.4d \
645 #         -D PYTHON_LIBRARY=/opt/py34/lib/libpython3.4d.so
646 #
647 # On Macs:
648 #   cmake ../blender \
649 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4 \
650 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/config \
651 #         -G Xcode
652 #
653 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
654
655 #-----------------------------------------------------------------------------
656 #Platform specifics
657
658 if(WITH_X11)
659         find_package(X11 REQUIRED)
660
661         find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
662         mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
663
664         list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
665
666         if(WITH_X11_XINPUT)
667                 if(X11_Xinput_LIB)
668                         list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
669                 else()
670                         set(WITH_X11_XINPUT OFF)
671                 endif()
672         endif()
673
674         if(WITH_X11_XF86VMODE)
675                 # XXX, why dont cmake make this available?
676                 find_library(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
677                 mark_as_advanced(X11_Xxf86vmode_LIB)
678                 if(X11_Xxf86vmode_LIB)
679                         list(APPEND PLATFORM_LINKLIBS ${X11_Xxf86vmode_LIB})
680                 else()
681                         set(WITH_X11_XF86VMODE OFF)
682                 endif()
683         endif()
684
685 endif()
686
687 if(UNIX AND NOT APPLE)
688         macro(find_package_wrapper)
689                 string(TOUPPER ${ARGV0} _NAME_UPPER)
690                 if(WITH_STATIC_LIBS)
691                         set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
692                         set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
693                 endif()
694                 find_package(${ARGV})
695                 if(WITH_STATIC_LIBS)
696                         set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
697                         unset(_cmake_find_library_suffixes_back)
698                 endif()
699         endmacro()
700
701         find_package_wrapper(JPEG REQUIRED)
702         find_package_wrapper(PNG REQUIRED)
703         find_package_wrapper(ZLIB REQUIRED)
704         find_package_wrapper(Freetype REQUIRED)
705
706         if(WITH_PYTHON)
707                 # No way to set py34. remove for now.
708                 # find_package(PythonLibs)
709
710                 # Use our own instead, since wothout py is such a rare case,
711                 # require this package
712                 # XXX Linking errors with debian static python :/
713 #               find_package_wrapper(PythonLibsUnix REQUIRED)
714                 find_package(PythonLibsUnix REQUIRED)
715         endif()
716
717         if(WITH_IMAGE_OPENEXR)
718                 find_package_wrapper(OpenEXR)  # our own module
719                 if(NOT OPENEXR_FOUND)
720                         set(WITH_IMAGE_OPENEXR OFF)
721                 endif()
722         endif()
723
724         if(WITH_IMAGE_OPENJPEG)
725                 find_package_wrapper(OpenJPEG)
726                 if(NOT OPENJPEG_FOUND)
727                         set(WITH_IMAGE_OPENJPEG OFF)
728                 endif()
729         endif()
730
731         if(WITH_IMAGE_TIFF)
732                 # XXX Linking errors with debian static tiff :/
733 #               find_package_wrapper(TIFF)
734                 find_package(TIFF)
735                 if(NOT TIFF_FOUND)
736                         set(WITH_IMAGE_TIFF OFF)
737                 endif()
738         endif()
739
740         # Audio IO
741         if(WITH_OPENAL)
742                 find_package_wrapper(OpenAL)
743                 if(NOT OPENAL_FOUND)
744                         set(WITH_OPENAL OFF)
745                 endif()
746         endif()
747
748         if(WITH_SDL)
749                 find_package_wrapper(SDL)
750                 mark_as_advanced(
751                         SDLMAIN_LIBRARY
752                         SDL_INCLUDE_DIR
753                         SDL_LIBRARY
754                         SDL_LIBRARY_TEMP
755                 )
756                 # unset(SDLMAIN_LIBRARY CACHE)
757                 if(NOT SDL_FOUND)
758                         set(WITH_SDL OFF)
759                 endif()
760         endif()
761
762         if(WITH_JACK)
763                 find_package_wrapper(Jack)
764                 if(NOT JACK_FOUND)
765                         set(WITH_JACK OFF)
766                 endif()
767         endif()
768
769         # Codecs
770         if(WITH_CODEC_SNDFILE)
771                 find_package_wrapper(SndFile)
772                 if(NOT SNDFILE_FOUND)
773                         set(WITH_CODEC_SNDFILE OFF)
774                 endif()
775         endif()
776
777         if(WITH_CODEC_FFMPEG)
778                 set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
779                 set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
780
781                 mark_as_advanced(FFMPEG)
782
783                 # lame, but until we have proper find module for ffmpeg
784                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
785                 if(EXISTS "${FFMPEG}/include/ffmpeg/")
786                         list(APPEND FFMPEG_INCLUDE_DIRS "${FFMPEG}/include/ffmpeg")
787                 endif()
788                 # end lameness
789
790                 mark_as_advanced(FFMPEG_LIBRARIES)
791                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
792                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
793         endif()
794
795         if(WITH_FFTW3)
796                 find_package_wrapper(Fftw3)
797                 if(NOT FFTW3_FOUND)
798                         set(WITH_FFTW3 OFF)
799                 endif()
800         endif()
801
802         if(WITH_OPENCOLLADA)
803                 find_package_wrapper(OpenCOLLADA)
804                 if(OPENCOLLADA_FOUND)
805                         find_package_wrapper(XML2)
806                         find_package_wrapper(PCRE)
807                 else()
808                         set(WITH_OPENCOLLADA OFF)
809                 endif()
810         endif()
811
812         if(WITH_MEM_JEMALLOC)
813                 find_package_wrapper(JeMalloc)
814                 if(NOT JEMALLOC_FOUND)
815                         set(WITH_MEM_JEMALLOC OFF)
816                 endif()
817         endif()
818
819         if(WITH_INPUT_NDOF)
820                 find_package_wrapper(Spacenav)
821                 if(NOT SPACENAV_FOUND)
822                         set(WITH_INPUT_NDOF OFF)
823                 endif()
824
825                 # use generic names within blenders buildsystem.
826                 if(SPACENAV_FOUND)
827                         set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
828                         set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
829                 endif()
830         endif()
831
832         if(WITH_BOOST)
833                 # uses in build instructions to override include and library variables
834                 if(NOT BOOST_CUSTOM)
835                         if(WITH_STATIC_LIBS)
836                                 set(Boost_USE_STATIC_LIBS ON)
837                         endif()
838                         set(Boost_USE_MULTITHREADED ON)
839                         set(__boost_packages filesystem regex system thread date_time)
840                         if(WITH_INTERNATIONAL)
841                                 list(APPEND __boost_packages locale)
842                         endif()
843                         if(WITH_CYCLES_NETWORK)
844                                 list(APPEND __boost_packages serialization)
845                         endif()
846                         find_package(Boost 1.48 COMPONENTS ${__boost_packages})
847                         if(NOT Boost_FOUND)
848                                 # try to find non-multithreaded if -mt not found, this flag
849                                 # doesn't matter for us, it has nothing to do with thread
850                                 # safety, but keep it to not disturb build setups
851                                 set(Boost_USE_MULTITHREADED OFF)
852                                 find_package(Boost 1.48 COMPONENTS ${__boost_packages})
853                         endif()
854                         unset(__boost_packages)
855                         if(Boost_USE_STATIC_LIBS AND WITH_BOOST_ICU)
856                                 find_package(IcuLinux)
857                         endif()
858                         mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
859                 endif()
860
861                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
862                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
863                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
864                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
865         endif()
866
867         if(WITH_OPENIMAGEIO)
868                 find_package_wrapper(OpenImageIO)
869
870                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
871                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
872                 set(OPENIMAGEIO_DEFINITIONS "")
873
874                 if(WITH_IMAGE_TIFF)
875                         list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}")
876                 endif()
877                 if(WITH_IMAGE_OPENEXR)
878                         list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}")
879                 endif()
880
881                 if(NOT OPENIMAGEIO_FOUND)
882                         set(WITH_OPENIMAGEIO OFF)
883                         message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
884                 endif()
885         endif()
886
887         if(WITH_OPENCOLORIO)
888                 find_package_wrapper(OpenColorIO)
889
890                 set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
891                 set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
892                 set(OPENCOLORIO_DEFINITIONS)
893
894                 if(NOT OPENCOLORIO_FOUND)
895                         set(WITH_OPENCOLORIO OFF)
896                         message(STATUS "OpenColorIO not found")
897                 endif()
898         endif()
899
900         # XXX Maybe most of this section should go into an llvm module?
901         if(WITH_LLVM)
902                 # Set llvm version if not specified
903                 if(NOT LLVM_VERSION)
904                         set(LLVM_VERSION "3.0")
905                 endif()
906
907                 if(LLVM_DIRECTORY)
908                         find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
909                         if(NOT LLVM_CONFIG)
910                                 find_program(LLVM_CONFIG llvm-config HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
911                         endif()
912                 else()
913                         find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION})
914                         if(NOT LLVM_CONFIG)
915                                 find_program(LLVM_CONFIG llvm-config)
916                         endif()
917                 endif()
918
919                 if(NOT DEFINED LLVM_VERSION)
920                         execute_process(COMMAND ${LLVM_CONFIG} --version
921                                                         OUTPUT_VARIABLE LLVM_VERSION
922                                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
923                         set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
924                 endif()
925                 if(NOT DEFINED LLVM_DIRECTORY)
926                         execute_process(COMMAND ${LLVM_CONFIG} --prefix
927                                                         OUTPUT_VARIABLE LLVM_DIRECTORY
928                                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
929                         set(LLVM_DIRECTORY ${LLVM_DIRECTORY} CACHE PATH "Path to the LLVM installation")
930                 endif()
931                 if(NOT DEFINED LLVM_LIBPATH)
932                         execute_process(COMMAND ${LLVM_CONFIG} --libdir
933                                                         OUTPUT_VARIABLE LLVM_LIBPATH
934                                                         OUTPUT_STRIP_TRAILING_WHITESPACE)
935                         set(LLVM_LIBPATH ${LLVM_LIBPATH} CACHE PATH "Path to the LLVM library path")
936                         mark_as_advanced(LLVM_LIBPATH)
937                 endif()
938
939                 if(LLVM_STATIC)
940                         find_library(LLVM_LIBRARY
941                                      NAMES LLVMAnalysis # first of a whole bunch of libs to get
942                                      PATHS ${LLVM_LIBPATH})
943                 else()
944                         find_library(LLVM_LIBRARY
945                                      NAMES LLVM-${LLVM_VERSION}
946                                      PATHS ${LLVM_LIBPATH})
947                 endif()
948
949
950                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIBPATH)
951                         if(LLVM_STATIC)
952                                 # if static LLVM libraries were requested, use llvm-config to generate
953                                 # the list of what libraries we need, and substitute that in the right
954                                 # way for LLVM_LIBRARY.
955                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
956                                                 OUTPUT_VARIABLE LLVM_LIBRARY
957                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
958                                 string(REPLACE " " ";" LLVM_LIBRARY "${LLVM_LIBRARY}")
959                         endif()
960                 else()
961                         message(FATAL_ERROR "LLVM not found.")
962                 endif()
963
964                 # Fix for conflict with Mesa llvmpipe
965                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--version-script=${CMAKE_SOURCE_DIR}/source/creator/blender.map")
966         endif()
967
968         if(WITH_CYCLES_OSL)
969                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
970         
971                 message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
972         
973                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
974                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
975                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
976                 # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
977                 # otherwise LLVM is missing the osl_allocate_closure_component function
978                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -Wl,--whole-archive ${OSL_LIB_EXEC} -Wl,--no-whole-archive ${OSL_LIB_QUERY})
979                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
980                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
981         
982                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
983                         set(OSL_FOUND TRUE)
984                         message(STATUS "OSL includes = ${OSL_INCLUDES}")
985                         message(STATUS "OSL library = ${OSL_LIBRARIES}")
986                         message(STATUS "OSL compiler = ${OSL_COMPILER}")
987                 else()
988                         message(STATUS "OSL not found")
989                 endif()
990         endif()
991
992         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
993         list(APPEND PLATFORM_LINKLIBS -lutil -lc -lm -lpthread)
994
995         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
996                 if(NOT WITH_PYTHON_MODULE)
997                         # binreloc is linux only
998                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
999                         set(WITH_BINRELOC ON)
1000                 endif()
1001         endif()
1002
1003         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -pthread")
1004         if(CMAKE_DL_LIBS)
1005                 list(APPEND PLATFORM_LINKLIBS ${CMAKE_DL_LIBS})
1006         endif()
1007
1008         # lfs on glibc, all compilers should use
1009         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1010
1011         # GNU Compiler
1012         if(CMAKE_COMPILER_IS_GNUCC)
1013                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
1014         # CLang is the same as GCC for now.
1015         elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
1016                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
1017         # Solaris CC
1018         elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro")
1019                 set(PLATFORM_CFLAGS "-pipe -features=extensions -fPIC -D__FUNCTION__=__func__")
1020                 
1021         # Intel C++ Compiler
1022         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1023                 # think these next two are broken
1024                 find_program(XIAR xiar)
1025                 if(XIAR)
1026                         set(CMAKE_AR "${XIAR}")
1027                 endif()
1028                 mark_as_advanced(XIAR)
1029
1030                 find_program(XILD xild)
1031                 if(XILD)
1032                         set(CMAKE_LINKER "${XILD}")
1033                 endif()
1034                 mark_as_advanced(XILD)
1035
1036                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
1037                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
1038
1039                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
1040                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
1041                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
1042         endif()
1043
1044 elseif(WIN32)
1045
1046         add_definitions(-DWIN32)
1047
1048         if(MSVC)
1049
1050                 # needed for some MSVC installations
1051                 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
1052                 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
1053                 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
1054
1055                 list(APPEND PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid psapi)
1056
1057                 add_definitions(
1058                         -D_CRT_NONSTDC_NO_DEPRECATE
1059                         -D_CRT_SECURE_NO_DEPRECATE
1060                         -D_SCL_SECURE_NO_DEPRECATE
1061                         -D_CONSOLE
1062                         -D_LIB
1063                 )
1064
1065                 # MSVC11 needs _ALLOW_KEYWORD_MACROS to build
1066                 if(NOT MSVC_VERSION VERSION_LESS 1700)
1067                         add_definitions(-D_ALLOW_KEYWORD_MACROS)
1068                 endif()
1069
1070                 if(CMAKE_CL_64)
1071                         # We want to support Vista level ABI for x64
1072                         if(NOT MSVC_VERSION VERSION_LESS 1700)
1073                                 add_definitions(-D_WIN32_WINNT=0x600)
1074                         endif()
1075                 endif()
1076
1077                 add_definitions(-DOIIO_STATIC_BUILD)
1078
1079                 set(CMAKE_CXX_FLAGS "/nologo /J /Gd /EHsc /MP" CACHE STRING "MSVC MT C++ flags " FORCE)
1080                 set(CMAKE_C_FLAGS   "/nologo /J /Gd /MP"       CACHE STRING "MSVC MT C++ flags " FORCE)
1081
1082                 if(CMAKE_CL_64)
1083                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1084                 else()
1085                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
1086                 endif()
1087                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1088                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1089                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1090                 if(CMAKE_CL_64)
1091                         set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1092                 else()
1093                         set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
1094                 endif()
1095                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1096                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1097                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1098
1099                 # most msvc warnings are C & C++
1100                 set(_WARNINGS
1101                         # warning level:
1102                         "/W3"
1103                         "/w34062"  # switch statement contains 'default' but no 'case' labels
1104                         # disable:
1105                         "/wd4018"  # signed/unsigned mismatch
1106                         "/wd4065"  # switch statement contains 'default' but no 'case' labels
1107                         "/wd4127"  # conditional expression is constant
1108                         "/wd4181"  # qualifier applied to reference type; ignored
1109                         "/wd4200"  # zero-sized array in struct/union
1110                         "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
1111                         "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
1112                         "/wd4305"  # truncation from 'type1' to 'type2'
1113                         "/wd4800"  # forcing value to bool 'true' or 'false'
1114                         # errors:
1115                         "/we4013"  # 'function' undefined; assuming extern returning int
1116                         "/we4431"  # missing type specifier - int assumed
1117                 )
1118
1119                 string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
1120                 set(C_WARNINGS "${_WARNINGS}")
1121                 set(CXX_WARNINGS "${_WARNINGS}")
1122                 unset(_WARNINGS)
1123
1124                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
1125
1126                 # MSVC only, Mingw doesnt need
1127                 if(CMAKE_CL_64)
1128                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
1129                 else()
1130                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
1131                 endif()
1132
1133                 set(PLATFORM_LINKFLAGS_DEBUG "/IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
1134
1135                 if(NOT DEFINED LIBDIR)
1136                         # Setup 64bit and 64bit windows systems
1137                         if(CMAKE_CL_64)
1138                                 message(STATUS "64 bit compiler detected.")
1139                                 set(LIBDIR_BASE ${CMAKE_SOURCE_DIR}/../lib/win64)
1140                         else()
1141                                 message(STATUS "32 bit compiler detected.")
1142                                 set(LIBDIR_BASE ${CMAKE_SOURCE_DIR}/../lib/windows)
1143                         endif()
1144                         if(MSVC12)
1145                                 message(STATUS "Visual C++ 2013 detected.")
1146                                 set(LIBDIR ${LIBDIR_BASE}_vc12)
1147                         else()
1148                                 set(LIBDIR ${LIBDIR_BASE})
1149                         endif()
1150                 else()
1151                         message(STATUS using LIBDIR  ${LIBDIR})
1152                 endif()
1153
1154                 # Add each of our libraries to our cmake_prefix_path so find_package() could work
1155                 FILE(GLOB children RELATIVE ${LIBDIR} ${LIBDIR}/*)
1156                 FOREACH(child ${children})
1157                 IF(IS_DIRECTORY ${LIBDIR}/${child})
1158                         LIST(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
1159                 ENDIF()
1160                 ENDFOREACH()
1161
1162                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
1163                 set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz_st.lib)
1164                 set(ZLIB_INCLUDE_DIR ${LIBDIR}/zlib/include)
1165                 set(ZLIB_LIBRARY ${LIBDIR}/zlib/lib/libz_st.lib)
1166                 set(ZLIB_DIR ${LIBDIR}/zlib)
1167                 #find_package(zlib) # we want to find before finding things that depend on it like png
1168
1169
1170                 find_package(png)
1171                 if(NOT PNG_FOUND)
1172                         set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
1173                         message(WARNING "Using HARDCODED libpng locations")
1174                         set(PNG_LIBRARIES libpng)
1175                         set(PNG "${LIBDIR}/png")
1176                         set(PNG_INCLUDE_DIRS "${PNG}/include")
1177                         set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1178                 endif()
1179
1180                 if(MSVC)
1181                         set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
1182                 endif()
1183                 find_package(jpeg REQUIRED)
1184
1185                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
1186                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
1187
1188                 set(FREETYPE ${LIBDIR}/freetype)
1189                 set(FREETYPE_INCLUDE_DIRS
1190                         ${LIBDIR}/freetype/include
1191                         ${LIBDIR}/freetype/include/freetype2
1192                 )
1193                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
1194                 find_package(freetype REQUIRED)
1195
1196                 if(WITH_FFTW3)
1197                         set(FFTW3 ${LIBDIR}/fftw3)
1198                         set(FFTW3_LIBRARIES libfftw)
1199                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1200                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1201                 endif()
1202
1203                 if(WITH_OPENCOLLADA)
1204                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1205
1206                         set(OPENCOLLADA_INCLUDE_DIRS
1207                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1208                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1209                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1210                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1211                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1212                         )
1213
1214                         set(OPENCOLLADA_LIBRARIES
1215                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
1216                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
1217                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
1218                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
1219                                 ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
1220                                 ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
1221                                 ${OPENCOLLADA}/lib/opencollada/xml.lib
1222                                 ${OPENCOLLADA}/lib/opencollada/buffer.lib
1223                                 ${OPENCOLLADA}/lib/opencollada/ftoa.lib
1224                         )
1225
1226                         if(NOT WITH_LLVM)
1227                                 list(APPEND OPENCOLLADA_LIBRARIES ${OPENCOLLADA}/lib/opencollada/UTF.lib)
1228                         endif()
1229
1230                         set(PCRE_LIBRARIES
1231                                 ${OPENCOLLADA}/lib/opencollada/pcre.lib
1232                         )
1233                 endif()
1234
1235                 if(WITH_CODEC_FFMPEG)
1236                         set(FFMPEG_INCLUDE_DIRS
1237                                 ${LIBDIR}/ffmpeg/include
1238                                 ${LIBDIR}/ffmpeg/include/msvc
1239                         )
1240                         find_package(FFMPEG)
1241                         if(NOT FFMPEG_FOUND)
1242                                 message(WARNING "Using HARDCODED ffmpeg locations")
1243                                 set(FFMPEG_LIBRARY_VERSION 55)
1244                                 set(FFMPEG_LIBRARY_VERSION_AVU 52)
1245                                 set(FFMPEG_LIBRARIES
1246                                         ${LIBDIR}/ffmpeg/lib/avcodec-${FFMPEG_LIBRARY_VERSION}.lib
1247                                         ${LIBDIR}/ffmpeg/lib/avformat-${FFMPEG_LIBRARY_VERSION}.lib
1248                                         ${LIBDIR}/ffmpeg/lib/avdevice-${FFMPEG_LIBRARY_VERSION}.lib
1249                                         ${LIBDIR}/ffmpeg/lib/avutil-${FFMPEG_LIBRARY_VERSION_AVU}.lib
1250                                         ${LIBDIR}/ffmpeg/lib/swscale-2.lib
1251                                         )
1252                         endif()
1253                 endif()
1254
1255                 if(WITH_IMAGE_OPENEXR)
1256                         set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
1257                         set(OPENEXR_VERSION "2.1")
1258                         find_package(OPENEXR REQUIRED)
1259                         if(NOT OPENEXR_FOUND)
1260                         message(WARNING "Using HARDCODED OpenEXR locations")
1261                         set(OPENEXR ${LIBDIR}/openexr)
1262                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1263                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1264                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1265                         if(MSVC12)
1266                                 set(OPENEXR_LIBRARIES
1267                                         ${OPENEXR_LIBPATH}/Iex-2_1.lib
1268                                         ${OPENEXR_LIBPATH}/Half.lib
1269                                         ${OPENEXR_LIBPATH}/IlmImf-2_1.lib
1270                                         ${OPENEXR_LIBPATH}/Imath-2_1.lib
1271                                         ${OPENEXR_LIBPATH}/IlmThread-2_1.lib
1272                                 )
1273                         else()
1274                                 set(OPENEXR_LIBRARIES
1275                                         ${OPENEXR_LIBPATH}/Iex.lib
1276                                         ${OPENEXR_LIBPATH}/Half.lib
1277                                         ${OPENEXR_LIBPATH}/IlmImf.lib
1278                                         ${OPENEXR_LIBPATH}/Imath.lib
1279                                         ${OPENEXR_LIBPATH}/IlmThread.lib
1280                                 )
1281                         endif()
1282                         endif(NOT OPENEXR_FOUND)
1283                 endif()
1284
1285                 if(WITH_IMAGE_TIFF)
1286                 # Try to find tiff first then complain and set static and maybe wrong paths
1287                 find_package(TIFF)
1288                 if(NOT TIFF_FOUND)
1289                         message(WARNING "Using HARDCODED libtiff locations")
1290                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
1291                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
1292                 endif()
1293                 endif()
1294
1295                 if(WITH_JACK)
1296                         set(JACK_INCLUDE_DIRS
1297                                 ${LIBDIR}/jack/include/jack
1298                                 ${LIBDIR}/jack/include
1299                         )
1300                         set(JACK_LIBRARIES optimized ${LIBDIR}/jack/lib/libjack.lib debug ${LIBDIR}/jack/lib/libjack_d.lib)
1301                 endif()
1302
1303                 if(WITH_PYTHON)
1304                         set(PYTHON_VERSION 3.4) # CACHE STRING)
1305
1306                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1307                         # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
1308                         set(PYTHON_LIBRARY ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.lib)
1309                         unset(_PYTHON_VERSION_NO_DOTS)
1310
1311                         # Shared includes for both vc2008 and vc2010
1312                         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
1313
1314                         # uncached vars
1315                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1316                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1317                 endif()
1318
1319                 if(WITH_BOOST)
1320                         if(WITH_CYCLES_OSL)
1321                                 set(boost_extra_libs wave)
1322                         endif(WITH_CYCLES_OSL)
1323                         if(WITH_INTERNATIONAL)
1324                                 list(APPEND boost_extra_libs locale)
1325                         endif(WITH_INTERNATIONAL)
1326                         set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
1327                         set(Boost_USE_MULTITHREADED ON) # suffix -mt
1328                         set(Boost_USE_STATIC_LIBS ON) # suffix -s
1329                         find_package(Boost COMPONENTS date_time filesystem thread regex system ${boost_extra_libs})
1330                         IF(NOT Boost_FOUND)
1331                                 message(WARNING "USING HARDCODED boost locations")
1332                                 set(BOOST ${LIBDIR}/boost)
1333                                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1334                                 if(MSVC12)
1335                                         set(BOOST_LIBPATH ${BOOST}/lib)
1336                                         set(BOOST_POSTFIX "vc120-mt-s-1_55.lib")
1337                                         set(BOOST_DEBUG_POSTFIX "vc120-mt-sgd-1_55.lib")
1338                                 else()
1339                                         set(BOOST_LIBPATH ${BOOST}/lib)
1340                                         set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
1341                                         set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_49.lib")
1342                                 endif()
1343                                 set(BOOST_LIBRARIES
1344                                         optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
1345                                         optimized libboost_regex-${BOOST_POSTFIX}
1346                                         optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
1347                                         debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
1348                                         debug libboost_regex-${BOOST_DEBUG_POSTFIX}
1349                                         debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
1350                                 if(WITH_CYCLES_OSL)
1351                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1352                                                 optimized libboost_wave-${BOOST_POSTFIX}
1353                                                 debug libboost_wave-${BOOST_DEBUG_POSTFIX})
1354                                 endif()
1355                                 if(WITH_INTERNATIONAL)
1356                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1357                                                 optimized libboost_locale-${BOOST_POSTFIX}
1358                                                 debug libboost_locale-${BOOST_DEBUG_POSTFIX})
1359                                 endif()
1360                         else() # we found boost using find_package
1361                                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
1362                                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
1363                                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
1364                         endif()
1365                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
1366                 endif()
1367                         
1368                 if(WITH_OPENIMAGEIO)
1369                         find_package(OpenImageIO)
1370                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1371                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1372                         set(OIIO_OPTIMIZED optimized OpenImageIO optimized OpenImageIO_Util)
1373                         set(OIIO_DEBUG debug OpenImageIO_d debug OpenImageIO_Util_d)
1374                         set(OPENIMAGEIO_LIBRARIES ${OIIO_OPTIMIZED} ${OIIO_DEBUG})
1375                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1376                         set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
1377                 endif()
1378
1379                 if(WITH_LLVM)
1380                         set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1381                         file(GLOB LLVM_LIBRARY_OPTIMIZED ${LLVM_DIRECTORY}/lib/*.lib)
1382
1383                         if(EXISTS ${LLVM_DIRECTORY}/debug/lib)
1384                                 foreach(LLVM_OPTIMIZED_LIB ${LLVM_LIBRARY_OPTIMIZED})
1385                                         get_filename_component(LIBNAME ${LLVM_OPTIMIZED_LIB} ABSOLUTE)
1386                                         list(APPEND LLVM_LIBS optimized ${LIBNAME})
1387                                 endforeach(LLVM_OPTIMIZED_LIB)
1388                         
1389                                 file(GLOB LLVM_LIBRARY_DEBUG ${LLVM_DIRECTORY}/debug/lib/*.lib)
1390
1391                                 foreach(LLVM_DEBUG_LIB ${LLVM_LIBRARY_DEBUG})
1392                                         get_filename_component(LIBNAME ${LLVM_DEBUG_LIB} ABSOLUTE)
1393                                         list(APPEND LLVM_LIBS debug ${LIBNAME})
1394                                 endforeach(LLVM_DEBUG_LIB)
1395
1396                                 set(LLVM_LIBRARY ${LLVM_LIBS})
1397                         else()
1398                                 message(WARNING "LLVM debug libs not present on this system. Using release libs for debug builds.")
1399                                 set(LLVM_LIBRARY ${LLVM_LIBRARY_OPTIMIZED})
1400                         endif()
1401                         
1402                 endif()
1403         
1404                 if(WITH_OPENCOLORIO)
1405                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1406                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1407                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1408                         set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
1409                         set(OPENCOLORIO_DEFINITIONS)
1410                 endif()
1411                 
1412
1413                 if(WITH_MOD_CLOTH_ELTOPO)
1414                         set(LAPACK ${LIBDIR}/lapack)
1415                         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
1416                         set(LAPACK_LIBPATH ${LAPACK}/lib)
1417                         set(LAPACK_LIBRARIES
1418                                 ${LIBDIR}/lapack/lib/libf2c.lib
1419                                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
1420                                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
1421                         )
1422                 endif()
1423
1424                 # used in many places so include globally, like OpenGL
1425                 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
1426
1427         elseif(CMAKE_COMPILER_IS_GNUCC)
1428                 # keep GCC specific stuff here
1429                 include(CheckCSourceCompiles)
1430                 # Setup 64bit and 64bit windows systems
1431                 CHECK_C_SOURCE_COMPILES("
1432                         #ifndef __MINGW64__
1433                         #error
1434                         #endif
1435                         int main(void) { return 0; }
1436                         " 
1437                         WITH_MINGW64)
1438                 
1439                 if(WITH_MINGW64)
1440                         message(STATUS "Compiling for 64 bit with MinGW-w64.")
1441                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
1442                 else()
1443                         message(STATUS "Compiling for 32 bit with MinGW-w32.")
1444                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
1445                         
1446                         if(WITH_RAYOPTIMIZATION)
1447                                 message(WARNING "MinGW-w32 is known to be unstable with 'WITH_RAYOPTIMIZATION' option enabled.")
1448                         endif()
1449                 endif()
1450                 
1451                 list(APPEND PLATFORM_LINKLIBS -lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi)
1452                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
1453
1454                 if(WITH_MINGW64)
1455                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
1456                         list(APPEND PLATFORM_LINKLIBS -lpthread)
1457                         
1458                         add_definitions(-DFREE_WINDOWS64 -DMS_WIN64)
1459                 endif()
1460
1461                 add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1462
1463                 add_definitions(-DFREE_WINDOWS)
1464
1465                 set(PNG "${LIBDIR}/png")
1466                 set(PNG_INCLUDE_DIRS "${PNG}/include")
1467                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1468
1469                 if(WITH_MINGW64)
1470                         set(JPEG_LIBRARIES jpeg)
1471                 else()
1472                         set(JPEG_LIBRARIES libjpeg)
1473                 endif()
1474                 set(PNG_LIBRARIES png)
1475
1476                 set(ZLIB ${LIBDIR}/zlib)
1477                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
1478                 set(ZLIB_LIBPATH ${ZLIB}/lib)
1479                 set(ZLIB_LIBRARIES z)
1480
1481                 set(JPEG "${LIBDIR}/jpeg")
1482                 set(JPEG_INCLUDE_DIR "${JPEG}/include")
1483                 set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
1484                 
1485                 # comes with own pthread library
1486                 if(NOT WITH_MINGW64)
1487                         set(PTHREADS ${LIBDIR}/pthreads)
1488                         #set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
1489                         set(PTHREADS_LIBPATH ${PTHREADS}/lib)
1490                         set(PTHREADS_LIBRARIES pthreadGC2)
1491                 endif()
1492                 
1493                 set(FREETYPE ${LIBDIR}/freetype)
1494                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1495                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1496                 set(FREETYPE_LIBRARY freetype)
1497
1498                 if(WITH_FFTW3)
1499                         set(FFTW3 ${LIBDIR}/fftw3)
1500                         set(FFTW3_LIBRARIES fftw3)
1501                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1502                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1503                 endif()
1504
1505                 if(WITH_OPENCOLLADA)
1506                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1507                         set(OPENCOLLADA_INCLUDE_DIRS
1508                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1509                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1510                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1511                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1512                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1513                         )
1514                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib/opencollada)
1515                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver buffer ftoa xml)
1516                         set(PCRE_LIBRARIES pcre)
1517                 endif()
1518
1519                 if(WITH_CODEC_FFMPEG)
1520                         set(FFMPEG ${LIBDIR}/ffmpeg)
1521                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1522                         if(WITH_MINGW64)
1523                                 set(FFMPEG_LIBRARIES avcodec.dll avformat.dll avdevice.dll avutil.dll swscale.dll swresample.dll)
1524                         else()
1525                                 set(FFMPEG_LIBRARIES avcodec-55 avformat-55 avdevice-55 avutil-52 swscale-2)
1526                         endif()
1527                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1528                 endif()
1529
1530                 if(WITH_IMAGE_OPENEXR)
1531                         set(OPENEXR ${LIBDIR}/openexr)
1532                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1533                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1534                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
1535                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1536                 endif()
1537
1538                 if(WITH_IMAGE_TIFF)
1539                         set(TIFF ${LIBDIR}/tiff)
1540                         set(TIFF_LIBRARY tiff)
1541                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
1542                         set(TIFF_LIBPATH ${TIFF}/lib)
1543                 endif()
1544
1545                 if(WITH_JACK)
1546                         set(JACK ${LIBDIR}/jack)
1547                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
1548                         set(JACK_LIBRARIES jack)
1549                         set(JACK_LIBPATH ${JACK}/lib)
1550
1551                         # TODO, gives linking errors, force off
1552                         set(WITH_JACK OFF)
1553                 endif()
1554
1555                 if(WITH_PYTHON)
1556                         # normally cached but not since we include them with blender
1557                         set(PYTHON_VERSION 3.4) #  CACHE STRING)
1558                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1559                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
1560                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}mw.lib")  # CACHE FILEPATH)
1561                         unset(_PYTHON_VERSION_NO_DOTS)
1562
1563                         # uncached vars
1564                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1565                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1566                 endif()
1567
1568                 if(WITH_BOOST)
1569                         set(BOOST ${LIBDIR}/boost)
1570                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1571                         if(WITH_MINGW64)
1572                                 set(BOOST_POSTFIX "mgw47-mt-s-1_49")
1573                                 set(BOOST_DEBUG_POSTFIX "mgw47-mt-sd-1_49")
1574                         else()
1575                                 set(BOOST_POSTFIX "mgw46-mt-s-1_49")
1576                                 set(BOOST_DEBUG_POSTFIX "mgw46-mt-sd-1_49")
1577                         endif()
1578                         set(BOOST_LIBRARIES
1579                                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
1580                                 boost_regex-${BOOST_POSTFIX}
1581                                 boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
1582                                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
1583                                 boost_regex-${BOOST_DEBUG_POSTFIX}
1584                                 boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
1585                         if(WITH_INTERNATIONAL)
1586                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1587                                         optimized boost_locale-${BOOST_POSTFIX}
1588                                         debug boost_locale-${BOOST_DEBUG_POSTFIX}) 
1589                         endif()
1590                         if(WITH_CYCLES_OSL)
1591                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1592                                         optimized boost_wave-${BOOST_POSTFIX}
1593                                         debug boost_wave-${BOOST_DEBUG_POSTFIX}) 
1594                         endif()
1595                         set(BOOST_LIBPATH ${BOOST}/lib)
1596                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
1597                 endif()
1598                         
1599                 if(WITH_OPENIMAGEIO)
1600                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1601                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1602                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1603                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1604                         set(OPENIMAGEIO_DEFINITIONS "")
1605                 endif()
1606                 
1607                 if(WITH_LLVM)
1608                         set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1609                         set(LLVM_LIBPATH ${LLVM_DIRECTORY}/lib)
1610                         # Explicitly set llvm lib order.
1611                         #---- WARNING ON GCC ORDER OF LIBS IS IMPORTANT, DO NOT CHANGE! ---------
1612                         set(LLVM_LIBRARY LLVMSelectionDAG LLVMCodeGen LLVMScalarOpts LLVMAnalysis LLVMArchive
1613                                 LLVMAsmParser LLVMAsmPrinter
1614                                 LLVMBitReader LLVMBitWriter
1615                                 LLVMDebugInfo LLVMExecutionEngine
1616                                 LLVMInstCombine LLVMInstrumentation
1617                                 LLVMInterpreter LLVMJIT
1618                                 LLVMLinker LLVMMC
1619                                 LLVMMCDisassembler LLVMMCJIT
1620                                 LLVMMCParser LLVMObject
1621                                 LLVMRuntimeDyld 
1622                                 LLVMSupport
1623                                 LLVMTableGen LLVMTarget
1624                                 LLVMTransformUtils LLVMVectorize
1625                                 LLVMX86AsmParser LLVMX86AsmPrinter
1626                                 LLVMX86CodeGen LLVMX86Desc
1627                                 LLVMX86Disassembler LLVMX86Info
1628                                 LLVMX86Utils LLVMipa
1629                                 LLVMipo LLVMCore)
1630                         # imagehelp is needed by LLVM 3.1 on MinGW, check lib\Support\Windows\Signals.inc
1631                         list(APPEND PLATFORM_LINKLIBS -limagehlp)
1632                 endif()
1633                 
1634                 if(WITH_OPENCOLORIO)
1635                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1636                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1637                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1638                         set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1639                         set(OPENCOLORIO_DEFINITIONS)
1640                 endif()
1641
1642                 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
1643
1644                 ## DISABLE - causes linking errors 
1645                 ## for re-distribution, so users dont need mingw installed
1646                 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")
1647
1648         endif()
1649         
1650         # Things common to both mingw and MSVC  should go here
1651
1652         set(WINTAB_INC ${LIBDIR}/wintab/include)
1653
1654         if(WITH_OPENAL)
1655                 set(OPENAL ${LIBDIR}/openal)
1656                 set(OPENALDIR ${LIBDIR}/openal)
1657                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
1658                 if(MSVC12)
1659                         set(OPENAL_LIBRARY openal32)
1660                 else()
1661                         set(OPENAL_LIBRARY wrap_oal)
1662                 endif()
1663                 set(OPENAL_LIBPATH ${OPENAL}/lib)
1664         endif()
1665
1666         if(WITH_CODEC_SNDFILE)
1667                 set(SNDFILE ${LIBDIR}/sndfile)
1668                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1669                 set(SNDFILE_LIBRARIES libsndfile-1)
1670                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
1671         endif()
1672
1673         if(WITH_SDL)
1674                 set(SDL ${LIBDIR}/sdl)
1675                 set(SDL_INCLUDE_DIR ${SDL}/include)
1676                 set(SDL_LIBRARY SDL)
1677                 set(SDL_LIBPATH ${SDL}/lib)
1678         endif()
1679
1680         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
1681                 add_definitions(-D__SSE__ -D__MMX__)
1682         endif()
1683
1684         if(WITH_CYCLES_OSL)
1685                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1686         
1687                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1688                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1689                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1690                 find_library(OSL_LIB_EXEC_DEBUG NAMES oslexec_d PATHS ${CYCLES_OSL}/lib)
1691                 find_library(OSL_LIB_COMP_DEBUG NAMES oslcomp_d PATHS ${CYCLES_OSL}/lib)
1692                 find_library(OSL_LIB_QUERY_DEBUG NAMES oslquery_d PATHS ${CYCLES_OSL}/lib)
1693                 list(APPEND OSL_LIBRARIES optimized ${OSL_LIB_COMP} optimized ${OSL_LIB_EXEC} optimized ${OSL_LIB_QUERY} debug ${OSL_LIB_EXEC_DEBUG} debug ${OSL_LIB_COMP_DEBUG} debug ${OSL_LIB_QUERY_DEBUG})
1694                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1695                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1696         
1697                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1698                         set(OSL_FOUND TRUE)
1699                 else()
1700                         message(STATUS "OSL not found")
1701                 endif()
1702         endif()
1703
1704 elseif(APPLE)
1705
1706         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
1707                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/7/8/9
1708         endif()
1709
1710         if(WITH_LIBS10.5)
1711                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1712         else()
1713                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1714                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1715                 else()
1716                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1717                 endif()
1718         endif()
1719
1720
1721         if(WITH_OPENAL)
1722                 find_package(OpenAL)
1723                 if(OPENAL_FOUND)
1724                         set(WITH_OPENAL ON)
1725                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1726                 else()
1727                         set(WITH_OPENAL OFF)
1728                 endif()
1729         endif()
1730
1731         if(WITH_JACK)
1732                 find_library(JACK_FRAMEWORK
1733                         NAMES jackmp
1734                 )
1735                 set(JACK_INCLUDE_DIRS ${JACK_FRAMEWORK}/headers)
1736                 if(NOT JACK_FRAMEWORK)
1737                         set(WITH_JACK OFF)
1738                 endif()
1739         endif()
1740
1741         if(WITH_CODEC_SNDFILE)
1742                 set(SNDFILE ${LIBDIR}/sndfile)
1743                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1744                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1745                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1746         endif()
1747
1748         if(WITH_PYTHON)
1749                 # we use precompiled libraries for py 3.4 and up by default
1750                 set(PYTHON_VERSION 3.4)
1751                 if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
1752                         # normally cached but not since we include them with blender
1753                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
1754                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1755                         set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
1756                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1757                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1758                 else()
1759                         # module must be compiled against Python framework
1760                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1761                         set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1762                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1763                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
1764                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1765                 endif()
1766                 
1767                 # uncached vars
1768                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1769                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1770         endif()
1771
1772         if(WITH_FFTW3)
1773                 set(FFTW3 ${LIBDIR}/fftw3)
1774                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1775                 set(FFTW3_LIBRARIES fftw3)
1776                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1777         endif()
1778
1779         set(PNG_LIBRARIES png)
1780         set(JPEG_LIBRARIES jpeg)
1781
1782         set(ZLIB /usr)
1783         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1784         set(ZLIB_LIBRARIES z bz2)
1785
1786         set(FREETYPE ${LIBDIR}/freetype)
1787         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1788         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1789         set(FREETYPE_LIBRARY freetype)
1790
1791         if(WITH_IMAGE_OPENEXR)
1792                 set(OPENEXR ${LIBDIR}/openexr)
1793                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1794                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1795                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1796                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1797         endif()
1798
1799         if(WITH_CODEC_FFMPEG)
1800                 set(FFMPEG ${LIBDIR}/ffmpeg)
1801                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1802                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1803                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1804                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
1805         endif()
1806
1807         find_library(SYSTEMSTUBS_LIBRARY
1808                 NAMES
1809                 SystemStubs
1810                 PATHS
1811         )
1812         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1813         if(SYSTEMSTUBS_LIBRARY)
1814                 list(APPEND PLATFORM_LINKLIBS stdc++ SystemStubs)
1815         else()
1816                 list(APPEND PLATFORM_LINKLIBS stdc++)
1817         endif()
1818
1819         set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1820         set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1821         if(WITH_CODEC_QUICKTIME)
1822                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1823                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1824                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1825                         # libSDL still needs 32bit carbon quicktime
1826                 endif()
1827         endif()
1828
1829         # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1830         # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1831         if(WITH_INPUT_NDOF)
1832                 # This thread it *should* work and check the framework - campbell
1833                 # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1834                 find_library(3DCONNEXION_CLIENT_FRAMEWORK
1835                         NAMES 3DconnexionClient
1836                 )
1837                 if(NOT 3DCONNEXION_CLIENT_FRAMEWORK)
1838                         set(WITH_INPUT_NDOF OFF)
1839                 endif()
1840
1841                 if(WITH_INPUT_NDOF)
1842                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework 3DconnexionClient")
1843                         set(NDOF_INCLUDE_DIRS /Library/Frameworks/3DconnexionClient.framework/Headers )
1844                 endif()
1845         endif()
1846
1847         if(WITH_JACK)
1848                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework jackmp")
1849         endif()
1850         
1851         if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK)
1852                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")# force cmake to link right framework
1853         endif()
1854         
1855         if(WITH_OPENCOLLADA)
1856                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1857
1858                 set(OPENCOLLADA_INCLUDE_DIRS
1859                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1860                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1861                         ${LIBDIR}/opencollada/include/COLLADAFramework
1862                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1863                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1864                 )
1865
1866                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1867                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lxml2 -lbuffer -lftoa")
1868                 # Use UTF functions from collada if LLVM is not enabled
1869                 if(NOT WITH_LLVM)
1870                         set(OPENCOLLADA_LIBRARIES "${OPENCOLLADA_LIBRARIES} -lUTF")
1871                 endif()
1872                 # pcre is bundled with openCollada
1873                 #set(PCRE ${LIBDIR}/pcre)
1874                 #set(PCRE_LIBPATH ${PCRE}/lib)
1875                 set(PCRE_LIBRARIES pcre)
1876                 #libxml2 is used
1877                 #set(EXPAT ${LIBDIR}/expat)
1878                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1879                 set(EXPAT_LIB)
1880         endif()
1881
1882         if(WITH_SDL)
1883                 set(SDL ${LIBDIR}/sdl)
1884                 set(SDL_INCLUDE_DIR ${SDL}/include)
1885                 set(SDL_LIBRARY SDL)
1886                 set(SDL_LIBPATH ${SDL}/lib)
1887         endif()
1888
1889         set(PNG "${LIBDIR}/png")
1890         set(PNG_INCLUDE_DIRS "${PNG}/include")
1891         set(PNG_LIBPATH ${PNG}/lib)
1892
1893         set(JPEG "${LIBDIR}/jpeg")
1894         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1895         set(JPEG_LIBPATH ${JPEG}/lib)
1896
1897         if(WITH_IMAGE_TIFF)
1898                 set(TIFF ${LIBDIR}/tiff)
1899                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1900                 set(TIFF_LIBRARY tiff)
1901                 set(TIFF_LIBPATH ${TIFF}/lib)
1902         endif()
1903
1904         if(WITH_INPUT_NDOF)
1905                 # linker needs "-weak_framework 3DconnexionClient"
1906         endif()
1907
1908         if(WITH_BOOST)
1909                 set(BOOST ${LIBDIR}/boost)
1910                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1911                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt boost_wave-mt)
1912                 if(WITH_INTERNATIONAL)
1913                         list(APPEND BOOST_LIBRARIES boost_locale-mt)
1914                 endif()
1915                 if(WITH_CYCLES_NETWORK)
1916                         list(APPEND BOOST_LIBRARIES boost_serialization-mt)
1917                 endif()
1918                 set(BOOST_LIBPATH ${BOOST}/lib)
1919                 set(BOOST_DEFINITIONS)
1920         endif()
1921         
1922         if(WITH_INTERNATIONAL OR WITH_CODEC_FFMPEG)
1923                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -liconv") # boost_locale and ffmpeg needs it !
1924         endif()
1925
1926         if(WITH_OPENIMAGEIO)
1927                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
1928                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1929                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO}/lib/libOpenImageIO.a ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1930                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
1931                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
1932         endif()
1933
1934         if(WITH_OPENCOLORIO)
1935                 set(OPENCOLORIO ${LIBDIR}/opencolorio)
1936                 set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1937                 set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
1938                 set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1939                 set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
1940         endif()
1941
1942         if(WITH_LLVM)
1943                 set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1944                 set(LLVM_VERSION "3.4" CACHE STRING     "Version of LLVM to use")
1945                 if(EXISTS "${LLVM_DIRECTORY}/bin/llvm-config")
1946                         set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
1947                 else()
1948                         set(LLVM_CONFIG llvm-config)
1949                 endif()
1950                 execute_process(COMMAND ${LLVM_CONFIG} --version
1951                                 OUTPUT_VARIABLE LLVM_VERSION
1952                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1953                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
1954                                 OUTPUT_VARIABLE LLVM_DIRECTORY
1955                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1956                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
1957                                 OUTPUT_VARIABLE LLVM_LIBPATH
1958                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1959                 find_library(LLVM_LIBRARY
1960                              NAMES LLVMAnalysis # first of a whole bunch of libs to get
1961                              PATHS ${LLVM_LIBPATH})
1962
1963                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIBPATH)
1964                         if(LLVM_STATIC)
1965                                 # if static LLVM libraries were requested, use llvm-config to generate
1966                                 # the list of what libraries we need, and substitute that in the right
1967                                 # way for LLVM_LIBRARY.
1968                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
1969                                                 OUTPUT_VARIABLE LLVM_LIBRARY
1970                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1971                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
1972                         else()
1973                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -lLLVM-3.4")
1974                         endif()
1975                 else()
1976                         message(FATAL_ERROR "LLVM not found.")
1977                 endif()
1978         endif()
1979
1980         if(WITH_CYCLES_OSL)
1981                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1982         
1983                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1984                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1985                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1986                 # WARNING! depends on correct order of OSL libs linking
1987                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -force_load ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
1988                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1989                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1990         
1991                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1992                         set(OSL_FOUND TRUE)
1993                 else()
1994                         message(STATUS "OSL not found")
1995                 endif()
1996         endif()
1997         
1998         if(WITH_OPENMP)
1999                 execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE COMPILER_VENDOR)
2000                 string(SUBSTRING "${COMPILER_VENDOR}" 0 5 VENDOR_NAME) # truncate output
2001                 if(${VENDOR_NAME} MATCHES "Apple") # Apple does not support OpenMP reliable with gcc and not with clang
2002                         set(WITH_OPENMP OFF)
2003                 else() # vanilla gcc or clang_omp support OpenMP
2004                         message(STATUS "Using special OpenMP enabled compiler !") # letting find_package(OpenMP) module work for gcc
2005                         if(CMAKE_C_COMPILER_ID MATCHES "Clang") # clang-omp in darwin libs
2006                                 set(OPENMP_FOUND ON)
2007                                 set(OpenMP_C_FLAGS "-fopenmp" CACHE STRING "C compiler flags for OpenMP parallization" FORCE)
2008                                 set(OpenMP_CXX_FLAGS "-fopenmp" CACHE STRING "C++ compiler flags for OpenMP parallization" FORCE)
2009                                 include_directories(${LIBDIR}/openmp/include)
2010                                 link_directories(${LIBDIR}/openmp/lib)
2011                                 # This is a workaround for our helperbinaries ( datatoc, masgfmt, ... ),
2012                                 # They are linked also to omp lib, so we need it in builddir for runtime exexcution, TODO: remove all unneeded dependencies from these
2013                                 execute_process(COMMAND ditto -arch ${CMAKE_OSX_ARCHITECTURES} ${LIBDIR}/openmp/lib/libiomp5.dylib ${CMAKE_BINARY_DIR}/bin/libiomp5.dylib) # for intermediate binaries, lib id @loader_path
2014                         endif()
2015                 endif()
2016         endif()
2017
2018         set(EXETYPE MACOSX_BUNDLE)
2019
2020         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
2021         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
2022         if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386")
2023                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -msse -msse2 -msse3 -mssse3")
2024                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic  -msse -msse2 -msse3 -mssse3")
2025                 if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
2026                         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
2027                         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
2028                 endif()
2029         else()
2030                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
2031                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
2032         endif()
2033
2034         if(${XCODE_VERSION} VERSION_EQUAL 5 OR ${XCODE_VERSION} VERSION_GREATER 5)
2035                 # Xcode 5 is always using CLANG, which has too low template depth of 128 for libmv
2036                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
2037         endif()
2038         # Get rid of eventually clashes, we export some symbols explicite as local
2039         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Xlinker -unexported_symbols_list -Xlinker ${CMAKE_SOURCE_DIR}/source/creator/osx_locals.map")
2040 endif()
2041
2042 #-----------------------------------------------------------------------------
2043 # Common.
2044
2045 if(APPLE OR WIN32)
2046         if(NOT EXISTS "${LIBDIR}/")
2047                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
2048         endif()
2049 endif()
2050
2051 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
2052         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
2053 endif()
2054
2055 if(WITH_CYCLES)
2056         if(NOT WITH_OPENIMAGEIO)
2057                 message(FATAL_ERROR "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
2058         endif()
2059         if(NOT WITH_BOOST)
2060                 message(FATAL_ERROR "Cycles requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
2061         endif()
2062
2063         if(WITH_CYCLES_OSL)
2064                 if(NOT WITH_LLVM)
2065                         message(FATAL_ERROR "Cycles OSL requires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
2066                 endif()
2067         endif()
2068 endif()
2069
2070 if(WITH_INTERNATIONAL)
2071         if(NOT WITH_BOOST)
2072                 message(FATAL_ERROR "Internationalization requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_INTERNATIONAL")
2073         endif()
2074 endif()
2075
2076 # See TEST_SSE_SUPPORT() for how this is defined.
2077
2078 if(WITH_RAYOPTIMIZATION)
2079         if(SUPPORT_SSE_BUILD)
2080                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
2081                 add_definitions(-D__SSE__ -D__MMX__)
2082         endif()
2083         if(SUPPORT_SSE2_BUILD)
2084                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
2085                 add_definitions(-D__SSE2__)
2086                 if(NOT SUPPORT_SSE_BUILD) # dont double up
2087                         add_definitions(-D__MMX__)
2088                 endif()
2089         endif()
2090 endif()
2091
2092
2093 # set the endian define
2094 if(MSVC)
2095         # for some reason this fails on msvc
2096         add_definitions(-D__LITTLE_ENDIAN__)
2097         
2098 # OSX-Note: as we do crosscompiling with specific set architecture,
2099 # endianess-detection and autosetting is counterproductive
2100 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
2101
2102 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
2103         add_definitions(-D__LITTLE_ENDIAN__)
2104 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)            
2105         add_definitions(-D__BIG_ENDIAN__)
2106         
2107 else()
2108         include(TestBigEndian)
2109         test_big_endian(_SYSTEM_BIG_ENDIAN)
2110         if(_SYSTEM_BIG_ENDIAN)
2111                 add_definitions(-D__BIG_ENDIAN__)
2112         else()
2113                 add_definitions(-D__LITTLE_ENDIAN__)
2114         endif()
2115         unset(_SYSTEM_BIG_ENDIAN)
2116 endif()
2117
2118
2119 if(WITH_IMAGE_OPENJPEG)
2120         if(WITH_SYSTEM_OPENJPEG)
2121                 # dealt with above
2122         else()
2123                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
2124                 add_definitions(-DOPJ_STATIC)
2125         endif()
2126 endif()
2127
2128 if(WITH_IMAGE_REDCODE)
2129         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
2130         set(REDCODE_INC ${REDCODE})
2131 endif()
2132
2133
2134 #-----------------------------------------------------------------------------
2135 # Configure OpenGL.
2136
2137 find_package(OpenGL)
2138 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
2139
2140 if(WITH_GLU)
2141         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_glu_LIBRARY}")
2142         list(APPEND GL_DEFINITIONS -DWITH_GLU)
2143 endif()
2144
2145 if(WITH_SYSTEM_GLES)
2146         find_package_wrapper(OpenGLES)
2147 endif()
2148
2149 if(WITH_GL_PROFILE_COMPAT OR WITH_GL_PROFILE_CORE)
2150         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_gl_LIBRARY}")
2151
2152 elseif(WITH_GL_PROFILE_ES20)
2153         if(WITH_SYSTEM_GLES)
2154                 if(NOT OPENGLES_LIBRARY)
2155                         message(FATAL_ERROR "Unable to find OpenGL ES libraries.  Install them or disable WITH_SYSTEM_GLES.")
2156                 endif()
2157
2158                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_LIBRARY)
2159
2160         else()
2161                 set(OPENGLES_LIBRARY "" CACHE FILEPATH "OpenGL ES 2.0 library file")
2162                 mark_as_advanced(OPENGLES_LIBRARY)
2163
2164                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
2165
2166                 if (NOT OPENGLES_LIBRARY)
2167                         message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_LIBRARY to the file path of an OpenGL ES 2.0 library.")
2168                 endif()
2169
2170         endif()
2171
2172         if(WIN32)
2173                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
2174
2175                 set(OPENGLES_DLL "" CACHE FILEPATH "OpenGL ES 2.0 redistributable DLL file")
2176                 mark_as_advanced(OPENGLES_DLL)
2177
2178                 if(NOT OPENGLES_DLL)
2179                         message(FATAL_ERROR "To compile WITH_GL_PROFILE_ES20 you need to set OPENGLES_DLL to the file path of an OpenGL ES 2.0 runtime dynamic link library (DLL).")
2180                 endif()
2181
2182                 if(WITH_GL_ANGLE)
2183                         list(APPEND GL_DEFINITIONS -DWITH_ANGLE)
2184
2185                         set(D3DCOMPILER_DLL "" CACHE FILEPATH "Direct3D Compiler redistributable DLL file (needed by ANGLE)")
2186
2187                         get_filename_component(D3DCOMPILER_FILENAME "${D3DCOMPILER_DLL}" NAME)
2188                         list(APPEND GL_DEFINITIONS "-DD3DCOMPILER=\"\\\"${D3DCOMPILER_FILENAME}\\\"\"")
2189
2190                         mark_as_advanced(D3DCOMPILER_DLL)
2191
2192                         if (D3DCOMPILER_DLL STREQUAL "")
2193                                 message(FATAL_ERROR "To compile WITH_GL_ANGLE you need to set D3DCOMPILER_DLL to the file path of a copy of the DirectX redistributable DLL file: D3DCompiler_46.dll")
2194                         endif()
2195
2196                 endif()
2197
2198         endif()
2199
2200 endif()
2201
2202 if(WITH_GL_EGL)
2203         list(APPEND GL_DEFINITIONS -DWITH_GL_EGL)
2204
2205         if(WITH_SYSTEM_GLES)
2206                 if(NOT OPENGLES_EGL_LIBRARY)
2207                         message(FATAL_ERROR "Unable to find OpenGL ES libraries.  Install them or disable WITH_SYSTEM_GLES.")
2208                 endif()
2209
2210                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_EGL_LIBRARY)
2211
2212         else()
2213                 set(OPENGLES_EGL_LIBRARY "" CACHE FILEPATH "EGL library file")
2214                 mark_as_advanced(OPENGLES_EGL_LIBRARY)
2215
2216                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}" "${OPENGLES_EGL_LIBRARY}")
2217
2218                 if (NOT OPENGLES_EGL_LIBRARY)
2219                         message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY to the file path of an EGL library.")
2220                 endif()
2221
2222         endif()
2223
2224         if(WIN32)
2225                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
2226
2227                 set(OPENGLES_EGL_DLL "" CACHE FILEPATH "EGL redistributable DLL file")
2228                 mark_as_advanced(OPENGLES_EGL_DLL)
2229
2230                 if(NOT OPENGLES_EGL_DLL)
2231                         message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_EGL_DLL to the file path of an EGL runtime dynamic link library (DLL).")
2232                 endif()
2233
2234         endif()
2235
2236 endif()
2237
2238 if(WITH_GL_PROFILE_COMPAT)
2239         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_COMPAT)
2240 endif()
2241
2242 if(WITH_GL_PROFILE_CORE)
2243         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_CORE)
2244 endif()
2245
2246 if(WITH_GL_PROFILE_ES20)
2247         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_ES20)
2248 endif()
2249
2250 if(WITH_GL_EGL)
2251         list(APPEND GL_DEFINITIONS -DWITH_EGL)
2252 endif()
2253
2254 #-----------------------------------------------------------------------------
2255 # Configure OpenMP.
2256 if(WITH_OPENMP)
2257         find_package(OpenMP)
2258         if(OPENMP_FOUND)
2259                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
2260                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
2261         else()
2262                 set(WITH_OPENMP OFF)
2263         endif()
2264
2265         mark_as_advanced(
2266                 OpenMP_C_FLAGS
2267                 OpenMP_CXX_FLAGS
2268         )
2269 endif()
2270
2271 #-----------------------------------------------------------------------------
2272 # Configure GLEW
2273
2274 if(WITH_GLEW_MX)
2275         list(APPEND GL_DEFINITIONS -DWITH_GLEW_MX)
2276 endif()
2277
2278 if(WITH_SYSTEM_GLEW)
2279         find_package(GLEW)
2280
2281         # Note: There is an assumption here that the system GLEW is not a static library.
2282
2283         if(NOT GLEW_FOUND)
2284                 message(FATAL_ERROR "GLEW is required to build Blender. Install it or disable WITH_SYSTEM_GLEW.")
2285         endif()
2286
2287         if(WITH_GLEW_MX)
2288                 set(BLENDER_GLEW_LIBRARIES ${GLEW_MX_LIBRARY})
2289         else()
2290                 set(BLENDER_GLEW_LIBRARIES ${GLEW_LIBRARY})
2291         endif()
2292 else()
2293         if(WITH_GLEW_ES)
2294                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew-es/include")
2295
2296                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC -DWITH_GLEW_ES)
2297
2298                 # These definitions remove APIs from glew.h, making GLEW smaller, and catching unguarded API usage
2299                 if(NOT WITH_GL_PROFILE_ES20)
2300                         # No ES functions are needed
2301                         list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
2302                 elseif(NOT (WITH_GL_PROFILE_CORE OR WITH_GL_PROFILE_COMPAT))
2303                         # ES is enabled, but the other functions are all disabled
2304                         list(APPEND GL_DEFINITIONS -DGLEW_ES_ONLY)
2305                 endif()
2306
2307                 if(WITH_GL_PROFILE_ES20)
2308                         if(WITH_GL_EGL)
2309                                 list(APPEND GL_DEFINITIONS -DGLEW_USE_LIB_ES20)
2310                         endif()
2311
2312                         # ToDo: This is an experiment to eliminate ES 1 symbols,
2313                         # GLEW doesn't really properly provide this level of control
2314                         # (for example, without modification it eliminates too many symbols)
2315                         # so there are lots of modifications to GLEW to make this work,
2316                         # and no attempt to make it work beyond Blender at this point.
2317                         list(APPEND GL_DEFINITIONS -DGL_ES_VERSION_1_0=0 -DGL_ES_VERSION_CL_1_1=0 -DGL_ES_VERSION_CM_1_1=0)
2318                 endif()
2319
2320                 if(WITH_GL_EGL)
2321                         list(APPEND GL_DEFINITIONS -DGLEW_INC_EGL)
2322                 endif()
2323
2324                 set(BLENDER_GLEW_LIBRARIES extern_glew_es bf_intern_glew_mx)
2325
2326         else()
2327                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
2328
2329                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC)
2330
2331                 # This won't affect the non-experimental glew library, 
2332                 # but is used for conditional compilation elsewhere.
2333                 list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
2334
2335                 set(BLENDER_GLEW_LIBRARIES extern_glew)
2336
2337         endif()
2338
2339 endif()
2340
2341 if(NOT WITH_GLU)
2342         list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
2343 endif()
2344
2345 #-----------------------------------------------------------------------------
2346 # Configure Bullet
2347
2348 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
2349         find_package(Bullet)
2350         if(NOT BULLET_FOUND)
2351                 set(WITH_BULLET OFF)
2352         endif()
2353 else()
2354         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
2355         # set(BULLET_LIBRARIES "")
2356 endif()
2357
2358 #-----------------------------------------------------------------------------
2359 # Configure Python.
2360
2361 if(WITH_PYTHON_MODULE)
2362         add_definitions(-DPy_ENABLE_SHARED)
2363 endif()
2364
2365 #-----------------------------------------------------------------------------
2366 # Extra compile flags
2367
2368 if(CMAKE_COMPILER_IS_GNUCC)
2369
2370         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2371         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
2372         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2373         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2374         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2375         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
2376         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2377         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2378         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2379         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2380         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2381         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2382         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
2383         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
2384         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
2385         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2386         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
2387         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2388         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2389         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
2390
2391         # gcc 4.2 gives annoying warnings on every file with this
2392         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2393                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
2394         endif()
2395
2396         # versions before gcc4.6 give many BLI_math warnings
2397         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
2398                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
2399                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
2400         endif()
2401
2402         # disable because it gives warnings for printf() & friends.
2403         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
2404
2405         if(NOT APPLE)
2406                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2407         endif()
2408
2409         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2410         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2411         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2412         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
2413         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2414         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2415         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2416         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
2417
2418         # gcc 4.2 gives annoying warnings on every file with this
2419         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2420                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
2421         endif()
2422
2423         # causes too many warnings
2424         if(NOT APPLE)
2425                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
2426                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
2427         endif()
2428
2429         # flags to undo strict flags
2430         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
2431         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
2432
2433         if(NOT APPLE)
2434                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2435         endif()
2436
2437 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
2438
2439         if(APPLE AND WITH_OPENMP) # we need the Intel omp lib linked here to not fail all tests due presence of -fopenmp !
2440                 set(CMAKE_REQUIRED_FLAGS "-L${LIBDIR}/openmp/lib -liomp5") # these are only used for the checks
2441         endif()
2442
2443         # strange, clang complains these are not supported, but then yses them.
2444         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2445         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2446         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2447         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2448         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2449         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2450         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2451         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2452         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2453         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2454
2455         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2456         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2457         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
2458         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
2459         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_OVERLOADED_VIRTUAL  -Wno-overloaded-virtual)  # we get a lot of these, if its a problem a dev needs to look into it.
2460         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
2461         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
2462
2463         # gives too many unfixable warnings
2464         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
2465         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
2466
2467         # flags to undo strict flags
2468         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
2469         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
2470
2471         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
2472         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
2473         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
2474         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
2475         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
2476         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
2477         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
2478         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
2479
2480         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
2481         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
2482         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
2483         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
2484         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
2485
2486 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
2487
2488         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2489         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2490         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2491
2492         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2493         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2494         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2495
2496         # disable numbered, false positives
2497         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
2498         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
2499
2500 endif()
2501
2502 # ensure python header is found since detection can fail, this could happen
2503 # with _any_ library but since we used a fixed python version this tends to
2504 # be most problematic.
2505 if(WITH_PYTHON)
2506         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
2507                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
2508                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
2509                                                         "to a valid python include path. Containing "
2510                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
2511         endif()
2512
2513         if(WIN32)
2514                 # pass, we have this in an archive to extract
2515         elseif(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
2516                 find_python_package(numpy)
2517         endif()
2518
2519         if(WIN32 OR APPLE)
2520                 # pass, we have this in lib/python/site-packages
2521         elseif(WITH_PYTHON_INSTALL_REQUESTS)
2522                 find_python_package(requests)
2523         endif()
2524 endif()
2525
2526 if(WITH_GCC_MUDFLAP)
2527         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -fmudflapth -funwind-tables")
2528         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread -lmudflapth -rdynamic")
2529         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS     C_WARN_NO_ERROR_MUDFLAP   -Wno-error=mudflap)
2530         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_ERROR_MUDFLAP -Wno-error=mudflap)
2531 endif()
2532
2533 # Include warnings first, so its possible to disable them with user defined flags
2534 # eg: -Wno-uninitialized
2535 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
2536 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
2537
2538 # defined above, platform spesific but shared names
2539 mark_as_advanced(
2540         CYCLES_OSL
2541         OSL_LIB_EXEC
2542         OSL_COMPILER
2543         OSL_LIB_COMP
2544         OSL_LIB_QUERY
2545         OSL_INCLUDES
2546 )
2547
2548 mark_as_advanced(
2549         LLVM_CONFIG
2550         LLVM_DIRECTORY
2551         LLVM_LIBRARY
2552         LLVM_VERSION
2553 )
2554
2555 #-------------------------------------------------------------------------------
2556 # Global Defines
2557
2558 # better not set includes here but this debugging option is off by default.
2559 if(WITH_CXX_GUARDEDALLOC)
2560         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
2561         add_definitions(-DWITH_CXX_GUARDEDALLOC)
2562 endif()
2563
2564 if(WITH_ASSERT_ABORT)
2565         add_definitions(-DWITH_ASSERT_ABORT)
2566 endif()
2567
2568 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
2569 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
2570
2571 #-----------------------------------------------------------------------------
2572 # Libraries
2573
2574 if(WITH_GTESTS)
2575         include(GTestTesting)
2576 endif()
2577
2578 if(WITH_BLENDER OR WITH_PLAYER)
2579         add_subdirectory(intern)
2580         add_subdirectory(extern)
2581
2582         # source after intern and extern to gather all
2583         # internal and external library information first, for test linking
2584         add_subdirectory(source)
2585 elseif(WITH_CYCLES_STANDALONE)
2586         add_subdirectory(intern/cycles)
2587         add_subdirectory(extern/clew)
2588         add_subdirectory(extern/cuew)
2589         if(NOT WITH_SYSTEM_GLEW)
2590                 add_subdirectory(extern/glew)
2591         endif()
2592 endif()
2593
2594 #-----------------------------------------------------------------------------
2595 # Blender Application
2596 if(WITH_BLENDER)
2597         add_subdirectory(source/creator)
2598 endif()
2599
2600
2601 #-----------------------------------------------------------------------------
2602 # Blender Player
2603 if(WITH_PLAYER)
2604         add_subdirectory(source/blenderplayer)
2605 endif()
2606
2607
2608 #-----------------------------------------------------------------------------
2609 # Testing
2610 add_subdirectory(tests)
2611
2612
2613 #-----------------------------------------------------------------------------
2614 # CPack for generating packages
2615 include(build_files/cmake/packaging.cmake)
2616
2617
2618 #-----------------------------------------------------------------------------
2619 # Print Final Configuration
2620
2621 if(FIRST_RUN)
2622         set(_config_msg "\n* Blender Configuration *")
2623         macro(info_cfg_option
2624                 _setting)
2625                 set(_msg "   * ${_setting}")
2626                 string(LENGTH "${_msg}" _len)
2627                 while("32" GREATER "${_len}")
2628                         set(_msg "${_msg} ")
2629                          math(EXPR _len "${_len} + 1")
2630                 endwhile()
2631
2632                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
2633         endmacro()
2634
2635         macro(info_cfg_text
2636                 _text)
2637                 set(_config_msg "${_config_msg}\n\n  ${_text}")
2638
2639
2640         endmacro()
2641
2642         message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
2643         message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
2644
2645         info_cfg_text("Build Options:")
2646         info_cfg_option(WITH_GAMEENGINE)
2647         info_cfg_option(WITH_PLAYER)
2648         info_cfg_option(WITH_BULLET)
2649         info_cfg_option(WITH_IK_SOLVER)
2650         info_cfg_option(WITH_IK_ITASC)
2651         info_cfg_option(WITH_OPENCOLLADA)
2652         info_cfg_option(WITH_FFTW3)
2653         info_cfg_option(WITH_INTERNATIONAL)
2654         info_cfg_option(WITH_INPUT_NDOF)
2655         info_cfg_option(WITH_CYCLES)
2656         info_cfg_option(WITH_FREESTYLE)
2657         info_cfg_option(WITH_OPENCOLORIO)
2658
2659         info_cfg_text("Compiler Options:")
2660         info_cfg_option(WITH_BUILDINFO)
2661         info_cfg_option(WITH_OPENMP)
2662         info_cfg_option(WITH_RAYOPTIMIZATION)
2663
2664         info_cfg_text("System Options:")
2665         info_cfg_option(WITH_INSTALL_PORTABLE)
2666         info_cfg_option(WITH_X11_XF86VMODE)
2667         info_cfg_option(WITH_X11_XINPUT)
2668         info_cfg_option(WITH_MEM_JEMALLOC)
2669         info_cfg_option(WITH_MEM_VALGRIND)
2670         info_cfg_option(WITH_SYSTEM_GLEW)
2671         info_cfg_option(WITH_SYSTEM_OPENJPEG)
2672
2673         info_cfg_text("Image Formats:")
2674         info_cfg_option(WITH_OPENIMAGEIO)
2675         info_cfg_option(WITH_IMAGE_CINEON)
2676         info_cfg_option(WITH_IMAGE_DDS)
2677         info_cfg_option(WITH_IMAGE_HDR)
2678         info_cfg_option(WITH_IMAGE_OPENEXR)
2679         info_cfg_option(WITH_IMAGE_OPENJPEG)
2680         info_cfg_option(WITH_IMAGE_REDCODE)
2681         info_cfg_option(WITH_IMAGE_TIFF)
2682
2683         info_cfg_text("Audio:")
2684         info_cfg_option(WITH_OPENAL)
2685         info_cfg_option(WITH_SDL)
2686         info_cfg_option(WITH_JACK)
2687         info_cfg_option(WITH_JACK_DYNLOAD)
2688         info_cfg_option(WITH_CODEC_AVI)
2689         info_cfg_option(WITH_CODEC_FFMPEG)
2690         info_cfg_option(WITH_CODEC_SNDFILE)
2691
2692         info_cfg_text("Compression:")
2693         info_cfg_option(WITH_LZMA)
2694         info_cfg_option(WITH_LZO)
2695
2696         info_cfg_text("Python:")
2697         info_cfg_option(WITH_PYTHON_INSTALL)
2698         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
2699         info_cfg_option(WITH_PYTHON_MODULE)
2700         info_cfg_option(WITH_PYTHON_SAFETY)
2701         if(APPLE)
2702                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
2703         endif()
2704
2705         info_cfg_text("Modifiers:")
2706         info_cfg_option(WITH_MOD_BOOLEAN)
2707         info_cfg_option(WITH_MOD_REMESH)
2708         info_cfg_option(WITH_MOD_FLUID)
2709         info_cfg_option(WITH_MOD_OCEANSIM)
2710
2711         info_cfg_text("OpenGL:")
2712         info_cfg_option(WITH_GLEW_ES)
2713         info_cfg_option(WITH_GLU)
2714         info_cfg_option(WITH_GL_EGL)
2715         info_cfg_option(WITH_GL_PROFILE_COMPAT)
2716         info_cfg_option(WITH_GL_PROFILE_CORE)
2717         info_cfg_option(WITH_GL_PROFILE_ES20)
2718         if(WIN32)
2719                 info_cfg_option(WITH_GL_ANGLE)
2720         endif()
2721
2722         info_cfg_text("Other:")
2723         info_cfg_option(WITH_OPENNL)
2724
2725         # debug
2726         message(STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}")
2727
2728         info_cfg_text("")
2729
2730         message("${_config_msg}")
2731 endif()