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