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