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