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