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