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