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