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