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