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