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