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