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