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