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