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