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 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 option(WITH_CLAY_ENGINE    "Enable Clay engine" ON)
248
249 # Compositor
250 option(WITH_COMPOSITOR         "Enable the tile based nodal compositor" ON)
251
252 option(WITH_OPENSUBDIV    "Enable OpenSubdiv for surface subdivision" _init_OPENSUBDIV)
253
254 option(WITH_OPENVDB       "Enable features relying on OpenVDB" OFF)
255 option(WITH_OPENVDB_BLOSC "Enable blosc compression for OpenVDB, only enable if OpenVDB was built with blosc support" OFF)
256
257 # GHOST Windowing Library Options
258 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
259 mark_as_advanced(WITH_GHOST_DEBUG)
260
261 option(WITH_GHOST_SDL    "Enable building Blender against SDL for windowing rather than the native APIs" OFF)
262 mark_as_advanced(WITH_GHOST_SDL)
263
264 if(WITH_X11)
265         option(WITH_GHOST_XDND    "Enable drag'n'drop support on X11 using XDND protocol" ON)
266 endif()
267
268 # Misc...
269 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
270 mark_as_advanced(WITH_HEADLESS)
271
272 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
273 option(WITH_SYSTEM_AUDASPACE "Build with external audaspace library installed on the system (only enable if you know what you're doing!)" OFF)
274 mark_as_advanced(WITH_AUDASPACE)
275 mark_as_advanced(WITH_SYSTEM_AUDASPACE)
276
277 if(NOT WITH_AUDASPACE)
278         set(WITH_SYSTEM_AUDASPACE OFF)
279 endif()
280
281 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
282 if(UNIX AND NOT APPLE)
283         option(WITH_OPENMP_STATIC "Link OpenMP statically (only used by the release environment)" OFF)
284         mark_as_advanced(WITH_OPENMP_STATIC)
285 endif()
286
287 if(WITH_X11)
288         option(WITH_X11_XINPUT    "Enable X11 Xinput (tablet support and unicode input)"  ON)
289         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"                       ON)
290         option(WITH_X11_XFIXES    "Enable X11 XWayland cursor warping workaround"         ON)
291         option(WITH_X11_ALPHA     "Enable X11 transparent background"                     ON)
292 endif()
293
294 if(UNIX AND NOT APPLE)
295         option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" OFF)
296         option(WITH_SYSTEM_GLES "Use OpenGL ES library provided by the operating system"           ON)
297 else()
298         # not an option for other OS's
299         set(WITH_SYSTEM_GLEW OFF)
300         set(WITH_SYSTEM_GLES OFF)
301 endif()
302
303
304 # (unix defaults to System OpenJPEG On)
305 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" OFF)
306
307 if(UNIX AND NOT APPLE)
308         option(WITH_SYSTEM_EIGEN3 "Use the systems Eigen3 library" OFF)
309 endif()
310
311
312 # Modifiers
313 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
314 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
315 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
316 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
317 # option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)  # this is now only available in a branch
318 # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
319 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
320
321 # Image format support
322 option(WITH_OPENIMAGEIO         "Enable OpenImageIO Support (http://www.openimageio.org)" ON)
323 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ${_init_IMAGE_OPENEXR})
324 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
325 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
326 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
327 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
328 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
329 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
330
331 # Audio/Video format support
332 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
333 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ${_init_CODEC_FFMPEG})
334 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
335
336 # Alembic support
337 option(WITH_ALEMBIC             "Enable Alembic Support" OFF)
338 option(WITH_ALEMBIC_HDF5        "Enable Legacy Alembic Support (not officially supported)" OFF)
339
340 # 3D format support
341 # Disable opencollada when we don't have precompiled libs
342 option(WITH_OPENCOLLADA   "Enable OpenCollada Support (http://www.opencollada.org)" ${_init_OPENCOLLADA})
343
344 # Sound output
345 option(WITH_SDL           "Enable SDL for sound and joystick support" ${_init_SDL})
346 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
347 option(WITH_JACK          "Enable JACK Support (http://www.jackaudio.org)" ${_init_JACK})
348 if(UNIX AND NOT APPLE)
349         option(WITH_JACK_DYNLOAD  "Enable runtime dynamic JACK libraries loading" OFF)
350 endif()
351 if(UNIX AND NOT APPLE)
352         option(WITH_SDL_DYNLOAD  "Enable runtime dynamic SDL libraries loading" OFF)
353 endif()
354
355 # Compression
356 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
357 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
358 if(UNIX AND NOT APPLE)
359         option(WITH_SYSTEM_LZO    "Use the system LZO library" OFF)
360 endif()
361
362 # Camera/motion tracking
363 option(WITH_LIBMV         "Enable Libmv structure from motion library" ON)
364 option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." OFF)
365 mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
366
367 # Logging/unbit test libraries.
368 option(WITH_SYSTEM_GFLAGS   "Use system-wide Gflags instead of a bundled one" OFF)
369 option(WITH_SYSTEM_GLOG     "Use system-wide Glog instead of a bundled one" OFF)
370 mark_as_advanced(WITH_SYSTEM_GFLAGS)
371 mark_as_advanced(WITH_SYSTEM_GLOG)
372
373 # Freestyle
374 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
375
376 # Misc
377 if(WIN32)
378         option(WITH_INPUT_IME "Enable Input Method Editor (IME) for complex Asian character input" ON)
379 endif()
380 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ${_init_INPUT_NDOF})
381 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
382 if(UNIX AND NOT APPLE)
383         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
384         option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
385         if(WITH_STATIC_LIBS)
386                 option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
387                 mark_as_advanced(WITH_BOOST_ICU)
388         endif()
389 endif()
390
391 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
392 if(WITH_PYTHON_INSTALL OR (WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE))
393         set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
394         mark_as_advanced(PYTHON_NUMPY_PATH)
395         set(PYTHON_NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_PATH}/numpy/core/include CACHE PATH "Path to the include directory of the numpy module")
396         mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIRS)
397 endif()
398 if(WITH_PYTHON_INSTALL)
399         option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
400
401         if(UNIX AND NOT APPLE)
402                 option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
403                 set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
404                 mark_as_advanced(PYTHON_REQUESTS_PATH)
405         endif()
406 endif()
407
408 option(WITH_CPU_SSE              "Enable SIMD instruction if they're detected on the host machine" ON)
409 mark_as_advanced(WITH_CPU_SSE)
410
411 # Cycles
412 option(WITH_CYCLES                                      "Enable Cycles Render Engine" ON)
413 option(WITH_CYCLES_STANDALONE           "Build Cycles standalone application" OFF)
414 option(WITH_CYCLES_STANDALONE_GUI       "Build Cycles standalone with GUI" OFF)
415 option(WITH_CYCLES_OSL                          "Build Cycles with OSL support" ${_init_CYCLES_OSL})
416 option(WITH_CYCLES_OPENSUBDIV           "Build Cycles with OpenSubdiv support" ${_init_CYCLES_OPENSUBDIV})
417 option(WITH_CYCLES_CUDA_BINARIES        "Build Cycles CUDA binaries" OFF)
418 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")
419 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
420 unset(PLATFORM_DEFAULT)
421 option(WITH_CYCLES_LOGGING      "Build Cycles with logging support" ON)
422 option(WITH_CYCLES_DEBUG        "Build Cycles with extra debug capabilities" OFF)
423 option(WITH_CYCLES_NATIVE_ONLY  "Build Cycles with native kernel only (which fits current CPU, use for development only)" OFF)
424 mark_as_advanced(WITH_CYCLES_LOGGING)
425 mark_as_advanced(WITH_CYCLES_DEBUG)
426 mark_as_advanced(WITH_CYCLES_NATIVE_ONLY)
427
428 option(WITH_CUDA_DYNLOAD "Dynamically load CUDA libraries at runtime" ON)
429 mark_as_advanced(WITH_CUDA_DYNLOAD)
430
431 # LLVM
432 option(WITH_LLVM                                        "Use LLVM" OFF)
433 if(APPLE)
434         option(LLVM_STATIC                                      "Link with LLVM static libraries" ON) # we prefer static llvm build on Apple, dyn build possible though
435 else()
436         option(LLVM_STATIC                                      "Link with LLVM static libraries" OFF)
437 endif()
438 mark_as_advanced(LLVM_STATIC)
439
440 # disable for now, but plan to support on all platforms eventually
441 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" ON)
442 mark_as_advanced(WITH_MEM_JEMALLOC)
443
444 # currently only used for BLI_mempool
445 option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
446 mark_as_advanced(WITH_MEM_VALGRIND)
447
448 # Debug
449 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
450 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
451
452 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
453 mark_as_advanced(WITH_ASSERT_ABORT)
454
455 option(WITH_BOOST                                       "Enable features depending on boost" ON)
456
457 # Unit testsing
458 option(WITH_GTESTS "Enable GTest unit testing" OFF)
459 option(WITH_OPENGL_TESTS "Enable OpenGL related unit testing (Experimental)" OFF)
460
461
462 # Documentation
463 if(UNIX AND NOT APPLE)
464         option(WITH_DOC_MANPAGE "Create a manual page (Unix manpage)" OFF)
465 endif()
466
467
468 # OpenGL
469
470 option(WITH_GLEW_ES             "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
471 option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)"       OFF)
472 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (thru either EGL or the AGL/WGL/XGL 'es20' profile)"                                  OFF)
473
474 mark_as_advanced(
475         WITH_GLEW_ES
476         WITH_GL_EGL
477         WITH_GL_PROFILE_ES20
478 )
479
480 if(WIN32)
481         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)
482         mark_as_advanced(WITH_GL_ANGLE)
483 endif()
484
485 if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
486         message(WARNING Ignoring WITH_SYSTEM_GLEW and using WITH_GLEW_ES)
487         set(WITH_SYSTEM_GLEW OFF)
488 endif()
489
490 if(WIN32)
491         getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
492         set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
493 endif()
494
495 # Experimental support of C11 and C++11
496 #
497 # We default options to whatever default standard in the current compiler.
498 if(APPLE)
499         set(_c11_init ON)
500         set(_cxx11_init ON)
501         set(WITH_C11 ON)
502         set(WITH_CXX11 ON)
503 elseif(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0") AND (NOT WITH_CXX11))
504         set(_c11_init ON)
505 else()
506         set(_c11_init OFF)
507 endif()
508 set(_cxx11_init ON)
509
510 option(WITH_C11 "Build with C11 standard enabled, for development use only!" ${_c11_init})
511 mark_as_advanced(WITH_C11)
512 option(WITH_CXX11 "Build with C++11 standard enabled, for development use only!" ${_cxx11_init})
513 mark_as_advanced(WITH_CXX11)
514
515 # Compiler toolchain
516 if(CMAKE_COMPILER_IS_GNUCC)
517         option(WITH_LINKER_GOLD "Use ld.gold linker which is usually faster than ld.bfd" ON)
518         mark_as_advanced(WITH_LINKER_GOLD)
519 endif()
520
521 if(WIN32)
522         # Use hardcoded paths or find_package to find externals
523         option(WITH_WINDOWS_FIND_MODULES "Use find_package to locate libraries" OFF)
524         mark_as_advanced(WITH_WINDOWS_FIND_MODULES)
525
526         option(WITH_WINDOWS_CODESIGN "Use signtool to sign the final binary." OFF)
527         mark_as_advanced(WITH_WINDOWS_CODESIGN)
528
529         set(WINDOWS_CODESIGN_PFX CACHE FILEPATH  "Path to pfx file to use for codesigning.")
530         mark_as_advanced(WINDOWS_CODESIGN_PFX)
531
532         set(WINDOWS_CODESIGN_PFX_PASSWORD CACHE STRING  "password for pfx file used for codesigning.")
533         mark_as_advanced(WINDOWS_CODESIGN_PFX_PASSWORD)
534 endif()
535
536 # avoid using again
537 option_defaults_clear()
538
539 # end option(...)
540
541
542
543 # By default we want to install to the directory we are compiling our executables
544 # unless specified otherwise, which we currently do not allow
545 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
546         if(WIN32)
547                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
548         elseif(APPLE)
549                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
550         else()
551                 if(WITH_INSTALL_PORTABLE)
552                         set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH} CACHE PATH "default install path" FORCE)
553                 endif()
554         endif()
555 endif()
556
557
558
559 # Apple
560
561 if(APPLE)
562         include(platform_apple_xcode)
563 endif()
564
565
566 #-----------------------------------------------------------------------------
567 # Check for conflicting/unsupported configurations
568
569 if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_STANDALONE)
570         message(FATAL_ERROR
571                 "At least one of WITH_BLENDER or WITH_PLAYER or "
572                 "WITH_CYCLES_STANDALONE must be enabled, nothing to do!"
573         )
574 endif()
575
576 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
577         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
578 endif()
579
580 if(NOT WITH_CXX11)
581         if(WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE)
582                 message(FATAL_ERROR "WITH_AUDASPACE requires WITH_CXX11")
583         endif()
584 endif()
585
586 if(NOT WITH_AUDASPACE)
587         if(WITH_OPENAL)
588                 message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
589         endif()
590         if(WITH_JACK)
591                 message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
592         endif()
593         if(WITH_GAMEENGINE)
594                 message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
595         endif()
596 endif()
597
598 if(NOT WITH_SDL AND WITH_GHOST_SDL)
599         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
600 endif()
601
602 # python module, needs some different options
603 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
604         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
605 endif()
606
607 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
608         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
609 endif()
610
611
612 # may as well build python module without a UI
613 if(WITH_PYTHON_MODULE)
614         set(WITH_HEADLESS ON)
615 endif()
616
617 if(NOT WITH_PYTHON)
618         set(WITH_CYCLES OFF)
619 endif()
620
621 # enable boost for cycles, audaspace or i18n
622 # otherwise if the user disabled
623 if(NOT WITH_BOOST)
624         # Explicitly disabled. so disable all deps.
625         macro(set_and_warn
626                 _setting _val)
627                 if(${${_setting}})
628                         message(STATUS "'WITH_BOOST' is disabled: forcing 'set(${_setting} ${_val})'")
629                 endif()
630                 set(${_setting} ${_val})
631         endmacro()
632
633         set_and_warn(WITH_CYCLES         OFF)
634         set_and_warn(WITH_INTERNATIONAL  OFF)
635         set_and_warn(WITH_OPENVDB        OFF)
636         set_and_warn(WITH_OPENCOLORIO    OFF)
637         set_and_warn(WITH_MOD_BOOLEAN    OFF)
638 elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_INTERNATIONAL OR
639        WITH_OPENVDB OR WITH_OPENCOLORIO OR WITH_MOD_BOOLEAN)
640         # Keep enabled
641 else()
642         # New dependency graph needs either Boost or C++11 for function bindings.
643         if(NOT WITH_CXX11)
644                 # Enabled but we don't need it
645                 set(WITH_BOOST OFF)
646         endif()
647 endif()
648
649 # auto enable openimageio for cycles
650 if(WITH_CYCLES)
651         set(WITH_OPENIMAGEIO ON)
652
653         # auto enable llvm for cycles_osl
654         if(WITH_CYCLES_OSL)
655                 set(WITH_LLVM ON CACHE BOOL "" FORCE)
656         endif()
657 else()
658         set(WITH_CYCLES_OSL OFF)
659 endif()
660
661 # auto enable openimageio linking dependencies
662 if(WITH_OPENIMAGEIO)
663         set(WITH_IMAGE_OPENEXR ON)
664         set(WITH_IMAGE_TIFF ON)
665 endif()
666
667 # auto enable alembic linking dependencies
668 if(WITH_ALEMBIC)
669         set(WITH_IMAGE_OPENEXR ON)
670 endif()
671
672 # don't store paths to libs for portable distribution
673 if(WITH_INSTALL_PORTABLE)
674         set(CMAKE_SKIP_BUILD_RPATH TRUE)
675 endif()
676
677 if(WITH_GHOST_SDL OR WITH_HEADLESS)
678         set(WITH_X11           OFF)
679         set(WITH_X11_XINPUT    OFF)
680         set(WITH_X11_XF86VMODE OFF)
681         set(WITH_X11_XFIXES    OFF)
682         set(WITH_X11_ALPHA     OFF)
683         set(WITH_GHOST_XDND    OFF)
684         set(WITH_INPUT_IME     OFF)
685 endif()
686
687 if(WITH_CPU_SSE)
688         TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
689 else()
690         message(STATUS "SSE and SSE2 optimizations are DISABLED!")
691         set(COMPILER_SSE_FLAG)
692         set(COMPILER_SSE2_FLAG)
693 endif()
694
695 if(WITH_BUILDINFO)
696         find_package(Git)
697         if(NOT GIT_FOUND)
698                 message(WARNING "Git was not found, disabling WITH_BUILDINFO")
699                 set(WITH_BUILDINFO OFF)
700         endif()
701 endif()
702
703 TEST_SHARED_PTR_SUPPORT()
704 TEST_UNORDERED_MAP_SUPPORT()
705
706 if(WITH_AUDASPACE)
707         if(NOT WITH_SYSTEM_AUDASPACE)
708                 set(AUDASPACE_C_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/audaspace/bindings/C" "${CMAKE_BINARY_DIR}/extern/audaspace")
709                 set(AUDASPACE_PY_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/audaspace/bindings")
710         endif()
711 endif()
712
713 #-----------------------------------------------------------------------------
714 # Check for valid directories
715 # ... a partial checkout may cause this.
716 #
717 # note: we need to check for a known subdir in both cases.
718 #       since uninitialized git submodules will give blank dirs
719
720 if(WITH_INTERNATIONAL)
721         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
722                 message(WARNING
723                         "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
724                         "This is a 'git submodule', which are known not to work with bridges to other version "
725                         "control systems, disabling 'WITH_INTERNATIONAL'."
726                 )
727                 set(WITH_INTERNATIONAL OFF)
728         endif()
729 endif()
730
731 if(WITH_PYTHON)
732         # While we have this as an '#error' in 'bpy_capi_utils.h',
733         # upgrading Python tends to cause confusion for users who build.
734         # Give the error message early to make this more obvious.
735         #
736         # Do this before main 'platform_*' checks,
737         # because UNIX will search for the old Python paths which may not exist.
738         # giving errors about missing paths before this case is met.
739         if(DEFINED PYTHON_VERSION AND "${PYTHON_VERSION}" VERSION_LESS "3.6")
740                 message(FATAL_ERROR "At least Python 3.6 is required to build")
741         endif()
742
743         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
744                 message(WARNING
745                         "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
746                         "This is a 'git submodule', which are known not to work with bridges to other version "
747                         "control systems: * CONTINUING WITHOUT ADDONS *"
748                 )
749         endif()
750 endif()
751
752 #-----------------------------------------------------------------------------
753 # Initialize un-cached vars, avoid unused warning
754
755 # linux only, not cached
756 set(WITH_BINRELOC OFF)
757
758 # MACOSX only, set to avoid uninitialized
759 set(EXETYPE "")
760
761 # C/C++ flags
762 set(PLATFORM_CFLAGS)
763
764 # these are added to later on.
765 set(C_WARNINGS)
766 set(CXX_WARNINGS)
767
768 # for gcc -Wno-blah-blah
769 set(CC_REMOVE_STRICT_FLAGS)
770
771 # libraries to link the binary with passed to target_link_libraries()
772 # known as LLIBS to scons
773 set(PLATFORM_LINKLIBS "")
774
775 # Added to linker flags in setup_liblinks
776 # - CMAKE_EXE_LINKER_FLAGS
777 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
778 set(PLATFORM_LINKFLAGS "")
779 set(PLATFORM_LINKFLAGS_DEBUG "")
780
781
782 #-----------------------------------------------------------------------------
783 #Platform specifics
784
785 if(WITH_X11)
786         find_package(X11 REQUIRED)
787
788         find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
789         mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
790
791         list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
792
793         if(WITH_X11_XINPUT)
794                 if(X11_Xinput_LIB)
795                         list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
796                 else()
797                         set(WITH_X11_XINPUT OFF)
798                 endif()
799         endif()
800
801         if(WITH_X11_XF86VMODE)
802                 # XXX, why dont cmake make this available?
803                 find_library(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
804                 mark_as_advanced(X11_Xxf86vmode_LIB)
805                 if(X11_Xxf86vmode_LIB)
806                         list(APPEND PLATFORM_LINKLIBS ${X11_Xxf86vmode_LIB})
807                 else()
808                         set(WITH_X11_XF86VMODE OFF)
809                 endif()
810         endif()
811
812         if(WITH_X11_XFIXES)
813                 if(X11_Xfixes_LIB)
814                         list(APPEND PLATFORM_LINKLIBS ${X11_Xfixes_LIB})
815                 else()
816                         set(WITH_X11_XFIXES 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         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_RESTRICT -Wrestrict)
1298
1299         # gcc 4.2 gives annoying warnings on every file with this
1300         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1301                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
1302         endif()
1303
1304         # versions before gcc4.6 give many BLI_math warnings
1305         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
1306                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
1307                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
1308         endif()
1309
1310         # versions before gcc4.8 include global name-space.
1311         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.8")
1312                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_SHADOW -Wshadow)
1313         endif()
1314
1315         # disable because it gives warnings for printf() & friends.
1316         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1317
1318         if(NOT APPLE)
1319                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1320         endif()
1321
1322         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1323         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1324         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1325         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
1326         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1327         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1328         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1329         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
1330         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1331         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1332         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1333         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1334         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_POINTER_ARITH -Wpointer-arith)
1335         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_PARAMETER -Wunused-parameter)
1336         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_WRITE_STRINGS -Wwrite-strings)
1337         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1338         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_FORMAT_SIGN -Wformat-signedness)
1339         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_RESTRICT -Wrestrict)
1340
1341         # gcc 4.2 gives annoying warnings on every file with this
1342         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1343                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
1344         endif()
1345
1346         # causes too many warnings
1347         if(NOT APPLE)
1348                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1349                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
1350         endif()
1351
1352         # Use 'ATTR_FALLTHROUGH' macro to suppress.
1353         if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "7.0"))
1354                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_IMPLICIT_FALLTHROUGH -Wimplicit-fallthrough=5)
1355                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_IMPLICIT_FALLTHROUGH -Wimplicit-fallthrough=5)
1356         endif()
1357
1358         # flags to undo strict flags
1359         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
1360         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
1361
1362         if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "7.0"))
1363                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_IMPLICIT_FALLTHROUGH    -Wno-implicit-fallthrough)
1364         endif()
1365
1366         if(NOT APPLE)
1367                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1368         endif()
1369
1370 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
1371
1372         # strange, clang complains these are not supported, but then uses them.
1373         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1374         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1375         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1376         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1377         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1378         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1379         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1380         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1381         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1382
1383         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1384         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1385         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
1386         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
1387         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.
1388         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
1389         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
1390
1391         # gives too many unfixable warnings
1392         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
1393         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
1394
1395         # flags to undo strict flags
1396         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
1397         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
1398
1399         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
1400         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
1401         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
1402         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
1403         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
1404         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
1405         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
1406         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
1407
1408         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
1409         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
1410         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
1411         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
1412         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
1413
1414 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1415
1416         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1417         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1418         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1419
1420         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1421         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1422         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1423
1424         # disable numbered, false positives
1425         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
1426         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
1427 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
1428         # most msvc warnings are C & C++
1429         set(_WARNINGS
1430                 # warning level:
1431                 "/W3"
1432                 "/w34062"  # switch statement contains 'default' but no 'case' labels
1433                 # disable:
1434                 "/wd4018"  # signed/unsigned mismatch
1435                 "/wd4146"  # unary minus operator applied to unsigned type, result still unsigned
1436                 "/wd4065"  # switch statement contains 'default' but no 'case' labels
1437                 "/wd4127"  # conditional expression is constant
1438                 "/wd4181"  # qualifier applied to reference type; ignored
1439                 "/wd4200"  # zero-sized array in struct/union
1440                 "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
1441                 "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
1442                 "/wd4305"  # truncation from 'type1' to 'type2'
1443                 "/wd4800"  # forcing value to bool 'true' or 'false'
1444                 # errors:
1445                 "/we4013"  # 'function' undefined; assuming extern returning int
1446                 "/we4133"  # incompatible pointer types
1447                 "/we4431"  # missing type specifier - int assumed
1448         )
1449
1450         string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
1451         set(C_WARNINGS "${_WARNINGS}")
1452         set(CXX_WARNINGS "${_WARNINGS}")
1453         unset(_WARNINGS)
1454 endif()
1455
1456 # ensure python header is found since detection can fail, this could happen
1457 # with _any_ library but since we used a fixed python version this tends to
1458 # be most problematic.
1459 if(WITH_PYTHON)
1460         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1461                 message(FATAL_ERROR
1462                         "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1463                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1464                         "to a valid python include path. Containing "
1465                         "Python.h for python version \"${PYTHON_VERSION}\""
1466                 )
1467         endif()
1468
1469         if(WIN32)
1470                 # pass, we have this in an archive to extract
1471         elseif((WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY) OR (WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE))
1472                 if(("${PYTHON_NUMPY_PATH}" STREQUAL "") OR (${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
1473                         find_python_package(numpy)
1474                         unset(PYTHON_NUMPY_INCLUDE_DIRS CACHE)
1475                         set(PYTHON_NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_PATH}/numpy/core/include CACHE PATH "Path to the include directory of the numpy module")
1476                         mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIRS)
1477                 endif()
1478         endif()
1479
1480         if(WIN32 OR APPLE)
1481                 # pass, we have this in lib/python/site-packages
1482         elseif(WITH_PYTHON_INSTALL_REQUESTS)
1483                 find_python_package(requests)
1484         endif()
1485 endif()
1486
1487 if(WITH_CXX11)
1488         if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
1489                 # TODO(sergey): Do we want c++11 or gnu-c++11 here?
1490                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
1491         elseif(MSVC)
1492                 # Nothing special is needed, C++11 features are available by default.
1493         else()
1494                 message(FATAL_ERROR "Compiler ${CMAKE_C_COMPILER_ID} is not supported for C++11 build yet")
1495         endif()
1496 else()
1497         # GCC-6 switched to C++11 by default, which would break linking with existing libraries
1498         # by default. So we explicitly disable C++11 for a new GCC so no linking issues happens.
1499         if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0"))
1500                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++98")
1501                 # We also disable any of C++11 ABI from usage, so we wouldn't even try to
1502                 # link to stuff from std::__cxx11 namespace.
1503                 add_definitions("-D_GLIBCXX_USE_CXX11_ABI=0")
1504         endif()
1505 endif()
1506
1507 # Visual Studio has all standards it supports available by default
1508 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "Intel")
1509         # Use C99 + GNU extensions, works with GCC, Clang, ICC
1510         if(WITH_C11)
1511                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
1512         else()
1513                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
1514         endif()
1515 endif()
1516
1517 # Include warnings first, so its possible to disable them with user defined flags
1518 # eg: -Wno-uninitialized
1519 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
1520 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
1521
1522 # defined above, platform specific but shared names
1523 mark_as_advanced(
1524         CYCLES_OSL
1525         OSL_LIB_EXEC
1526         OSL_COMPILER
1527         OSL_LIB_COMP
1528         OSL_LIB_QUERY
1529         OSL_INCLUDE_DIR
1530 )
1531
1532 mark_as_advanced(
1533         LLVM_CONFIG
1534         LLVM_ROOT_DIR
1535         LLVM_LIBRARY
1536         LLVM_VERSION
1537 )
1538
1539 #-------------------------------------------------------------------------------
1540 # Global Defines
1541
1542 # better not set includes here but this debugging option is off by default.
1543 if(WITH_CXX_GUARDEDALLOC)
1544         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1545         add_definitions(-DWITH_CXX_GUARDEDALLOC)
1546 endif()
1547
1548 if(WITH_ASSERT_ABORT)
1549         add_definitions(-DWITH_ASSERT_ABORT)
1550 endif()
1551
1552 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1553 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1554
1555 #-----------------------------------------------------------------------------
1556 # Libraries
1557
1558 if(WITH_GTESTS)
1559         include(GTestTesting)
1560 endif()
1561
1562 if(WITH_BLENDER OR WITH_PLAYER)
1563         add_subdirectory(intern)
1564         add_subdirectory(extern)
1565
1566         # source after intern and extern to gather all
1567         # internal and external library information first, for test linking
1568         add_subdirectory(source)
1569 elseif(WITH_CYCLES_STANDALONE)
1570         add_subdirectory(intern/cycles)
1571         add_subdirectory(extern/clew)
1572         if(WITH_CUDA_DYNLOAD)
1573                 add_subdirectory(extern/cuew)
1574         endif()
1575         if(NOT WITH_SYSTEM_GLEW)
1576                 add_subdirectory(extern/glew)
1577         endif()
1578 endif()
1579
1580 #-----------------------------------------------------------------------------
1581 # Blender Application
1582 if(WITH_BLENDER)
1583         add_subdirectory(source/creator)
1584 endif()
1585
1586
1587 #-----------------------------------------------------------------------------
1588 # Blender Player
1589 if(WITH_PLAYER)
1590         add_subdirectory(source/blenderplayer)
1591 endif()
1592
1593
1594 #-----------------------------------------------------------------------------
1595 # Testing
1596 add_subdirectory(tests)
1597
1598
1599 #-----------------------------------------------------------------------------
1600 # CPack for generating packages
1601 include(build_files/cmake/packaging.cmake)
1602
1603 #-----------------------------------------------------------------------------
1604 # Use dynamic loading for OpenMP
1605 if(WITH_BLENDER)
1606         openmp_delayload(blender)
1607 endif()
1608 if(WITH_PLAYER)
1609         openmp_delayload(blenderplayer)
1610 endif()
1611
1612 #-----------------------------------------------------------------------------
1613 # Print Final Configuration
1614
1615 if(FIRST_RUN)
1616
1617         set(_config_msg "\nBlender Configuration\n=====================")
1618
1619         function(info_cfg_option
1620                 _setting
1621                 )
1622
1623                 set(_msg "  - ${_setting}")
1624                 string(LENGTH "${_msg}" _len)
1625                 while("32" GREATER "${_len}")
1626                         set(_msg "${_msg} ")
1627                         math(EXPR _len "${_len} + 1")
1628                 endwhile()
1629
1630                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
1631         endfunction()
1632
1633         function(info_cfg_text
1634                 _text
1635                 )
1636
1637                 set(_config_msg "${_config_msg}\n\n  ${_text}" PARENT_SCOPE)
1638         endfunction()
1639
1640         message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
1641         message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
1642
1643         info_cfg_text("Build Options:")
1644         info_cfg_option(WITH_GAMEENGINE)
1645         info_cfg_option(WITH_PLAYER)
1646         info_cfg_option(WITH_BULLET)
1647         info_cfg_option(WITH_IK_SOLVER)
1648         info_cfg_option(WITH_IK_ITASC)
1649         info_cfg_option(WITH_OPENCOLLADA)
1650         info_cfg_option(WITH_FFTW3)
1651         info_cfg_option(WITH_INTERNATIONAL)
1652         info_cfg_option(WITH_INPUT_NDOF)
1653         info_cfg_option(WITH_CYCLES)
1654         info_cfg_option(WITH_FREESTYLE)
1655         info_cfg_option(WITH_OPENCOLORIO)
1656         info_cfg_option(WITH_OPENVDB)
1657         info_cfg_option(WITH_ALEMBIC)
1658
1659         info_cfg_text("Compiler Options:")
1660         info_cfg_option(WITH_BUILDINFO)
1661         info_cfg_option(WITH_OPENMP)
1662         info_cfg_option(WITH_RAYOPTIMIZATION)
1663
1664         info_cfg_text("System Options:")
1665         info_cfg_option(WITH_INSTALL_PORTABLE)
1666         info_cfg_option(WITH_X11_ALPHA)
1667         info_cfg_option(WITH_X11_XF86VMODE)
1668         info_cfg_option(WITH_X11_XFIXES)
1669         info_cfg_option(WITH_X11_XINPUT)
1670         info_cfg_option(WITH_MEM_JEMALLOC)
1671         info_cfg_option(WITH_MEM_VALGRIND)
1672         info_cfg_option(WITH_SYSTEM_GLEW)
1673         info_cfg_option(WITH_SYSTEM_OPENJPEG)
1674
1675         info_cfg_text("Image Formats:")
1676         info_cfg_option(WITH_OPENIMAGEIO)
1677         info_cfg_option(WITH_IMAGE_CINEON)
1678         info_cfg_option(WITH_IMAGE_DDS)
1679         info_cfg_option(WITH_IMAGE_HDR)
1680         info_cfg_option(WITH_IMAGE_OPENEXR)
1681         info_cfg_option(WITH_IMAGE_OPENJPEG)
1682         info_cfg_option(WITH_IMAGE_TIFF)
1683
1684         info_cfg_text("Audio:")
1685         info_cfg_option(WITH_OPENAL)
1686         info_cfg_option(WITH_SDL)
1687         info_cfg_option(WITH_SDL_DYNLOAD)
1688         info_cfg_option(WITH_JACK)
1689         info_cfg_option(WITH_JACK_DYNLOAD)
1690         info_cfg_option(WITH_CODEC_AVI)
1691         info_cfg_option(WITH_CODEC_FFMPEG)
1692         info_cfg_option(WITH_CODEC_SNDFILE)
1693
1694         info_cfg_text("Compression:")
1695         info_cfg_option(WITH_LZMA)
1696         info_cfg_option(WITH_LZO)
1697
1698         info_cfg_text("Python:")
1699         info_cfg_option(WITH_PYTHON_INSTALL)
1700         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
1701         info_cfg_option(WITH_PYTHON_MODULE)
1702         info_cfg_option(WITH_PYTHON_SAFETY)
1703         if(APPLE)
1704                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
1705         endif()
1706
1707         info_cfg_text("Modifiers:")
1708         info_cfg_option(WITH_MOD_BOOLEAN)
1709         info_cfg_option(WITH_MOD_REMESH)
1710         info_cfg_option(WITH_MOD_FLUID)
1711         info_cfg_option(WITH_MOD_OCEANSIM)
1712
1713         info_cfg_text("OpenGL:")
1714         info_cfg_option(WITH_GLEW_ES)
1715         info_cfg_option(WITH_GL_EGL)
1716         info_cfg_option(WITH_GL_PROFILE_ES20)
1717         if(WIN32)
1718                 info_cfg_option(WITH_GL_ANGLE)
1719         endif()
1720
1721         info_cfg_text("")
1722
1723         message("${_config_msg}")
1724 endif()
1725
1726 if(0)
1727         print_all_vars()
1728 endif()