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