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