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