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