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