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