glTF: add Draco shared library for mesh compression.
[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 # enable boost for cycles, audaspace or i18n
644 # otherwise if the user disabled
645 if(NOT WITH_BOOST)
646         # Explicitly disabled. so disable all deps.
647         macro(set_and_warn
648                 _setting _val)
649                 if(${${_setting}})
650                         message(STATUS "'WITH_BOOST' is disabled: forcing 'set(${_setting} ${_val})'")
651                 endif()
652                 set(${_setting} ${_val})
653         endmacro()
654
655         set_and_warn(WITH_CYCLES         OFF)
656         set_and_warn(WITH_INTERNATIONAL  OFF)
657         set_and_warn(WITH_OPENVDB        OFF)
658         set_and_warn(WITH_OPENCOLORIO    OFF)
659 elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_INTERNATIONAL OR
660        WITH_OPENVDB OR WITH_OPENCOLORIO)
661         # Keep enabled
662 else()
663         # Disable boost if not needed.
664         set(WITH_BOOST OFF)
665 endif()
666
667 # auto enable openimageio for cycles
668 if(WITH_CYCLES)
669         set(WITH_OPENIMAGEIO ON)
670
671         # auto enable llvm for cycles_osl
672         if(WITH_CYCLES_OSL)
673                 set(WITH_LLVM ON CACHE BOOL "" FORCE)
674         endif()
675 else()
676         set(WITH_CYCLES_OSL OFF)
677 endif()
678
679 # auto enable openimageio linking dependencies
680 if(WITH_OPENIMAGEIO)
681         set(WITH_IMAGE_OPENEXR ON)
682         set(WITH_IMAGE_TIFF ON)
683 endif()
684
685 # auto enable alembic linking dependencies
686 if(WITH_ALEMBIC)
687         set(WITH_IMAGE_OPENEXR ON)
688 endif()
689
690 # don't store paths to libs for portable distribution
691 if(WITH_INSTALL_PORTABLE)
692         set(CMAKE_SKIP_BUILD_RPATH TRUE)
693 endif()
694
695 if(WITH_GHOST_SDL OR WITH_HEADLESS)
696         set(WITH_X11           OFF)
697         set(WITH_X11_XINPUT    OFF)
698         set(WITH_X11_XF86VMODE OFF)
699         set(WITH_X11_XFIXES    OFF)
700         set(WITH_X11_ALPHA     OFF)
701         set(WITH_GHOST_XDND    OFF)
702         set(WITH_INPUT_IME     OFF)
703 endif()
704
705 if(WITH_CPU_SSE)
706         TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
707 else()
708         message(STATUS "SSE and SSE2 optimizations are DISABLED!")
709         set(COMPILER_SSE_FLAG)
710         set(COMPILER_SSE2_FLAG)
711 endif()
712
713 if(WITH_BUILDINFO)
714         find_package(Git)
715         if(NOT GIT_FOUND)
716                 message(WARNING "Git was not found, disabling WITH_BUILDINFO")
717                 set(WITH_BUILDINFO OFF)
718         endif()
719 endif()
720
721 if(WITH_AUDASPACE)
722         if(NOT WITH_SYSTEM_AUDASPACE)
723                 set(AUDASPACE_C_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/audaspace/bindings/C" "${CMAKE_BINARY_DIR}/extern/audaspace")
724                 set(AUDASPACE_PY_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/audaspace/bindings")
725         endif()
726 endif()
727
728 # Auto-enable CUDA dynload if toolkit is not found.
729 if(NOT WITH_CUDA_DYNLOAD)
730         find_package(CUDA)
731         if (NOT CUDA_FOUND)
732                 message("CUDA toolkit not found, using dynamic runtime loading of libraries instead")
733                 set(WITH_CUDA_DYNLOAD ON)
734         endif()
735 endif()
736
737 #-----------------------------------------------------------------------------
738 # Check for valid directories
739 # ... a partial checkout may cause this.
740 #
741 # note: we need to check for a known subdir in both cases.
742 #       since uninitialized git submodules will give blank dirs
743
744 if(WITH_INTERNATIONAL)
745         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
746                 message(WARNING
747                         "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
748                         "This is a 'git submodule', which are known not to work with bridges to other version "
749                         "control systems, disabling 'WITH_INTERNATIONAL'."
750                 )
751                 set(WITH_INTERNATIONAL OFF)
752         endif()
753 endif()
754
755 if(WITH_PYTHON)
756         # While we have this as an '#error' in 'bpy_capi_utils.h',
757         # upgrading Python tends to cause confusion for users who build.
758         # Give the error message early to make this more obvious.
759         #
760         # Do this before main 'platform_*' checks,
761         # because UNIX will search for the old Python paths which may not exist.
762         # giving errors about missing paths before this case is met.
763         if(DEFINED PYTHON_VERSION AND "${PYTHON_VERSION}" VERSION_LESS "3.7")
764                 message(FATAL_ERROR "At least Python 3.7 is required to build")
765         endif()
766
767         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
768                 message(WARNING
769                         "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
770                         "This is a 'git submodule', which are known not to work with bridges to other version "
771                         "control systems: * CONTINUING WITHOUT ADDONS *"
772                 )
773         endif()
774 endif()
775
776 #-----------------------------------------------------------------------------
777 # Initialize un-cached vars, avoid unused warning
778
779 # linux only, not cached
780 set(WITH_BINRELOC OFF)
781
782 # MACOSX only, set to avoid uninitialized
783 set(EXETYPE "")
784
785 # C/C++ flags
786 set(PLATFORM_CFLAGS)
787
788 # these are added to later on.
789 set(C_WARNINGS)
790 set(CXX_WARNINGS)
791
792 # for gcc -Wno-blah-blah
793 set(C_REMOVE_STRICT_FLAGS)
794 set(CXX_REMOVE_STRICT_FLAGS)
795
796 # libraries to link the binary with passed to target_link_libraries()
797 # known as LLIBS to scons
798 set(PLATFORM_LINKLIBS "")
799
800 # Added to linker flags in setup_liblinks
801 # - CMAKE_EXE_LINKER_FLAGS
802 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
803 set(PLATFORM_LINKFLAGS "")
804 set(PLATFORM_LINKFLAGS_DEBUG "")
805
806 if (NOT CMAKE_BUILD_TYPE MATCHES "Release")
807         if(WITH_COMPILER_ASAN)
808                 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COMPILER_ASAN_CFLAGS}")
809                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${COMPILER_ASAN_CFLAGS}")
810
811                 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COMPILER_ASAN_CXXFLAGS}")
812                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COMPILER_ASAN_CXXFLAGS}")
813                 if(MSVC)
814                         set(COMPILER_ASAN_LINKER_FLAGS "/FUNCTIONPADMIN:6")
815                 endif()
816                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS};${COMPILER_ASAN_LIBRARY}")
817                 set(PLATFORM_LINKFLAGS "${COMPILER_ASAN_LIBRARY} ${COMPILER_ASAN_LINKER_FLAGS}")
818                 set(PLATFORM_LINKFLAGS_DEBUG "${COMPILER_ASAN_LIBRARY} ${COMPILER_ASAN_LINKER_FLAGS}")
819         endif()
820 endif()
821
822 #-----------------------------------------------------------------------------
823 #Platform specifics
824
825 if(WITH_X11)
826         find_package(X11 REQUIRED)
827
828         find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
829         mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
830
831         list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
832
833         if(WITH_X11_XINPUT)
834                 if(X11_Xinput_LIB)
835                         list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
836                 else()
837                         set(WITH_X11_XINPUT OFF)
838                 endif()
839         endif()
840
841         if(WITH_X11_XF86VMODE)
842                 # XXX, why doesn't cmake make this available?
843                 find_library(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
844                 mark_as_advanced(X11_Xxf86vmode_LIB)
845                 if(X11_Xxf86vmode_LIB)
846                         list(APPEND PLATFORM_LINKLIBS ${X11_Xxf86vmode_LIB})
847                 else()
848                         set(WITH_X11_XF86VMODE OFF)
849                 endif()
850         endif()
851
852         if(WITH_X11_XFIXES)
853                 if(X11_Xfixes_LIB)
854                         list(APPEND PLATFORM_LINKLIBS ${X11_Xfixes_LIB})
855                 else()
856                         set(WITH_X11_XFIXES OFF)
857                 endif()
858         endif()
859
860         if(WITH_X11_ALPHA)
861                 find_library(X11_Xrender_LIB Xrender  ${X11_LIB_SEARCH_PATH})
862                 mark_as_advanced(X11_Xrender_LIB)
863                 if(X11_Xrender_LIB)
864                         list(APPEND PLATFORM_LINKLIBS ${X11_Xrender_LIB})
865                 else()
866                         set(WITH_X11_ALPHA OFF)
867                 endif()
868         endif()
869
870 endif()
871
872
873 # ----------------------------------------------------------------------------
874 # Main Platform Checks
875 #
876 # - UNIX
877 # - WIN32
878 # - APPLE
879
880 if(UNIX AND NOT APPLE)
881         include(platform_unix)
882 elseif(WIN32)
883         include(platform_win32)
884 elseif(APPLE)
885         include(platform_apple)
886 endif()
887
888 #-----------------------------------------------------------------------------
889 # Common.
890
891 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
892         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
893 endif()
894
895 if(WITH_CYCLES)
896         if(NOT WITH_OPENIMAGEIO)
897                 message(FATAL_ERROR
898                         "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. "
899                         "Configure OIIO or disable WITH_CYCLES"
900                 )
901         endif()
902         if(NOT WITH_BOOST)
903                 message(FATAL_ERROR
904                         "Cycles requires WITH_BOOST, the library may not have been found. "
905                         "Configure BOOST or disable WITH_CYCLES"
906                 )
907         endif()
908
909         if(WITH_CYCLES_OSL)
910                 if(NOT WITH_LLVM)
911                         message(FATAL_ERROR
912                                 "Cycles OSL requires WITH_LLVM, the library may not have been found. "
913                                 "Configure LLVM or disable WITH_CYCLES_OSL"
914                         )
915                 endif()
916         endif()
917 endif()
918
919 if(WITH_INTERNATIONAL)
920         if(NOT WITH_BOOST)
921                 message(FATAL_ERROR
922                         "Internationalization requires WITH_BOOST, the library may not have been found. "
923                         "Configure BOOST or disable WITH_INTERNATIONAL"
924                 )
925         endif()
926 endif()
927
928 # See TEST_SSE_SUPPORT() for how this is defined.
929
930 # Do it globally, SSE2 is required for quite some time now.
931 # Doing it now allows to use SSE/SSE2 in inline headers.
932 if(SUPPORT_SSE_BUILD)
933         set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
934         add_definitions(-D__SSE__ -D__MMX__)
935 endif()
936 if(SUPPORT_SSE2_BUILD)
937         set(PLATFORM_CFLAGS " ${PLATFORM_CFLAGS} ${COMPILER_SSE2_FLAG}")
938         add_definitions(-D__SSE2__)
939         if(NOT SUPPORT_SSE_BUILD) # don't double up
940                 add_definitions(-D__MMX__)
941         endif()
942 endif()
943
944
945 # set the endian define
946 if(MSVC)
947         # for some reason this fails on msvc
948         add_definitions(-D__LITTLE_ENDIAN__)
949
950 # OSX-Note: as we do cross-compiling with specific set architecture,
951 # endianess-detection and auto-setting is counterproductive
952 # so we just set endianness according CMAKE_OSX_ARCHITECTURES
953
954 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
955         add_definitions(-D__LITTLE_ENDIAN__)
956 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)
957         add_definitions(-D__BIG_ENDIAN__)
958
959 else()
960         include(TestBigEndian)
961         test_big_endian(_SYSTEM_BIG_ENDIAN)
962         if(_SYSTEM_BIG_ENDIAN)
963                 add_definitions(-D__BIG_ENDIAN__)
964         else()
965                 add_definitions(-D__LITTLE_ENDIAN__)
966         endif()
967         unset(_SYSTEM_BIG_ENDIAN)
968 endif()
969 if(WITH_IMAGE_OPENJPEG)
970         # Special handling of Windows platform where openjpeg is always static.
971         if(WIN32)
972                 set(OPENJPEG_DEFINES "-DOPJ_STATIC")
973         else()
974                 set(OPENJPEG_DEFINES "")
975         endif()
976 endif()
977
978 if(NOT WITH_SYSTEM_EIGEN3)
979         set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3)
980 endif()
981
982 #-----------------------------------------------------------------------------
983 # Configure OpenGL.
984
985 find_package(OpenGL)
986 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
987
988 if(WITH_OPENGL)
989         add_definitions(-DWITH_OPENGL)
990 endif()
991
992 if(WITH_SYSTEM_GLES)
993         find_package_wrapper(OpenGLES)
994 endif()
995
996 if(WITH_GL_PROFILE_ES20)
997         if(WITH_SYSTEM_GLES)
998                 if(NOT OPENGLES_LIBRARY)
999                         message(FATAL_ERROR
1000                                 "Unable to find OpenGL ES libraries. "
1001                                 "Install them or disable WITH_SYSTEM_GLES."
1002                         )
1003                 endif()
1004
1005                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_LIBRARY)
1006
1007         else()
1008                 set(OPENGLES_LIBRARY "" CACHE FILEPATH "OpenGL ES 2.0 library file")
1009                 mark_as_advanced(OPENGLES_LIBRARY)
1010
1011                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
1012
1013                 if(NOT OPENGLES_LIBRARY)
1014                         message(FATAL_ERROR
1015                                 "To compile WITH_GL_EGL you need to set OPENGLES_LIBRARY "
1016                                 "to the file path of an OpenGL ES 2.0 library."
1017                         )
1018                 endif()
1019
1020         endif()
1021
1022         if(WIN32)
1023                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
1024
1025                 set(OPENGLES_DLL "" CACHE FILEPATH "OpenGL ES 2.0 redistributable DLL file")
1026                 mark_as_advanced(OPENGLES_DLL)
1027
1028                 if(NOT OPENGLES_DLL)
1029                         message(FATAL_ERROR
1030                                 "To compile WITH_GL_PROFILE_ES20 you need to set OPENGLES_DLL to the file "
1031                                 "path of an OpenGL ES 2.0 runtime dynamic link library (DLL)."
1032                         )
1033                 endif()
1034
1035                 if(WITH_GL_ANGLE)
1036                         list(APPEND GL_DEFINITIONS -DWITH_ANGLE)
1037
1038                         set(D3DCOMPILER_DLL "" CACHE FILEPATH "Direct3D Compiler redistributable DLL file (needed by ANGLE)")
1039
1040                         get_filename_component(D3DCOMPILER_FILENAME "${D3DCOMPILER_DLL}" NAME)
1041                         list(APPEND GL_DEFINITIONS "-DD3DCOMPILER=\"\\\"${D3DCOMPILER_FILENAME}\\\"\"")
1042
1043                         mark_as_advanced(D3DCOMPILER_DLL)
1044
1045                         if(D3DCOMPILER_DLL STREQUAL "")
1046                                 message(FATAL_ERROR
1047                                         "To compile WITH_GL_ANGLE you need to set D3DCOMPILER_DLL to the file "
1048                                         "path of a copy of the DirectX redistributable DLL file: D3DCompiler_46.dll"
1049                                 )
1050                         endif()
1051
1052                 endif()
1053
1054         endif()
1055
1056 else()
1057         if(OpenGL_GL_PREFERENCE STREQUAL "LEGACY" AND OPENGL_gl_LIBRARY)
1058                 list(APPEND BLENDER_GL_LIBRARIES ${OPENGL_gl_LIBRARY})
1059         else()
1060                 list(APPEND BLENDER_GL_LIBRARIES ${OPENGL_opengl_LIBRARY} ${OPENGL_glx_LIBRARY})
1061         endif()
1062 endif()
1063
1064 if(WITH_GL_EGL)
1065         list(APPEND GL_DEFINITIONS -DWITH_GL_EGL)
1066
1067         if(WITH_SYSTEM_GLES)
1068                 if(NOT OPENGLES_EGL_LIBRARY)
1069                         message(FATAL_ERROR
1070                                 "Unable to find OpenGL ES libraries. "
1071                                 "Install them or disable WITH_SYSTEM_GLES."
1072                         )
1073                 endif()
1074
1075                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_EGL_LIBRARY)
1076
1077         else()
1078                 set(OPENGLES_EGL_LIBRARY "" CACHE FILEPATH "EGL library file")
1079                 mark_as_advanced(OPENGLES_EGL_LIBRARY)
1080
1081                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}" "${OPENGLES_EGL_LIBRARY}")
1082
1083                 if(NOT OPENGLES_EGL_LIBRARY)
1084                         message(FATAL_ERROR
1085                                 "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY "
1086                                 "to the file path of an EGL library."
1087                         )
1088                 endif()
1089
1090         endif()
1091
1092         if(WIN32)
1093                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
1094
1095                 set(OPENGLES_EGL_DLL "" CACHE FILEPATH "EGL redistributable DLL file")
1096                 mark_as_advanced(OPENGLES_EGL_DLL)
1097
1098                 if(NOT OPENGLES_EGL_DLL)
1099                         message(FATAL_ERROR
1100                                 "To compile WITH_GL_EGL you need to set OPENGLES_EGL_DLL "
1101                                 "to the file path of an EGL runtime dynamic link library (DLL)."
1102                         )
1103                 endif()
1104
1105         endif()
1106
1107 endif()
1108
1109 if(WITH_GL_PROFILE_ES20)
1110         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_ES20)
1111 else()
1112         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_CORE)
1113 endif()
1114
1115 if(WITH_GL_EGL)
1116         list(APPEND GL_DEFINITIONS -DWITH_EGL)
1117 endif()
1118
1119 #-----------------------------------------------------------------------------
1120 # Configure OpenMP.
1121 if(WITH_OPENMP)
1122         if(NOT OPENMP_CUSTOM)
1123                 find_package(OpenMP)
1124         endif()
1125
1126         if(OPENMP_FOUND)
1127                 if(NOT WITH_OPENMP_STATIC)
1128                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1129                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1130                 else()
1131                         # Typically avoid adding flags as defines but we can't
1132                         # pass OpenMP flags to the linker for static builds, meaning
1133                         # we can't add any OpenMP related flags to CFLAGS variables
1134                         # since they're passed to the linker as well.
1135                         add_definitions("${OpenMP_C_FLAGS}")
1136
1137                         find_library_static(OpenMP_LIBRARIES gomp ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
1138                 endif()
1139         else()
1140                 set(WITH_OPENMP OFF)
1141         endif()
1142
1143         mark_as_advanced(
1144                 OpenMP_C_FLAGS
1145                 OpenMP_CXX_FLAGS
1146         )
1147 endif()
1148
1149 #-----------------------------------------------------------------------------
1150 # Configure GLEW
1151
1152 if(WITH_SYSTEM_GLEW)
1153         find_package(GLEW)
1154
1155         # Note: There is an assumption here that the system GLEW is not a static library.
1156
1157         if(NOT GLEW_FOUND)
1158                 message(FATAL_ERROR "GLEW is required to build Blender. Install it or disable WITH_SYSTEM_GLEW.")
1159         endif()
1160
1161         set(BLENDER_GLEW_LIBRARIES ${GLEW_LIBRARY})
1162 else()
1163         if(WITH_GLEW_ES)
1164                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew-es/include")
1165
1166                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC -DWITH_GLEW_ES)
1167
1168                 # These definitions remove APIs from glew.h, making GLEW smaller, and catching unguarded API usage
1169                 if(WITH_GL_PROFILE_ES20)
1170                         list(APPEND GL_DEFINITIONS -DGLEW_ES_ONLY)
1171                 else()
1172                         # No ES functions are needed
1173                         list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
1174                 endif()
1175
1176                 if(WITH_GL_PROFILE_ES20)
1177                         if(WITH_GL_EGL)
1178                                 list(APPEND GL_DEFINITIONS -DGLEW_USE_LIB_ES20)
1179                         endif()
1180
1181                         # ToDo: This is an experiment to eliminate ES 1 symbols,
1182                         # GLEW doesn't really properly provide this level of control
1183                         # (for example, without modification it eliminates too many symbols)
1184                         # so there are lots of modifications to GLEW to make this work,
1185                         # and no attempt to make it work beyond Blender at this point.
1186                         list(APPEND GL_DEFINITIONS -DGL_ES_VERSION_1_0=0 -DGL_ES_VERSION_CL_1_1=0 -DGL_ES_VERSION_CM_1_1=0)
1187                 endif()
1188
1189                 if(WITH_GL_EGL)
1190                         list(APPEND GL_DEFINITIONS -DGLEW_INC_EGL)
1191                 endif()
1192
1193                 set(BLENDER_GLEW_LIBRARIES extern_glew_es bf_intern_glew_mx)
1194
1195         else()
1196                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1197
1198                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC)
1199
1200                 # This won't affect the non-experimental glew library,
1201                 # but is used for conditional compilation elsewhere.
1202                 list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
1203
1204                 set(BLENDER_GLEW_LIBRARIES extern_glew)
1205
1206         endif()
1207
1208 endif()
1209
1210 list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
1211
1212 #-----------------------------------------------------------------------------
1213 # Configure Bullet
1214
1215 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
1216         find_package(Bullet)
1217         if(NOT BULLET_FOUND)
1218                 set(WITH_BULLET OFF)
1219         endif()
1220 else()
1221         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
1222         # set(BULLET_LIBRARIES "")
1223 endif()
1224
1225 #-----------------------------------------------------------------------------
1226 # Configure Python.
1227
1228 if(WITH_PYTHON_MODULE)
1229         add_definitions(-DPy_ENABLE_SHARED)
1230 endif()
1231
1232 #-----------------------------------------------------------------------------
1233 # Configure GLog/GFlags
1234
1235 if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING))
1236         if(WITH_SYSTEM_GFLAGS)
1237                 find_package(Gflags)
1238                 if(NOT GFLAGS_FOUND)
1239                         message(FATAL_ERROR "System wide Gflags is requested but was not found")
1240                 endif()
1241                 # FindGflags does not define this, and we are not even sure what to use here.
1242                 set(GFLAGS_DEFINES)
1243         else()
1244                 set(GFLAGS_DEFINES
1245                         -DGFLAGS_DLL_DEFINE_FLAG=
1246                         -DGFLAGS_DLL_DECLARE_FLAG=
1247                         -DGFLAGS_DLL_DECL=
1248                 )
1249                 set(GFLAGS_NAMESPACE "gflags")
1250                 set(GFLAGS_LIBRARIES extern_gflags)
1251                 set(GFLAGS_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/extern/gflags/src")
1252         endif()
1253
1254         if(WITH_SYSTEM_GLOG)
1255                 find_package(Glog)
1256                 if(NOT GLOG_FOUND)
1257                         message(FATAL_ERROR "System wide Glog is requested but was not found")
1258                 endif()
1259                 # FindGlog does not define this, and we are not even sure what to use here.
1260                 set(GLOG_DEFINES)
1261         else()
1262                 set(GLOG_DEFINES
1263                         -DGOOGLE_GLOG_DLL_DECL=
1264                 )
1265                 set(GLOG_LIBRARIES extern_glog)
1266                 if(WIN32)
1267                         set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/src/windows)
1268                 else()
1269                         set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/include)
1270                 endif()
1271         endif()
1272 endif()
1273
1274 #-----------------------------------------------------------------------------
1275 # Configure Ceres
1276
1277 if(WITH_LIBMV)
1278         # We always have C++11 which includes unordered_map.
1279         set(CERES_DEFINES -DCERES_STD_UNORDERED_MAP)
1280 endif()
1281
1282 #-----------------------------------------------------------------------------
1283 # Extra compile flags
1284
1285 if(CMAKE_COMPILER_IS_GNUCC)
1286
1287         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1288         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1289         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1290         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1291         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_VLA -Werror=vla)
1292         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1293         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1294         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1295         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1296         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1297         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1298         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1299         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1300         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
1301         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
1302         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1303         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
1304         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1305         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1306         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
1307         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_FORMAT_SIGN -Wformat-signedness)
1308         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_RESTRICT -Wrestrict)
1309
1310         # gcc 4.2 gives annoying warnings on every file with this
1311         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1312                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
1313         endif()
1314
1315         # versions before gcc4.6 give many BLI_math warnings
1316         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
1317                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
1318                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
1319         endif()
1320
1321         # versions before gcc4.8 include global name-space.
1322         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.8")
1323                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_SHADOW -Wshadow)
1324         endif()
1325
1326         # disable because it gives warnings for printf() & friends.
1327         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1328
1329         if(NOT APPLE)
1330                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1331         endif()
1332
1333         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1334         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1335         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1336         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
1337         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1338         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1339         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1340         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
1341         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1342         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1343         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1344         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1345         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_POINTER_ARITH -Wpointer-arith)
1346         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_PARAMETER -Wunused-parameter)
1347         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_WRITE_STRINGS -Wwrite-strings)
1348         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1349         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_FORMAT_SIGN -Wformat-signedness)
1350         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_RESTRICT -Wrestrict)
1351
1352         # gcc 4.2 gives annoying warnings on every file with this
1353         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1354                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
1355         endif()
1356
1357         # causes too many warnings
1358         if(NOT APPLE)
1359                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1360                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
1361         endif()
1362
1363         # Use 'ATTR_FALLTHROUGH' macro to suppress.
1364         if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "7.0"))
1365                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_IMPLICIT_FALLTHROUGH -Wimplicit-fallthrough=5)
1366                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_IMPLICIT_FALLTHROUGH -Wimplicit-fallthrough=5)
1367         endif()
1368
1369         # flags to undo strict flags
1370         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
1371         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
1372         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION         -Wno-unused-function)
1373         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_TYPE_LIMITS             -Wno-type-limits)
1374         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_INT_IN_BOOL_CONTEXT     -Wno-int-in-bool-context)
1375         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_FORMAT                  -Wno-format)
1376         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_SWITCH                  -Wno-switch)
1377
1378         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_CLASS_MEMACCESS     -Wno-class-memaccess)
1379         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_COMMENT             -Wno-comment)
1380         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_TYPEDEFS     -Wno-unused-local-typedefs)
1381
1382         if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "7.0"))
1383                 ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_IMPLICIT_FALLTHROUGH    -Wno-implicit-fallthrough)
1384         endif()
1385
1386         if(NOT APPLE)
1387                 ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1388         endif()
1389
1390 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
1391
1392         # strange, clang complains these are not supported, but then uses them.
1393         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1394         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1395         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1396         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1397         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1398         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1399         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1400         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1401         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1402
1403         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1404         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1405         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
1406         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
1407         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.
1408         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
1409         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
1410
1411         # gives too many unfixable warnings
1412         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
1413         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
1414
1415         # flags to undo strict flags
1416         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
1417         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
1418
1419         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
1420         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
1421         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
1422         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
1423         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
1424         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
1425         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
1426         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
1427
1428         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
1429         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
1430         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
1431         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
1432         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
1433         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_COMMENT -Wno-comment)
1434         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_TYPEDEFS -Wno-unused-local-typedefs)
1435
1436 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1437
1438         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1439         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1440         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1441
1442         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1443         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1444         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1445
1446         # disable numbered, false positives
1447         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556,858,597,177,1292,167,279,592,94,2722,3199")
1448         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556,858,597,177,1292,167,279,592,94,2722,3199")
1449 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
1450         # most msvc warnings are C & C++
1451         set(_WARNINGS
1452                 # warning level:
1453                 "/W3"
1454                 "/w34062"  # switch statement contains 'default' but no 'case' labels
1455                 "/w34115"  # 'type' : named type definition in parentheses
1456                 "/w34189"  # local variable is initialized but not referenced
1457                 # disable:
1458                 "/wd4018"  # signed/unsigned mismatch
1459                 "/wd4146"  # unary minus operator applied to unsigned type, result still unsigned
1460                 "/wd4065"  # switch statement contains 'default' but no 'case' labels
1461                 "/wd4127"  # conditional expression is constant
1462                 "/wd4181"  # qualifier applied to reference type; ignored
1463                 "/wd4200"  # zero-sized array in struct/union
1464                 "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
1465                 "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
1466                 "/wd4305"  # truncation from 'type1' to 'type2'
1467                 "/wd4800"  # forcing value to bool 'true' or 'false'
1468                 "/wd4828"  # The file contains a character that is illegal
1469                 "/wd4996"  # identifier was declared deprecated
1470                 # errors:
1471                 "/we4013"  # 'function' undefined; assuming extern returning int
1472                 "/we4133"  # incompatible pointer types
1473                 "/we4431"  # missing type specifier - int assumed
1474         )
1475
1476         if(MSVC_VERSION GREATER_EQUAL 1911)
1477                 # see https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5038?view=vs-2017
1478                 set(_WARNINGS "${_WARNINGS} /w35038") #order of initialisation in c++ constructors
1479         endif()
1480
1481         string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
1482         set(C_WARNINGS "${_WARNINGS}")
1483         set(CXX_WARNINGS "${_WARNINGS}")
1484         unset(_WARNINGS)
1485 endif()
1486
1487 # ensure python header is found since detection can fail, this could happen
1488 # with _any_ library but since we used a fixed python version this tends to
1489 # be most problematic.
1490 if(WITH_PYTHON)
1491         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1492                 message(FATAL_ERROR
1493                         "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1494                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1495                         "to a valid python include path. Containing "
1496                         "Python.h for python version \"${PYTHON_VERSION}\""
1497                 )
1498         endif()
1499
1500         if(WIN32 OR APPLE)
1501                 # Windows and macOS have this bundled with Python libraries.
1502         elseif((WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY) OR (WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE))
1503                 if(("${PYTHON_NUMPY_PATH}" STREQUAL "") OR (${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
1504                         find_python_package(numpy)
1505                         unset(PYTHON_NUMPY_INCLUDE_DIRS CACHE)
1506                         set(PYTHON_NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_PATH}/numpy/core/include CACHE PATH "Path to the include directory of the numpy module")
1507                         mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIRS)
1508                 endif()
1509         endif()
1510
1511         if(WIN32 OR APPLE)
1512                 # pass, we have this in lib/python/site-packages
1513         elseif(WITH_PYTHON_INSTALL_REQUESTS)
1514                 find_python_package(requests)
1515         endif()
1516 endif()
1517
1518 if(
1519         CMAKE_COMPILER_IS_GNUCC OR
1520         CMAKE_C_COMPILER_ID MATCHES "Clang" OR
1521         CMAKE_C_COMPILER_ID MATCHES "Intel"
1522 )
1523         # TODO(sergey): Do we want c++11 or gnu-c++11 here?
1524         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
1525 elseif(MSVC)
1526         # Nothing special is needed, C++11 features are available by default.
1527 else()
1528         message(FATAL_ERROR "Unknown compiler ${CMAKE_C_COMPILER_ID}, can't enable C++11 build")
1529 endif()
1530
1531 # Visual Studio has all standards it supports available by default
1532 # Clang on windows copies this behavior and does not support these switches
1533 if(
1534         CMAKE_COMPILER_IS_GNUCC OR
1535         (CMAKE_C_COMPILER_ID MATCHES "Clang" AND (NOT MSVC)) OR
1536         (CMAKE_C_COMPILER_ID MATCHES "Intel")
1537 )
1538         # Use C11 + GNU extensions, works with GCC, Clang, ICC
1539         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
1540 endif()
1541
1542 # Include warnings first, so its possible to disable them with user defined flags
1543 # eg: -Wno-uninitialized
1544 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
1545 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
1546
1547 # defined above, platform specific but shared names
1548 mark_as_advanced(
1549         CYCLES_OSL
1550         OSL_LIB_EXEC
1551         OSL_COMPILER
1552         OSL_LIB_COMP
1553         OSL_LIB_QUERY
1554         OSL_INCLUDE_DIR
1555 )
1556
1557 mark_as_advanced(
1558         LLVM_CONFIG
1559         LLVM_ROOT_DIR
1560         LLVM_LIBRARY
1561         LLVM_VERSION
1562 )
1563
1564 #-------------------------------------------------------------------------------
1565 # Global Defines
1566
1567 # better not set includes here but this debugging option is off by default.
1568 if(WITH_CXX_GUARDEDALLOC)
1569         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1570         add_definitions(-DWITH_CXX_GUARDEDALLOC)
1571 endif()
1572
1573 if(WITH_ASSERT_ABORT)
1574         add_definitions(-DWITH_ASSERT_ABORT)
1575 endif()
1576
1577 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1578 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1579
1580 #-----------------------------------------------------------------------------
1581 # Libraries
1582
1583 if(WITH_GTESTS)
1584         include(GTestTesting)
1585 endif()
1586
1587 if(WITH_BLENDER)
1588         add_subdirectory(intern)
1589         add_subdirectory(extern)
1590
1591         # source after intern and extern to gather all
1592         # internal and external library information first, for test linking
1593         add_subdirectory(source)
1594 elseif(WITH_CYCLES_STANDALONE)
1595         add_subdirectory(intern/cycles)
1596         add_subdirectory(extern/clew)
1597         if(WITH_CUDA_DYNLOAD)
1598                 add_subdirectory(extern/cuew)
1599         endif()
1600         if(NOT WITH_SYSTEM_GLEW)
1601                 add_subdirectory(extern/glew)
1602         endif()
1603 endif()
1604
1605 #-----------------------------------------------------------------------------
1606 # Blender Application
1607 if(WITH_BLENDER)
1608         add_subdirectory(source/creator)
1609 endif()
1610
1611
1612 #-----------------------------------------------------------------------------
1613 # Testing
1614 add_subdirectory(tests)
1615
1616
1617 #-----------------------------------------------------------------------------
1618 # CPack for generating packages
1619 include(build_files/cmake/packaging.cmake)
1620
1621 #-----------------------------------------------------------------------------
1622 # Use dynamic loading for OpenMP
1623 if(WITH_BLENDER)
1624         openmp_delayload(blender)
1625 endif()
1626
1627 #-----------------------------------------------------------------------------
1628 # Print Final Configuration
1629
1630 if(FIRST_RUN)
1631
1632         set(_config_msg "\nBlender Configuration\n=====================")
1633
1634         function(info_cfg_option
1635                 _setting
1636                 )
1637
1638                 set(_msg "  - ${_setting}")
1639                 string(LENGTH "${_msg}" _len)
1640                 while("32" GREATER "${_len}")
1641                         set(_msg "${_msg} ")
1642                         math(EXPR _len "${_len} + 1")
1643                 endwhile()
1644
1645                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
1646         endfunction()
1647
1648         function(info_cfg_text
1649                 _text
1650                 )
1651
1652                 set(_config_msg "${_config_msg}\n\n  ${_text}" PARENT_SCOPE)
1653         endfunction()
1654
1655         message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
1656         message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
1657
1658         info_cfg_text("Build Options:")
1659         info_cfg_option(WITH_BULLET)
1660         info_cfg_option(WITH_IK_SOLVER)
1661         info_cfg_option(WITH_IK_ITASC)
1662         info_cfg_option(WITH_OPENCOLLADA)
1663         info_cfg_option(WITH_FFTW3)
1664         info_cfg_option(WITH_INTERNATIONAL)
1665         info_cfg_option(WITH_INPUT_NDOF)
1666         info_cfg_option(WITH_CYCLES)
1667         info_cfg_option(WITH_FREESTYLE)
1668         info_cfg_option(WITH_OPENCOLORIO)
1669         info_cfg_option(WITH_OPENVDB)
1670         info_cfg_option(WITH_ALEMBIC)
1671
1672         info_cfg_text("Compiler Options:")
1673         info_cfg_option(WITH_BUILDINFO)
1674         info_cfg_option(WITH_OPENMP)
1675         info_cfg_option(WITH_RAYOPTIMIZATION)
1676
1677         info_cfg_text("System Options:")
1678         info_cfg_option(WITH_INSTALL_PORTABLE)
1679         info_cfg_option(WITH_X11_ALPHA)
1680         info_cfg_option(WITH_X11_XF86VMODE)
1681         info_cfg_option(WITH_X11_XFIXES)
1682         info_cfg_option(WITH_X11_XINPUT)
1683         info_cfg_option(WITH_MEM_JEMALLOC)
1684         info_cfg_option(WITH_MEM_VALGRIND)
1685         info_cfg_option(WITH_SYSTEM_GLEW)
1686
1687         info_cfg_text("Image Formats:")
1688         info_cfg_option(WITH_OPENIMAGEIO)
1689         info_cfg_option(WITH_IMAGE_CINEON)
1690         info_cfg_option(WITH_IMAGE_DDS)
1691         info_cfg_option(WITH_IMAGE_HDR)
1692         info_cfg_option(WITH_IMAGE_OPENEXR)
1693         info_cfg_option(WITH_IMAGE_OPENJPEG)
1694         info_cfg_option(WITH_IMAGE_TIFF)
1695
1696         info_cfg_text("Audio:")
1697         info_cfg_option(WITH_OPENAL)
1698         info_cfg_option(WITH_SDL)
1699         info_cfg_option(WITH_SDL_DYNLOAD)
1700         info_cfg_option(WITH_JACK)
1701         info_cfg_option(WITH_JACK_DYNLOAD)
1702         info_cfg_option(WITH_CODEC_AVI)
1703         info_cfg_option(WITH_CODEC_FFMPEG)
1704         info_cfg_option(WITH_CODEC_SNDFILE)
1705
1706         info_cfg_text("Compression:")
1707         info_cfg_option(WITH_LZMA)
1708         info_cfg_option(WITH_LZO)
1709
1710         info_cfg_text("Python:")
1711         info_cfg_option(WITH_PYTHON_INSTALL)
1712         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
1713         info_cfg_option(WITH_PYTHON_MODULE)
1714         info_cfg_option(WITH_PYTHON_SAFETY)
1715         if(APPLE)
1716                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
1717         endif()
1718
1719         info_cfg_text("Modifiers:")
1720         info_cfg_option(WITH_MOD_REMESH)
1721         info_cfg_option(WITH_MOD_FLUID)
1722         info_cfg_option(WITH_MOD_OCEANSIM)
1723
1724         info_cfg_text("OpenGL:")
1725         info_cfg_option(WITH_GLEW_ES)
1726         info_cfg_option(WITH_GL_EGL)
1727         info_cfg_option(WITH_GL_PROFILE_ES20)
1728         if(WIN32)
1729                 info_cfg_option(WITH_GL_ANGLE)
1730         endif()
1731
1732         info_cfg_text("")
1733
1734         message("${_config_msg}")
1735 endif()
1736
1737 if(0)
1738         print_all_vars()
1739 endif()