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