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