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