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