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