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