Merge branch 'master' into blender2.8
[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 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/platform")
59
60 # avoid having empty buildtype
61 set(CMAKE_BUILD_TYPE_INIT "Release")
62
63 # quiet output for Makefiles, 'make -s' helps too
64 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
65
66 # global compile definitions since add_definitions() adds for all.
67
68 if(NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
69         set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
70                 $<$<CONFIG:Debug>:DEBUG;_DEBUG>
71                 $<$<CONFIG:Release>:NDEBUG>
72                 $<$<CONFIG:MinSizeRel>:NDEBUG>
73                 $<$<CONFIG:RelWithDebInfo>:NDEBUG>
74         )
75 else()
76         # keep until CMake-3.0 is min requirement
77         set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
78         set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
79         set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
80         set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
81 endif()
82
83 #-----------------------------------------------------------------------------
84 # Set policy
85
86 # see "cmake --help-policy CMP0003"
87 # So library linking is more sane
88 cmake_policy(SET CMP0003 NEW)
89
90 # So BUILDINFO and BLENDERPATH strings are automatically quoted
91 cmake_policy(SET CMP0005 NEW)
92
93 # So syntax problems are errors
94 cmake_policy(SET CMP0010 NEW)
95
96 # Input directories must have CMakeLists.txt
97 cmake_policy(SET CMP0014 NEW)
98
99 #-----------------------------------------------------------------------------
100 # Load some macros.
101 include(build_files/cmake/macros.cmake)
102
103
104 #-----------------------------------------------------------------------------
105 # Initialize project.
106
107 blender_project_hack_pre()
108
109 project(Blender)
110
111 blender_project_hack_post()
112
113 enable_testing()
114
115 #-----------------------------------------------------------------------------
116 # Redirect output files
117
118 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
119 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
120 set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests CACHE INTERNAL "" FORCE)
121
122 #-----------------------------------------------------------------------------
123 # Set default config options
124
125 get_blender_version()
126
127
128 #-----------------------------------------------------------------------------
129 # Platform Specific Defaults
130
131 # list of var-names
132 set(_init_vars)
133
134 # initialize to ON
135 macro(option_defaults_init)
136         foreach(_var ${ARGV})
137                 set(${_var} ON)
138                 list(APPEND _init_vars "${_var}")
139         endforeach()
140         unset(_var)
141 endmacro()
142
143 # remove from namespace
144 macro(option_defaults_clear)
145         foreach(_var ${_init_vars})
146                 unset(${_var})
147         endforeach()
148         unset(_var)
149         unset(_init_vars)
150 endmacro()
151
152
153 # values to initialize WITH_****
154 option_defaults_init(
155         _init_BUILDINFO
156         _init_CODEC_FFMPEG
157         _init_CYCLES_OSL
158         _init_CYCLES_OPENSUBDIV
159         _init_IMAGE_OPENEXR
160         _init_INPUT_NDOF
161         _init_JACK
162         _init_OPENCOLLADA
163         _init_OPENCOLORIO
164         _init_SDL
165         _init_FFTW3
166         _init_GAMEENGINE
167         _init_OPENSUBDIV
168 )
169
170 # customize...
171 if(UNIX AND NOT APPLE)
172         # some of these libraries are problematic on Linux
173         # disable less important dependencies by default
174         set(_init_CODEC_FFMPEG                   OFF)
175         set(_init_CYCLES_OSL                     OFF)
176         set(_init_CYCLES_OPENSUBDIV              OFF)
177         set(_init_IMAGE_OPENEXR                  OFF)
178         set(_init_JACK                           OFF)
179         set(_init_OPENCOLLADA                    OFF)
180         set(_init_OPENCOLORIO                    OFF)
181         set(_init_SDL                            OFF)
182         set(_init_FFTW3                          OFF)
183         set(_init_OPENSUBDIV                     OFF)
184 elseif(WIN32)
185         set(_init_JACK                           OFF)
186 elseif(APPLE)
187         set(_init_JACK                           OFF)
188         set(_init_OPENSUBDIV                     OFF)
189 endif()
190
191
192 #-----------------------------------------------------------------------------
193 # Options
194
195 # First platform specific non-cached vars
196 if(UNIX AND NOT APPLE)
197         set(WITH_X11 ON)
198 endif()
199
200 # Blender internal features
201 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
202 mark_as_advanced(WITH_BLENDER)
203
204 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
205
206 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
207 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON) 
208 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
209 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distributions see this as a security issue, rather than have them patch it, make a build option.
210
211 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)
212 mark_as_advanced(WITH_PYTHON_SAFETY)
213 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)
214 if(APPLE)
215         option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
216 endif()
217
218 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ${_init_BUILDINFO})
219 if(${CMAKE_VERSION} VERSION_LESS 2.8.8)
220         # add_library OBJECT arg unsupported
221         set(WITH_BUILDINFO OFF)
222 endif()
223 set(BUILDINFO_OVERRIDE_DATE "" CACHE STRING "Use instead of the current date for reproducable builds (empty string disables this option)")
224 set(BUILDINFO_OVERRIDE_TIME "" CACHE STRING "Use instead of the current time for reproducable builds (empty string disables this option)")
225 set(CPACK_OVERRIDE_PACKAGENAME "" CACHE STRING "Use instead of the standard packagename (empty string disables this option)")
226 mark_as_advanced(CPACK_OVERRIDE_PACKAGENAME)
227 mark_as_advanced(BUILDINFO_OVERRIDE_DATE)
228 mark_as_advanced(BUILDINFO_OVERRIDE_TIME)
229
230 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
231 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
232 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" ${_init_FFTW3})
233 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
234 option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
235 mark_as_advanced(WITH_SYSTEM_BULLET)
236 option(WITH_GAMEENGINE    "Enable Game Engine" ${_init_GAMEENGINE})
237 if(APPLE)
238         set(WITH_GAMEENGINE_DECKLINK OFF)
239 else()
240         option(WITH_GAMEENGINE_DECKLINK "Support BlackMagicDesign DeckLink cards in the Game Engine" ON)
241 endif()
242 option(WITH_PLAYER        "Build Player" OFF)
243 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ${_init_OPENCOLORIO})
244
245 option(WITH_CLAY_ENGINE    "Enable New Clay engine (Breaks Mac and Mesa compatibility)" ON)
246
247 option(WITH_LEGACY_OPENGL  "Enable build of legacy OpenGL" ON)
248
249 # Compositor
250 option(WITH_COMPOSITOR         "Enable the tile based nodal compositor" ON)
251
252 option(WITH_OPENSUBDIV    "Enable OpenSubdiv for surface subdivision" _init_OPENSUBDIV)
253
254 option(WITH_OPENVDB       "Enable features relying on OpenVDB" OFF)
255 option(WITH_OPENVDB_BLOSC "Enable blosc compression for OpenVDB, only enable if OpenVDB was built with blosc support" OFF)
256
257 # GHOST Windowing Library Options
258 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
259 mark_as_advanced(WITH_GHOST_DEBUG)
260
261 option(WITH_GHOST_SDL    "Enable building Blender against SDL for windowing rather than the native APIs" OFF)
262 mark_as_advanced(WITH_GHOST_SDL)
263
264 if(WITH_X11)
265         option(WITH_GHOST_XDND    "Enable drag'n'drop support on X11 using XDND protocol" ON)
266 endif()
267
268 # Misc...
269 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
270 mark_as_advanced(WITH_HEADLESS)
271
272 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
273 option(WITH_SYSTEM_AUDASPACE "Build with external audaspace library installed on the system (only enable if you know what you're doing!)" OFF)
274 mark_as_advanced(WITH_AUDASPACE)
275 mark_as_advanced(WITH_SYSTEM_AUDASPACE)
276
277 if(NOT WITH_AUDASPACE)
278         set(WITH_SYSTEM_AUDASPACE OFF)
279 endif()
280
281 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
282 if(UNIX AND NOT APPLE)
283         option(WITH_OPENMP_STATIC "Link OpenMP statically (only used by the release environment)" OFF)
284         mark_as_advanced(WITH_OPENMP_STATIC)
285 endif()
286
287 if(WITH_X11)
288         option(WITH_X11_XINPUT    "Enable X11 Xinput (tablet support and unicode input)"  ON)
289         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"                       ON)
290         option(WITH_X11_ALPHA     "Enable X11 transparent background"                     ON)
291 endif()
292
293 if(UNIX AND NOT APPLE)
294         option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" ON)
295         option(WITH_SYSTEM_GLES "Use OpenGL ES library provided by the operating system"           ON)
296 else()
297         # not an option for other OS's
298         set(WITH_SYSTEM_GLEW OFF)
299         set(WITH_SYSTEM_GLES OFF)
300 endif()
301
302
303 # (unix defaults to System OpenJPEG On)
304 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" OFF)
305
306 if(UNIX AND NOT APPLE)
307         option(WITH_SYSTEM_EIGEN3 "Use the systems Eigen3 library" OFF)
308 endif()
309
310
311 # Modifiers
312 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
313 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
314 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
315 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
316 # option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)  # this is now only available in a branch
317 # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
318 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
319
320 # Image format support
321 option(WITH_OPENIMAGEIO         "Enable OpenImageIO Support (http://www.openimageio.org)" ON)
322 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ${_init_IMAGE_OPENEXR})
323 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
324 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
325 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
326 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
327 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
328 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
329
330 # Audio/Video format support
331 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
332 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ${_init_CODEC_FFMPEG})
333 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
334
335 # Alembic support
336 option(WITH_ALEMBIC             "Enable Alembic Support" OFF)
337 option(WITH_ALEMBIC_HDF5        "Enable Legacy Alembic Support (not officially supported)" OFF)
338
339 if(APPLE)
340         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" OFF)
341 endif()
342
343 # 3D format support
344 # Disable opencollada when we don't have precompiled libs
345 option(WITH_OPENCOLLADA   "Enable OpenCollada Support (http://www.opencollada.org)" ${_init_OPENCOLLADA})
346
347 # Sound output
348 option(WITH_SDL           "Enable SDL for sound and joystick support" ${_init_SDL})
349 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
350 option(WITH_JACK          "Enable JACK Support (http://www.jackaudio.org)" ${_init_JACK})
351 if(UNIX AND NOT APPLE)
352         option(WITH_JACK_DYNLOAD  "Enable runtime dynamic JACK libraries loading" OFF)
353 endif()
354 if(UNIX AND NOT APPLE)
355         option(WITH_SDL_DYNLOAD  "Enable runtime dynamic SDL libraries loading" OFF)
356 endif()
357
358 # Compression
359 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
360 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
361 if(UNIX AND NOT APPLE)
362         option(WITH_SYSTEM_LZO    "Use the system LZO library" OFF)
363 endif()
364
365 # Camera/motion tracking
366 option(WITH_LIBMV         "Enable Libmv structure from motion library" ON)
367 option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." OFF)
368 mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
369
370 # Logging/unbit test libraries.
371 option(WITH_SYSTEM_GFLAGS   "Use system-wide Gflags instead of a bundled one" OFF)
372 option(WITH_SYSTEM_GLOG     "Use system-wide Glog instead of a bundled one" OFF)
373 mark_as_advanced(WITH_SYSTEM_GFLAGS)
374 mark_as_advanced(WITH_SYSTEM_GLOG)
375
376 # Freestyle
377 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
378
379 # Misc
380 if(WIN32)
381         option(WITH_INPUT_IME "Enable Input Method Editor (IME) for complex Asian character input" ON)
382 endif()
383 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ${_init_INPUT_NDOF})
384 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
385 if(UNIX AND NOT APPLE)
386         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
387         option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
388         if(WITH_STATIC_LIBS)
389                 option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
390                 mark_as_advanced(WITH_BOOST_ICU)
391         endif()
392 endif()
393
394 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
395 if(WITH_PYTHON_INSTALL)
396         option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
397         set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
398         mark_as_advanced(PYTHON_NUMPY_PATH)
399
400         if(UNIX AND NOT APPLE)
401                 option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
402                 set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
403                 mark_as_advanced(PYTHON_REQUESTS_PATH)
404         endif()
405 endif()
406
407 option(WITH_CPU_SSE              "Enable SIMD instruction if they're detected on the host machine" ON)
408 mark_as_advanced(WITH_CPU_SSE)
409
410 # Cycles
411 option(WITH_CYCLES                                      "Enable Cycles Render Engine" ON)
412 option(WITH_CYCLES_STANDALONE           "Build Cycles standalone application" OFF)
413 option(WITH_CYCLES_STANDALONE_GUI       "Build Cycles standalone with GUI" OFF)
414 option(WITH_CYCLES_OSL                          "Build Cycles with OSL support" ${_init_CYCLES_OSL})
415 option(WITH_CYCLES_OPENSUBDIV           "Build Cycles with OpenSubdiv support" ${_init_CYCLES_OPENSUBDIV})
416 option(WITH_CYCLES_CUDA_BINARIES        "Build Cycles CUDA binaries" OFF)
417 set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_37 sm_50 sm_52 sm_60 sm_61 CACHE STRING "CUDA architectures to build binaries for")
418 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
419 unset(PLATFORM_DEFAULT)
420 option(WITH_CYCLES_LOGGING      "Build Cycles with logging support" ON)
421 option(WITH_CYCLES_DEBUG        "Build Cycles with extra debug capabilities" OFF)
422 option(WITH_CYCLES_NATIVE_ONLY  "Build Cycles with native kernel only (which fits current CPU, use for development only)" OFF)
423 mark_as_advanced(WITH_CYCLES_LOGGING)
424 mark_as_advanced(WITH_CYCLES_DEBUG)
425 mark_as_advanced(WITH_CYCLES_NATIVE_ONLY)
426
427 option(WITH_CUDA_DYNLOAD "Dynamically load CUDA libraries at runtime" ON)
428 mark_as_advanced(WITH_CUDA_DYNLOAD)
429
430 # LLVM
431 option(WITH_LLVM                                        "Use LLVM" OFF)
432 if(APPLE)
433         option(LLVM_STATIC                                      "Link with LLVM static libraries" ON) # we prefer static llvm build on Apple, dyn build possible though
434 else()
435         option(LLVM_STATIC                                      "Link with LLVM static libraries" OFF)
436 endif()
437 mark_as_advanced(LLVM_STATIC)
438
439 # disable for now, but plan to support on all platforms eventually
440 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" ON)
441 mark_as_advanced(WITH_MEM_JEMALLOC)
442
443 # currently only used for BLI_mempool
444 option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
445 mark_as_advanced(WITH_MEM_VALGRIND)
446
447 # Debug
448 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
449 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
450
451 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
452 mark_as_advanced(WITH_ASSERT_ABORT)
453
454 option(WITH_BOOST                                       "Enable features depending on boost" ON)
455
456 # Unit testsing
457 option(WITH_GTESTS "Enable GTest unit testing" OFF)
458 option(WITH_OPENGL_TESTS "Enable OpenGL related unit testing (Experimental)" OFF)
459
460
461 # Documentation
462 if(UNIX AND NOT APPLE)
463         option(WITH_DOC_MANPAGE "Create a manual page (Unix manpage)" OFF)
464 endif()
465
466
467 # OpenGL
468
469 option(WITH_GLEW_ES             "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
470 option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)"       OFF)
471 option(WITH_GL_PROFILE_COMPAT   "Support using the OpenGL 'compatibility' profile. (deprecated)"                                                    ON )
472 option(WITH_GL_PROFILE_CORE     "Support using the OpenGL 3.3+ 'core' profile."                                                                     OFF)
473 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (thru either EGL or the AGL/WGL/XGL 'es20' profile)"                                  OFF)
474
475 mark_as_advanced(
476         WITH_GLEW_ES
477         WITH_GL_EGL
478         WITH_GL_PROFILE_COMPAT
479         WITH_GL_PROFILE_CORE
480         WITH_GL_PROFILE_ES20
481 )
482
483 if(WIN32)
484         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)
485         mark_as_advanced(WITH_GL_ANGLE)
486 endif()
487
488 if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
489         message(WARNING Ignoring WITH_SYSTEM_GLEW and using WITH_GLEW_ES)
490         set(WITH_SYSTEM_GLEW OFF)
491 endif()
492
493 if(WIN32)
494         getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
495         set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
496 endif()
497
498 # Experimental support of C11 and C++11
499 #
500 # We default options to whatever default standard in the current compiler.
501 if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0") AND (NOT WITH_CXX11))
502         set(_c11_init ON)
503 else()
504         set(_c11_init OFF)
505 endif()
506 set(_cxx11_init ON)
507
508 option(WITH_C11 "Build with C11 standard enabled, for development use only!" ${_c11_init})
509 mark_as_advanced(WITH_C11)
510 option(WITH_CXX11 "Build with C++11 standard enabled, for development use only!" ${_cxx11_init})
511 mark_as_advanced(WITH_CXX11)
512
513 # Compiler toolchain
514 if(CMAKE_COMPILER_IS_GNUCC)
515         option(WITH_LINKER_GOLD "Use ld.gold linker which is usually faster than ld.bfd" ON)
516         mark_as_advanced(WITH_LINKER_GOLD)
517 endif()
518
519 # Dependency graph
520 option(WITH_LEGACY_DEPSGRAPH "Build Blender with legacy dependency graph" ON)
521 mark_as_advanced(WITH_LEGACY_DEPSGRAPH)
522
523 if(WIN32)
524         # Use hardcoded paths or find_package to find externals
525         option(WITH_WINDOWS_FIND_MODULES "Use find_package to locate libraries" OFF)
526         mark_as_advanced(WITH_WINDOWS_FIND_MODULES)
527
528         option(WITH_WINDOWS_CODESIGN "Use signtool to sign the final binary." OFF)
529         mark_as_advanced(WITH_WINDOWS_CODESIGN)
530
531         set(WINDOWS_CODESIGN_PFX CACHE FILEPATH  "Path to pfx file to use for codesigning.")
532         mark_as_advanced(WINDOWS_CODESIGN_PFX)
533
534         set(WINDOWS_CODESIGN_PFX_PASSWORD CACHE STRING  "password for pfx file used for codesigning.")
535         mark_as_advanced(WINDOWS_CODESIGN_PFX_PASSWORD)
536 endif()
537
538 # avoid using again
539 option_defaults_clear()
540
541 # end option(...)
542
543
544
545 # By default we want to install to the directory we are compiling our executables
546 # unless specified otherwise, which we currently do not allow
547 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
548         if(WIN32)
549                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
550         elseif(APPLE)
551                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
552         else()
553                 if(WITH_INSTALL_PORTABLE)
554                         set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH} CACHE PATH "default install path" FORCE)
555                 endif()
556         endif()
557 endif()
558
559
560
561 # Apple
562
563 if(APPLE)
564         include(platform_apple_xcode)
565 endif()
566
567
568 #-----------------------------------------------------------------------------
569 # Check for conflicting/unsupported configurations
570
571 if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_STANDALONE)
572         message(FATAL_ERROR
573                 "At least one of WITH_BLENDER or WITH_PLAYER or "
574                 "WITH_CYCLES_STANDALONE must be enabled, nothing to do!"
575         )
576 endif()
577
578 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
579         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
580 endif()
581
582 if(WITH_GAMEENGINE AND NOT WITH_LEGACY_OPENGL)
583         message(FATAL_ERROR "WITH_GAME_ENGINE requires WITH_LEGACY_OPENGL")
584 endif()
585
586 if(NOT WITH_AUDASPACE)
587         if(WITH_OPENAL)
588                 message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
589         endif()
590         if(WITH_JACK)
591                 message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
592         endif()
593         if(WITH_GAMEENGINE)
594                 message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
595         endif()
596 endif()
597
598 if(NOT WITH_SDL AND WITH_GHOST_SDL)
599         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
600 endif()
601
602 # python module, needs some different options
603 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
604         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
605 endif()
606
607 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
608         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
609 endif()
610
611
612 # may as well build python module without a UI
613 if(WITH_PYTHON_MODULE)
614         set(WITH_HEADLESS ON)
615 endif()
616
617 if(NOT WITH_PYTHON)
618         set(WITH_CYCLES OFF)
619 endif()
620
621 # enable boost for cycles, audaspace or i18n
622 # otherwise if the user disabled
623 if(NOT WITH_BOOST)
624         # Explicitly disabled. so disable all deps.
625         macro(set_and_warn
626                 _setting _val)
627                 if(${${_setting}})
628                         message(STATUS "'WITH_BOOST' is disabled: forcing 'set(${_setting} ${_val})'")
629                 endif()
630                 set(${_setting} ${_val})
631         endmacro()
632
633         set_and_warn(WITH_CYCLES         OFF)
634         set_and_warn(WITH_AUDASPACE      OFF)
635         set_and_warn(WITH_INTERNATIONAL  OFF)
636         set_and_warn(WITH_OPENVDB        OFF)
637         set_and_warn(WITH_OPENCOLORIO    OFF)
638         set_and_warn(WITH_MOD_BOOLEAN    OFF)
639
640         set_and_warn(WITH_OPENAL         OFF)  # depends on AUDASPACE
641         set_and_warn(WITH_GAMEENGINE     OFF)  # depends on AUDASPACE
642         set_and_warn(WITH_PLAYER         OFF)  # depends on GAMEENGINE
643 elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_AUDASPACE OR WITH_INTERNATIONAL OR
644        WITH_OPENVDB OR WITH_OPENCOLORIO OR WITH_MOD_BOOLEAN)
645         # Keep enabled
646 else()
647         # New dependency graph needs either Boost or C++11 for function bindings.
648         if(NOT WITH_CXX11)
649                 # Enabled but we don't need it
650                 set(WITH_BOOST OFF)
651         endif()
652 endif()
653
654 # auto enable openimageio for cycles
655 if(WITH_CYCLES)
656         set(WITH_OPENIMAGEIO ON)
657
658         # auto enable llvm for cycles_osl
659         if(WITH_CYCLES_OSL)
660                 set(WITH_LLVM ON CACHE BOOL "" FORCE)
661         endif()
662 else()
663         set(WITH_CYCLES_OSL OFF)
664 endif()
665
666 # auto enable openimageio linking dependencies
667 if(WITH_OPENIMAGEIO)
668         set(WITH_IMAGE_OPENEXR ON)
669         set(WITH_IMAGE_TIFF ON)
670 endif()
671
672 # auto enable alembic linking dependencies
673 if(WITH_ALEMBIC)
674         set(WITH_IMAGE_OPENEXR ON)
675 endif()
676
677 # don't store paths to libs for portable distribution
678 if(WITH_INSTALL_PORTABLE)
679         set(CMAKE_SKIP_BUILD_RPATH TRUE)
680 endif()
681
682 if(WITH_GHOST_SDL OR WITH_HEADLESS)
683         set(WITH_X11           OFF)
684         set(WITH_X11_XINPUT    OFF)
685         set(WITH_X11_XF86VMODE OFF)
686         set(WITH_X11_ALPHA     OFF)
687         set(WITH_GHOST_XDND    OFF)
688         set(WITH_INPUT_IME     OFF)
689 endif()
690
691 if(WITH_CPU_SSE)
692         TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
693 else()
694         message(STATUS "SSE and SSE2 optimizations are DISABLED!")
695         set(COMPILER_SSE_FLAG)
696         set(COMPILER_SSE2_FLAG)
697 endif()
698
699 if(WITH_BUILDINFO)
700         find_package(Git)
701         if(NOT GIT_FOUND)
702                 message(WARNING "Git was not found, disabling WITH_BUILDINFO")
703                 set(WITH_BUILDINFO OFF)
704         endif()
705 endif()
706
707 TEST_SHARED_PTR_SUPPORT()
708 TEST_UNORDERED_MAP_SUPPORT()
709
710 if(WITH_AUDASPACE)
711         if(WITH_SYSTEM_AUDASPACE)
712                 set(AUDASPACE_DEFINITIONS
713                         -DWITH_AUDASPACE
714                         -DWITH_SYSTEM_AUDASPACE
715                         "-DAUD_DEVICE_H=<AUD_Device.h>"
716                         "-DAUD_SPECIAL_H=<AUD_Special.h>"
717                         "-DAUD_SOUND_H=<AUD_Sound.h>"
718                         "-DAUD_HANDLE_H=<AUD_Handle.h>"
719                         "-DAUD_SEQUENCE_H=<AUD_Sequence.h>"
720                         "-DAUD_TYPES_H=<AUD_Types.h>"
721                         "-DAUD_PYTHON_H=<python/PyAPI.h>"
722                 )
723         else()
724                 set(AUDASPACE_C_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/intern/audaspace/intern")
725                 set(AUDASPACE_PY_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/intern/audaspace/intern")
726                 set(AUDASPACE_DEFINITIONS
727                         -DWITH_AUDASPACE
728                         "-DAUD_DEVICE_H=<AUD_C-API.h>"
729                         "-DAUD_SPECIAL_H=<AUD_C-API.h>"
730                         "-DAUD_SOUND_H=<AUD_C-API.h>"
731                         "-DAUD_HANDLE_H=<AUD_C-API.h>"
732                         "-DAUD_SEQUENCE_H=<AUD_C-API.h>"
733                         "-DAUD_TYPES_H=<AUD_Space.h>"
734                 )
735         endif()
736 endif()
737
738 if(APPLE)
739         apple_check_quicktime()
740 endif()
741
742 #-----------------------------------------------------------------------------
743 # Check for valid directories
744 # ... a partial checkout may cause this.
745 #
746 # note: we need to check for a known subdir in both cases.
747 #       since uninitialized git submodules will give blank dirs
748
749 if(WITH_INTERNATIONAL)
750         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
751                 message(WARNING
752                         "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
753                         "This is a 'git submodule', which are known not to work with bridges to other version "
754                         "control systems, disabling 'WITH_INTERNATIONAL'."
755                 )
756                 set(WITH_INTERNATIONAL OFF)
757         endif()
758 endif()
759
760 if(WITH_PYTHON)
761         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
762                 message(WARNING
763                         "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
764                         "This is a 'git submodule', which are known not to work with bridges to other version "
765                         "control systems: * CONTINUING WITHOUT ADDONS *"
766                 )
767         endif()
768 endif()
769
770 #-----------------------------------------------------------------------------
771 # Initialize un-cached vars, avoid unused warning
772
773 # linux only, not cached
774 set(WITH_BINRELOC OFF)
775
776 # MACOSX only, set to avoid uninitialized
777 set(EXETYPE "")
778
779 # C/C++ flags
780 set(PLATFORM_CFLAGS)
781
782 # these are added to later on.
783 set(C_WARNINGS)
784 set(CXX_WARNINGS)
785
786 # for gcc -Wno-blah-blah
787 set(CC_REMOVE_STRICT_FLAGS)
788
789 # libraries to link the binary with passed to target_link_libraries()
790 # known as LLIBS to scons
791 set(PLATFORM_LINKLIBS "")
792
793 # Added to linker flags in setup_liblinks
794 # - CMAKE_EXE_LINKER_FLAGS
795 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
796 set(PLATFORM_LINKFLAGS "")
797 set(PLATFORM_LINKFLAGS_DEBUG "")
798
799
800 #-----------------------------------------------------------------------------
801 #Platform specifics
802
803 if(WITH_X11)
804         find_package(X11 REQUIRED)
805
806         find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
807         mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
808
809         list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
810
811         if(WITH_X11_XINPUT)
812                 if(X11_Xinput_LIB)
813                         list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
814                 else()
815                         set(WITH_X11_XINPUT OFF)
816                 endif()
817         endif()
818
819         if(WITH_X11_XF86VMODE)
820                 # XXX, why dont cmake make this available?
821                 find_library(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
822                 mark_as_advanced(X11_Xxf86vmode_LIB)
823                 if(X11_Xxf86vmode_LIB)
824                         list(APPEND PLATFORM_LINKLIBS ${X11_Xxf86vmode_LIB})
825                 else()
826                         set(WITH_X11_XF86VMODE OFF)
827                 endif()
828         endif()
829
830         if(WITH_X11_ALPHA)
831                 find_library(X11_Xrender_LIB Xrender  ${X11_LIB_SEARCH_PATH})
832                 mark_as_advanced(X11_Xrender_LIB)
833                 if(X11_Xrender_LIB)
834                         list(APPEND PLATFORM_LINKLIBS ${X11_Xrender_LIB})
835                 else()
836                         set(WITH_X11_ALPHA OFF)
837                 endif()
838         endif()
839
840 endif()
841
842
843 # ----------------------------------------------------------------------------
844 # Main Platform Checks
845 #
846 # - UNIX
847 # - WIN32
848 # - APPLE
849
850 if(UNIX AND NOT APPLE)
851         include(platform_unix)
852 elseif(WIN32)
853         include(platform_win32)
854 elseif(APPLE)
855         include(platform_apple)
856 endif()
857
858 #-----------------------------------------------------------------------------
859 # Common.
860
861 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
862         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
863 endif()
864
865 if(WITH_CYCLES)
866         if(NOT WITH_OPENIMAGEIO)
867                 message(FATAL_ERROR
868                         "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. "
869                         "Configure OIIO or disable WITH_CYCLES"
870                 )
871         endif()
872         if(NOT WITH_BOOST)
873                 message(FATAL_ERROR
874                         "Cycles requires WITH_BOOST, the library may not have been found. "
875                         "Configure BOOST or disable WITH_CYCLES"
876                 )
877         endif()
878
879         if(WITH_CYCLES_OSL)
880                 if(NOT WITH_LLVM)
881                         message(FATAL_ERROR
882                                 "Cycles OSL requires WITH_LLVM, the library may not have been found. "
883                                 "Configure LLVM or disable WITH_CYCLES_OSL"
884                         )
885                 endif()
886         endif()
887 endif()
888
889 if(WITH_INTERNATIONAL)
890         if(NOT WITH_BOOST)
891                 message(FATAL_ERROR
892                         "Internationalization requires WITH_BOOST, the library may not have been found. "
893                         "Configure BOOST or disable WITH_INTERNATIONAL"
894                 )
895         endif()
896 endif()
897
898 # See TEST_SSE_SUPPORT() for how this is defined.
899
900 # Do it globally, SSE2 is required for quite some time now.
901 # Doing it now allows to use SSE/SSE2 in inline headers.
902 if(SUPPORT_SSE_BUILD)
903         set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
904         add_definitions(-D__SSE__ -D__MMX__)
905 endif()
906 if(SUPPORT_SSE2_BUILD)
907         set(PLATFORM_CFLAGS " ${PLATFORM_CFLAGS} ${COMPILER_SSE2_FLAG}")
908         add_definitions(-D__SSE2__)
909         if(NOT SUPPORT_SSE_BUILD) # dont double up
910                 add_definitions(-D__MMX__)
911         endif()
912 endif()
913
914
915 # set the endian define
916 if(MSVC)
917         # for some reason this fails on msvc
918         add_definitions(-D__LITTLE_ENDIAN__)
919
920 # OSX-Note: as we do cross-compiling with specific set architecture,
921 # endianess-detection and auto-setting is counterproductive
922 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
923
924 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
925         add_definitions(-D__LITTLE_ENDIAN__)
926 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)
927         add_definitions(-D__BIG_ENDIAN__)
928
929 else()
930         include(TestBigEndian)
931         test_big_endian(_SYSTEM_BIG_ENDIAN)
932         if(_SYSTEM_BIG_ENDIAN)
933                 add_definitions(-D__BIG_ENDIAN__)
934         else()
935                 add_definitions(-D__LITTLE_ENDIAN__)
936         endif()
937         unset(_SYSTEM_BIG_ENDIAN)
938 endif()
939 if(WITH_IMAGE_OPENJPEG)
940         if(WITH_SYSTEM_OPENJPEG)
941                 # dealt with above
942                 set(OPENJPEG_DEFINES "")
943         else()
944                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
945                 set(OPENJPEG_DEFINES "-DOPJ_STATIC")
946         endif()
947         # Special handling of Windows platform where openjpeg is always static.
948         if(WIN32)
949                 set(OPENJPEG_DEFINES "-DOPJ_STATIC")
950         endif()
951 endif()
952
953 if(NOT WITH_SYSTEM_EIGEN3)
954         set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3)
955 endif()
956
957 #-----------------------------------------------------------------------------
958 # Configure OpenGL.
959
960 find_package(OpenGL)
961 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
962
963 if(WITH_SYSTEM_GLES)
964         find_package_wrapper(OpenGLES)
965 endif()
966
967 if(WITH_GL_PROFILE_COMPAT OR WITH_GL_PROFILE_CORE)
968         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_gl_LIBRARY}")
969
970 elseif(WITH_GL_PROFILE_ES20)
971         if(WITH_SYSTEM_GLES)
972                 if(NOT OPENGLES_LIBRARY)
973                         message(FATAL_ERROR
974                                 "Unable to find OpenGL ES libraries. "
975                                 "Install them or disable WITH_SYSTEM_GLES."
976                         )
977                 endif()
978
979                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_LIBRARY)
980
981         else()
982                 set(OPENGLES_LIBRARY "" CACHE FILEPATH "OpenGL ES 2.0 library file")
983                 mark_as_advanced(OPENGLES_LIBRARY)
984
985                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
986
987                 if(NOT OPENGLES_LIBRARY)
988                         message(FATAL_ERROR
989                                 "To compile WITH_GL_EGL you need to set OPENGLES_LIBRARY "
990                                 "to the file path of an OpenGL ES 2.0 library."
991                         )
992                 endif()
993
994         endif()
995
996         if(WIN32)
997                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
998
999                 set(OPENGLES_DLL "" CACHE FILEPATH "OpenGL ES 2.0 redistributable DLL file")
1000                 mark_as_advanced(OPENGLES_DLL)
1001
1002                 if(NOT OPENGLES_DLL)
1003                         message(FATAL_ERROR
1004                                 "To compile WITH_GL_PROFILE_ES20 you need to set OPENGLES_DLL to the file "
1005                                 "path of an OpenGL ES 2.0 runtime dynamic link library (DLL)."
1006                         )
1007                 endif()
1008
1009                 if(WITH_GL_ANGLE)
1010                         list(APPEND GL_DEFINITIONS -DWITH_ANGLE)
1011
1012                         set(D3DCOMPILER_DLL "" CACHE FILEPATH "Direct3D Compiler redistributable DLL file (needed by ANGLE)")
1013
1014                         get_filename_component(D3DCOMPILER_FILENAME "${D3DCOMPILER_DLL}" NAME)
1015                         list(APPEND GL_DEFINITIONS "-DD3DCOMPILER=\"\\\"${D3DCOMPILER_FILENAME}\\\"\"")
1016
1017                         mark_as_advanced(D3DCOMPILER_DLL)
1018
1019                         if(D3DCOMPILER_DLL STREQUAL "")
1020                                 message(FATAL_ERROR
1021                                         "To compile WITH_GL_ANGLE you need to set D3DCOMPILER_DLL to the file "
1022                                         "path of a copy of the DirectX redistributable DLL file: D3DCompiler_46.dll"
1023                                 )
1024                         endif()
1025
1026                 endif()
1027
1028         endif()
1029
1030 endif()
1031
1032 if(WITH_GL_EGL)
1033         list(APPEND GL_DEFINITIONS -DWITH_GL_EGL)
1034
1035         if(WITH_SYSTEM_GLES)
1036                 if(NOT OPENGLES_EGL_LIBRARY)
1037                         message(FATAL_ERROR
1038                                 "Unable to find OpenGL ES libraries. "
1039                                 "Install them or disable WITH_SYSTEM_GLES."
1040                         )
1041                 endif()
1042
1043                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_EGL_LIBRARY)
1044
1045         else()
1046                 set(OPENGLES_EGL_LIBRARY "" CACHE FILEPATH "EGL library file")
1047                 mark_as_advanced(OPENGLES_EGL_LIBRARY)
1048
1049                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}" "${OPENGLES_EGL_LIBRARY}")
1050
1051                 if(NOT OPENGLES_EGL_LIBRARY)
1052                         message(FATAL_ERROR
1053                                 "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY "
1054                                 "to the file path of an EGL library."
1055                         )
1056                 endif()
1057
1058         endif()
1059
1060         if(WIN32)
1061                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
1062
1063                 set(OPENGLES_EGL_DLL "" CACHE FILEPATH "EGL redistributable DLL file")
1064                 mark_as_advanced(OPENGLES_EGL_DLL)
1065
1066                 if(NOT OPENGLES_EGL_DLL)
1067                         message(FATAL_ERROR
1068                                 "To compile WITH_GL_EGL you need to set OPENGLES_EGL_DLL "
1069                                 "to the file path of an EGL runtime dynamic link library (DLL)."
1070                         )
1071                 endif()
1072
1073         endif()
1074
1075 endif()
1076
1077 if(WITH_LEGACY_OPENGL)
1078         list(APPEND GL_DEFINITIONS -DWITH_LEGACY_OPENGL)
1079 endif()
1080
1081 if(WITH_GL_PROFILE_COMPAT)
1082         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_COMPAT)
1083 endif()
1084
1085 if(WITH_GL_PROFILE_CORE)
1086         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_CORE)
1087 endif()
1088
1089 if(WITH_GL_PROFILE_ES20)
1090         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_ES20)
1091 endif()
1092
1093 if(WITH_GL_EGL)
1094         list(APPEND GL_DEFINITIONS -DWITH_EGL)
1095 endif()
1096
1097 #-----------------------------------------------------------------------------
1098 # Configure OpenMP.
1099 if(WITH_OPENMP)
1100         find_package(OpenMP)
1101         if(OPENMP_FOUND)
1102                 if(NOT WITH_OPENMP_STATIC)
1103                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1104                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1105                 else()
1106                         # Typically avoid adding flags as defines but we can't
1107                         # pass OpenMP flags to the linker for static builds, meaning
1108                         # we can't add any OpenMP related flags to CFLAGS variables
1109                         # since they're passed to the linker as well.
1110                         add_definitions("${OpenMP_C_FLAGS}")
1111
1112                         find_library_static(OpenMP_LIBRARIES gomp ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
1113                 endif()
1114         else()
1115                 set(WITH_OPENMP OFF)
1116         endif()
1117
1118         mark_as_advanced(
1119                 OpenMP_C_FLAGS
1120                 OpenMP_CXX_FLAGS
1121         )
1122 endif()
1123
1124 #-----------------------------------------------------------------------------
1125 # Configure GLEW
1126
1127 if(WITH_SYSTEM_GLEW)
1128         find_package(GLEW)
1129
1130         # Note: There is an assumption here that the system GLEW is not a static library.
1131
1132         if(NOT GLEW_FOUND)
1133                 message(FATAL_ERROR "GLEW is required to build Blender. Install it or disable WITH_SYSTEM_GLEW.")
1134         endif()
1135
1136         set(BLENDER_GLEW_LIBRARIES ${GLEW_LIBRARY})
1137 else()
1138         if(WITH_GLEW_ES)
1139                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew-es/include")
1140
1141                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC -DWITH_GLEW_ES)
1142
1143                 # These definitions remove APIs from glew.h, making GLEW smaller, and catching unguarded API usage
1144                 if(NOT WITH_GL_PROFILE_ES20)
1145                         # No ES functions are needed
1146                         list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
1147                 elseif(NOT (WITH_GL_PROFILE_CORE OR WITH_GL_PROFILE_COMPAT))
1148                         # ES is enabled, but the other functions are all disabled
1149                         list(APPEND GL_DEFINITIONS -DGLEW_ES_ONLY)
1150                 endif()
1151
1152                 if(WITH_GL_PROFILE_ES20)
1153                         if(WITH_GL_EGL)
1154                                 list(APPEND GL_DEFINITIONS -DGLEW_USE_LIB_ES20)
1155                         endif()
1156
1157                         # ToDo: This is an experiment to eliminate ES 1 symbols,
1158                         # GLEW doesn't really properly provide this level of control
1159                         # (for example, without modification it eliminates too many symbols)
1160                         # so there are lots of modifications to GLEW to make this work,
1161                         # and no attempt to make it work beyond Blender at this point.
1162                         list(APPEND GL_DEFINITIONS -DGL_ES_VERSION_1_0=0 -DGL_ES_VERSION_CL_1_1=0 -DGL_ES_VERSION_CM_1_1=0)
1163                 endif()
1164
1165                 if(WITH_GL_EGL)
1166                         list(APPEND GL_DEFINITIONS -DGLEW_INC_EGL)
1167                 endif()
1168
1169                 set(BLENDER_GLEW_LIBRARIES extern_glew_es bf_intern_glew_mx)
1170
1171         else()
1172                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1173
1174                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC)
1175
1176                 # This won't affect the non-experimental glew library, 
1177                 # but is used for conditional compilation elsewhere.
1178                 list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
1179
1180                 set(BLENDER_GLEW_LIBRARIES extern_glew)
1181
1182         endif()
1183
1184 endif()
1185
1186 list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
1187
1188 #-----------------------------------------------------------------------------
1189 # Configure Bullet
1190
1191 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
1192         find_package(Bullet)
1193         if(NOT BULLET_FOUND)
1194                 set(WITH_BULLET OFF)
1195         endif()
1196 else()
1197         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
1198         # set(BULLET_LIBRARIES "")
1199 endif()
1200
1201 #-----------------------------------------------------------------------------
1202 # Configure Python.
1203
1204 if(WITH_PYTHON_MODULE)
1205         add_definitions(-DPy_ENABLE_SHARED)
1206 endif()
1207
1208 #-----------------------------------------------------------------------------
1209 # Configure GLog/GFlags
1210
1211 if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING))
1212         if(WITH_SYSTEM_GFLAGS)
1213                 find_package(Gflags)
1214                 if(NOT GFLAGS_FOUND)
1215                         message(FATAL_ERROR "System wide Gflags is requested but was not found")
1216                 endif()
1217                 # FindGflags does not define this, and we are not even sure what to use here.
1218                 set(GFLAGS_DEFINES)
1219         else()
1220                 set(GFLAGS_DEFINES
1221                         -DGFLAGS_DLL_DEFINE_FLAG=
1222                         -DGFLAGS_DLL_DECLARE_FLAG=
1223                         -DGFLAGS_DLL_DECL=
1224                 )
1225                 set(GFLAGS_NAMESPACE "gflags")
1226                 set(GFLAGS_LIBRARIES extern_gflags)
1227                 set(GFLAGS_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/extern/gflags/src")
1228         endif()
1229
1230         if(WITH_SYSTEM_GLOG)
1231                 find_package(Glog)
1232                 if(NOT GLOG_FOUND)
1233                         message(FATAL_ERROR "System wide Glog is requested but was not found")
1234                 endif()
1235                 # FindGlog does not define this, and we are not even sure what to use here.
1236                 set(GLOG_DEFINES)
1237         else()
1238                 set(GLOG_DEFINES
1239                         -DGOOGLE_GLOG_DLL_DECL=
1240                 )
1241                 set(GLOG_LIBRARIES extern_glog)
1242                 if(WIN32)
1243                         set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/src/windows)
1244                 else()
1245                         set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/src)
1246                 endif()
1247         endif()
1248 endif()
1249
1250 #-----------------------------------------------------------------------------
1251 # Configure Ceres
1252
1253 if(WITH_LIBMV)
1254         set(CERES_DEFINES)
1255
1256         if(WITH_CXX11)
1257                 # nothing to be done
1258         elseif(SHARED_PTR_FOUND)
1259                 if(SHARED_PTR_TR1_MEMORY_HEADER)
1260                         list(APPEND CERES_DEFINES -DCERES_TR1_MEMORY_HEADER)
1261                 endif()
1262                 if(SHARED_PTR_TR1_NAMESPACE)
1263                         list(APPEND CERES_DEFINES -DCERES_TR1_SHARED_PTR)
1264                 endif()
1265         else()
1266                 message(FATAL_ERROR "Ceres: Unable to find shared_ptr.")
1267         endif()
1268
1269         if(WITH_CXX11)
1270                 list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP)
1271         elseif(HAVE_STD_UNORDERED_MAP_HEADER)
1272                 if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
1273                         list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP)
1274                 else()
1275                         if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
1276                                 list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
1277                         else()
1278                                 list(APPEND CERES_DEFINES -DCERES_NO_UNORDERED_MAP)
1279                                 message(STATUS "Ceres: Replacing unordered_map/set with map/set (warning: slower!)")
1280                         endif()
1281                 endif()
1282         else()
1283                 if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
1284                         list(APPEND CERES_DEFINES -DCERES_TR1_UNORDERED_MAP)
1285                 else()
1286                         list(APPEND CERES_DEFINES -DCERES_NO_UNORDERED_MAP)
1287                         message(STATUS "Ceres: Replacing unordered_map/set with map/set (warning: slower!)")
1288                 endif()
1289         endif()
1290 endif()
1291
1292 #-----------------------------------------------------------------------------
1293 # Extra compile flags
1294
1295 if(CMAKE_COMPILER_IS_GNUCC)
1296
1297         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1298         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1299         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1300         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1301         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_VLA -Werror=vla)
1302         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1303         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1304         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1305         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1306         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1307         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1308         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1309         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1310         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
1311         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
1312         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1313         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
1314         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1315         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1316         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
1317         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_FORMAT_SIGN -Wformat-signedness)
1318
1319         # gcc 4.2 gives annoying warnings on every file with this
1320         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1321                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
1322         endif()
1323
1324         # versions before gcc4.6 give many BLI_math warnings
1325         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
1326                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
1327                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
1328         endif()
1329
1330         # versions before gcc4.8 include global name-space.
1331         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.8")
1332                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_SHADOW -Wshadow)
1333         endif()
1334
1335         # disable because it gives warnings for printf() & friends.
1336         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1337
1338         if(NOT APPLE)
1339                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1340         endif()
1341
1342         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1343         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1344         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1345         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
1346         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1347         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1348         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1349         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
1350         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1351         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1352         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1353         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1354         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_POINTER_ARITH -Wpointer-arith)
1355         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_PARAMETER -Wunused-parameter)
1356         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_WRITE_STRINGS -Wwrite-strings)
1357         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1358         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_FORMAT_SIGN -Wformat-signedness)
1359
1360         # gcc 4.2 gives annoying warnings on every file with this
1361         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1362                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
1363         endif()
1364
1365         # causes too many warnings
1366         if(NOT APPLE)
1367                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1368                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
1369         endif()
1370
1371         # flags to undo strict flags
1372         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
1373         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
1374
1375         if(NOT APPLE)
1376                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1377         endif()
1378
1379 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
1380
1381         if(APPLE AND WITH_OPENMP) # we need the Intel omp lib linked here to not fail all tests due presence of -fopenmp !
1382                 set(CMAKE_REQUIRED_FLAGS "-L${LIBDIR}/openmp/lib -liomp5") # these are only used for the checks
1383         endif()
1384
1385         # strange, clang complains these are not supported, but then yses them.
1386         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1387         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1388         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1389         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1390         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1391         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1392         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1393         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1394         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1395
1396         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1397         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1398         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
1399         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
1400         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.
1401         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
1402         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
1403
1404         # gives too many unfixable warnings
1405         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
1406         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
1407
1408         # flags to undo strict flags
1409         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
1410         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
1411
1412         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
1413         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
1414         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
1415         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
1416         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
1417         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
1418         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
1419         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
1420
1421         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
1422         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
1423         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
1424         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
1425         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
1426
1427 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1428
1429         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1430         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1431         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1432
1433         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1434         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1435         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1436
1437         # disable numbered, false positives
1438         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
1439         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
1440 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
1441         # most msvc warnings are C & C++
1442         set(_WARNINGS
1443                 # warning level:
1444                 "/W3"
1445                 "/w34062"  # switch statement contains 'default' but no 'case' labels
1446                 # disable:
1447                 "/wd4018"  # signed/unsigned mismatch
1448                 "/wd4146"  # unary minus operator applied to unsigned type, result still unsigned
1449                 "/wd4065"  # switch statement contains 'default' but no 'case' labels
1450                 "/wd4127"  # conditional expression is constant
1451                 "/wd4181"  # qualifier applied to reference type; ignored
1452                 "/wd4200"  # zero-sized array in struct/union
1453                 "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
1454                 "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
1455                 "/wd4305"  # truncation from 'type1' to 'type2'
1456                 "/wd4800"  # forcing value to bool 'true' or 'false'
1457                 # errors:
1458                 "/we4013"  # 'function' undefined; assuming extern returning int
1459                 "/we4431"  # missing type specifier - int assumed
1460         )
1461
1462         string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
1463         set(C_WARNINGS "${_WARNINGS}")
1464         set(CXX_WARNINGS "${_WARNINGS}")
1465         unset(_WARNINGS)
1466 endif()
1467
1468 # ensure python header is found since detection can fail, this could happen
1469 # with _any_ library but since we used a fixed python version this tends to
1470 # be most problematic.
1471 if(WITH_PYTHON)
1472         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1473                 message(FATAL_ERROR
1474                         "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1475                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1476                         "to a valid python include path. Containing "
1477                         "Python.h for python version \"${PYTHON_VERSION}\""
1478                 )
1479         endif()
1480
1481         if(WIN32 OR APPLE)
1482                 # pass, we have this in an archive to extract
1483         elseif(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
1484                 find_python_package(numpy)
1485         endif()
1486
1487         if(WIN32 OR APPLE)
1488                 # pass, we have this in lib/python/site-packages
1489         elseif(WITH_PYTHON_INSTALL_REQUESTS)
1490                 find_python_package(requests)
1491         endif()
1492 endif()
1493
1494 if(WITH_CXX11)
1495         if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
1496                 # TODO(sergey): Do we want c++11 or gnu-c++11 here?
1497                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
1498         elseif(MSVC)
1499                 # Nothing special is needed, C++11 features are available by default.
1500         else()
1501                 message(FATAL_ERROR "Compiler ${CMAKE_C_COMPILER_ID} is not supported for C++11 build yet")
1502         endif()
1503 else()
1504         # GCC-6 switched to C++11 by default, which would break linking with existing libraries
1505         # by default. So we explicitly disable C++11 for a new GCC so no linking issues happens.
1506         if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0"))
1507                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++98")
1508                 # We also disable any of C++11 ABI from usage, so we wouldn't even try to
1509                 # link to stuff from std::__cxx11 namespace.
1510                 add_definitions("-D_GLIBCXX_USE_CXX11_ABI=0")
1511         endif()
1512 endif()
1513
1514 # Visual Studio has all standards it supports available by default
1515 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "Intel")
1516         # Use C99 + GNU extensions, works with GCC, Clang, ICC
1517         if(WITH_C11)
1518                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
1519         else()
1520                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
1521         endif()
1522 endif()
1523
1524 # Include warnings first, so its possible to disable them with user defined flags
1525 # eg: -Wno-uninitialized
1526 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
1527 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
1528
1529 # defined above, platform specific but shared names
1530 mark_as_advanced(
1531         CYCLES_OSL
1532         OSL_LIB_EXEC
1533         OSL_COMPILER
1534         OSL_LIB_COMP
1535         OSL_LIB_QUERY
1536         OSL_INCLUDE_DIR
1537 )
1538
1539 mark_as_advanced(
1540         LLVM_CONFIG
1541         LLVM_ROOT_DIR
1542         LLVM_LIBRARY
1543         LLVM_VERSION
1544 )
1545
1546 #-------------------------------------------------------------------------------
1547 # Global Defines
1548
1549 # better not set includes here but this debugging option is off by default.
1550 if(WITH_CXX_GUARDEDALLOC)
1551         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1552         add_definitions(-DWITH_CXX_GUARDEDALLOC)
1553 endif()
1554
1555 if(WITH_ASSERT_ABORT)
1556         add_definitions(-DWITH_ASSERT_ABORT)
1557 endif()
1558
1559 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1560 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1561
1562 #-----------------------------------------------------------------------------
1563 # Libraries
1564
1565 if(WITH_GTESTS)
1566         include(GTestTesting)
1567 endif()
1568
1569 if(WITH_BLENDER OR WITH_PLAYER)
1570         add_subdirectory(intern)
1571         add_subdirectory(extern)
1572
1573         # source after intern and extern to gather all
1574         # internal and external library information first, for test linking
1575         add_subdirectory(source)
1576 elseif(WITH_CYCLES_STANDALONE)
1577         add_subdirectory(intern/cycles)
1578         add_subdirectory(extern/clew)
1579         if(WITH_CUDA_DYNLOAD)
1580                 add_subdirectory(extern/cuew)
1581         endif()
1582         if(NOT WITH_SYSTEM_GLEW)
1583                 add_subdirectory(extern/glew)
1584         endif()
1585 endif()
1586
1587 #-----------------------------------------------------------------------------
1588 # Blender Application
1589 if(WITH_BLENDER)
1590         add_subdirectory(source/creator)
1591 endif()
1592
1593
1594 #-----------------------------------------------------------------------------
1595 # Blender Player
1596 if(WITH_PLAYER)
1597         add_subdirectory(source/blenderplayer)
1598 endif()
1599
1600
1601 #-----------------------------------------------------------------------------
1602 # Testing
1603 add_subdirectory(tests)
1604
1605
1606 #-----------------------------------------------------------------------------
1607 # CPack for generating packages
1608 include(build_files/cmake/packaging.cmake)
1609
1610 #-----------------------------------------------------------------------------
1611 # Use dynamic loading for OpenMP
1612 if(WITH_BLENDER)
1613         openmp_delayload(blender)
1614 endif(WITH_BLENDER)
1615 if(WITH_PLAYER)
1616         openmp_delayload(blenderplayer)
1617 endif(WITH_PLAYER)
1618
1619 #-----------------------------------------------------------------------------
1620 # Print Final Configuration
1621
1622 if(FIRST_RUN)
1623
1624         set(_config_msg "\nBlender Configuration\n=====================")
1625
1626         function(info_cfg_option
1627                 _setting
1628                 )
1629
1630                 set(_msg "  - ${_setting}")
1631                 string(LENGTH "${_msg}" _len)
1632                 while("32" GREATER "${_len}")
1633                         set(_msg "${_msg} ")
1634                         math(EXPR _len "${_len} + 1")
1635                 endwhile()
1636
1637                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
1638         endfunction()
1639
1640         function(info_cfg_text
1641                 _text
1642                 )
1643
1644                 set(_config_msg "${_config_msg}\n\n  ${_text}" PARENT_SCOPE)
1645         endfunction()
1646
1647         message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
1648         message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
1649
1650         info_cfg_text("Build Options:")
1651         info_cfg_option(WITH_GAMEENGINE)
1652         info_cfg_option(WITH_PLAYER)
1653         info_cfg_option(WITH_BULLET)
1654         info_cfg_option(WITH_IK_SOLVER)
1655         info_cfg_option(WITH_IK_ITASC)
1656         info_cfg_option(WITH_OPENCOLLADA)
1657         info_cfg_option(WITH_FFTW3)
1658         info_cfg_option(WITH_INTERNATIONAL)
1659         info_cfg_option(WITH_INPUT_NDOF)
1660         info_cfg_option(WITH_CYCLES)
1661         info_cfg_option(WITH_FREESTYLE)
1662         info_cfg_option(WITH_OPENCOLORIO)
1663         info_cfg_option(WITH_OPENVDB)
1664         info_cfg_option(WITH_ALEMBIC)
1665
1666         info_cfg_text("Compiler Options:")
1667         info_cfg_option(WITH_BUILDINFO)
1668         info_cfg_option(WITH_OPENMP)
1669         info_cfg_option(WITH_RAYOPTIMIZATION)
1670
1671         info_cfg_text("System Options:")
1672         info_cfg_option(WITH_INSTALL_PORTABLE)
1673         info_cfg_option(WITH_X11_ALPHA)
1674         info_cfg_option(WITH_X11_XF86VMODE)
1675         info_cfg_option(WITH_X11_XINPUT)
1676         info_cfg_option(WITH_MEM_JEMALLOC)
1677         info_cfg_option(WITH_MEM_VALGRIND)
1678         info_cfg_option(WITH_SYSTEM_GLEW)
1679         info_cfg_option(WITH_SYSTEM_OPENJPEG)
1680
1681         info_cfg_text("Image Formats:")
1682         info_cfg_option(WITH_OPENIMAGEIO)
1683         info_cfg_option(WITH_IMAGE_CINEON)
1684         info_cfg_option(WITH_IMAGE_DDS)
1685         info_cfg_option(WITH_IMAGE_HDR)
1686         info_cfg_option(WITH_IMAGE_OPENEXR)
1687         info_cfg_option(WITH_IMAGE_OPENJPEG)
1688         info_cfg_option(WITH_IMAGE_TIFF)
1689
1690         info_cfg_text("Audio:")
1691         info_cfg_option(WITH_OPENAL)
1692         info_cfg_option(WITH_SDL)
1693         info_cfg_option(WITH_SDL_DYNLOAD)
1694         info_cfg_option(WITH_JACK)
1695         info_cfg_option(WITH_JACK_DYNLOAD)
1696         info_cfg_option(WITH_CODEC_AVI)
1697         info_cfg_option(WITH_CODEC_FFMPEG)
1698         info_cfg_option(WITH_CODEC_SNDFILE)
1699
1700         info_cfg_text("Compression:")
1701         info_cfg_option(WITH_LZMA)
1702         info_cfg_option(WITH_LZO)
1703
1704         info_cfg_text("Python:")
1705         info_cfg_option(WITH_PYTHON_INSTALL)
1706         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
1707         info_cfg_option(WITH_PYTHON_MODULE)
1708         info_cfg_option(WITH_PYTHON_SAFETY)
1709         if(APPLE)
1710                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
1711         endif()
1712
1713         info_cfg_text("Modifiers:")
1714         info_cfg_option(WITH_MOD_BOOLEAN)
1715         info_cfg_option(WITH_MOD_REMESH)
1716         info_cfg_option(WITH_MOD_FLUID)
1717         info_cfg_option(WITH_MOD_OCEANSIM)
1718
1719         info_cfg_text("OpenGL:")
1720         info_cfg_option(WITH_GLEW_ES)
1721         info_cfg_option(WITH_GL_EGL)
1722         info_cfg_option(WITH_GL_PROFILE_COMPAT)
1723         info_cfg_option(WITH_GL_PROFILE_CORE)
1724         info_cfg_option(WITH_GL_PROFILE_ES20)
1725         if(WIN32)
1726                 info_cfg_option(WITH_GL_ANGLE)
1727         endif()
1728
1729         info_cfg_text("")
1730
1731         message("${_config_msg}")
1732 endif()
1733
1734 if(0)
1735         print_all_vars()
1736 endif()
1737