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