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