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