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