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