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