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