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