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