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