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