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