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