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 set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests CACHE INTERNAL "" FORCE)
119
120 #-----------------------------------------------------------------------------
121 # Set default config options
122
123 get_blender_version()
124
125
126 #-----------------------------------------------------------------------------
127 # Platform Specific Defaults
128
129 # list of var-names
130 set(_init_vars)
131
132 # initialize to ON
133 macro(option_defaults_init)
134         foreach(_var ${ARGV})
135                 set(${_var} ON)
136                 list(APPEND _init_vars "${_var}")
137         endforeach()
138         unset(_var)
139 endmacro()
140
141 # remove from namespace
142 macro(option_defaults_clear)
143         foreach(_var ${_init_vars})
144                 unset(${_var})
145         endforeach()
146         unset(_var)
147         unset(_init_vars)
148 endmacro()
149
150
151 # values to initialize WITH_****
152 option_defaults_init(
153         _init_BUILDINFO
154         _init_CODEC_FFMPEG
155         _init_CYCLES_OSL
156         _init_CYCLES_OPENSUBDIV
157         _init_IMAGE_OPENEXR
158         _init_INPUT_NDOF
159         _init_JACK
160         _init_OPENCOLLADA
161         _init_OPENCOLORIO
162         _init_SDL
163         _init_FFTW3
164         _init_OPENSUBDIV
165 )
166
167 # customize...
168 if(UNIX AND NOT APPLE)
169         # some of these libraries are problematic on Linux
170         # disable less important dependencies by default
171         set(_init_CODEC_FFMPEG                   OFF)
172         set(_init_CYCLES_OSL                     OFF)
173         set(_init_CYCLES_OPENSUBDIV              OFF)
174         set(_init_IMAGE_OPENEXR                  OFF)
175         set(_init_JACK                           OFF)
176         set(_init_OPENCOLLADA                    OFF)
177         set(_init_OPENCOLORIO                    OFF)
178         set(_init_SDL                            OFF)
179         set(_init_FFTW3                          OFF)
180         set(_init_OPENSUBDIV                     OFF)
181 elseif(WIN32)
182         set(_init_JACK                           OFF)
183 elseif(APPLE)
184         set(_init_JACK                           OFF)
185         set(_init_OPENSUBDIV                     OFF)
186 endif()
187
188
189 #-----------------------------------------------------------------------------
190 # Options
191
192 # First platform specific non-cached vars
193 if(UNIX AND NOT (APPLE OR HAIKU))
194         set(WITH_X11 ON)
195 endif()
196
197 # Blender internal features
198 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
199 mark_as_advanced(WITH_BLENDER)
200
201 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
202
203 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
204 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON)
205 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
206 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distributions see this as a security issue, rather than have them patch it, make a build option.
207
208 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)
209 mark_as_advanced(WITH_PYTHON_SAFETY)
210 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)
211 if(APPLE)
212         option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
213 endif()
214
215 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ${_init_BUILDINFO})
216 if(${CMAKE_VERSION} VERSION_LESS 2.8.8)
217         # add_library OBJECT arg unsupported
218         set(WITH_BUILDINFO OFF)
219 endif()
220 set(BUILDINFO_OVERRIDE_DATE "" CACHE STRING "Use instead of the current date for reproducable builds (empty string disables this option)")
221 set(BUILDINFO_OVERRIDE_TIME "" CACHE STRING "Use instead of the current time for reproducable builds (empty string disables this option)")
222 set(CPACK_OVERRIDE_PACKAGENAME "" CACHE STRING "Use instead of the standard packagename (empty string disables this option)")
223 mark_as_advanced(CPACK_OVERRIDE_PACKAGENAME)
224 mark_as_advanced(BUILDINFO_OVERRIDE_DATE)
225 mark_as_advanced(BUILDINFO_OVERRIDE_TIME)
226
227 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
228 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
229 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke, ocean sim, and audio effects)" ${_init_FFTW3})
230 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
231 option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
232 mark_as_advanced(WITH_SYSTEM_BULLET)
233 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ${_init_OPENCOLORIO})
234
235 # Compositor
236 option(WITH_COMPOSITOR         "Enable the tile based nodal compositor" ON)
237
238 option(WITH_OPENSUBDIV    "Enable OpenSubdiv for surface subdivision" _init_OPENSUBDIV)
239
240 option(WITH_OPENVDB       "Enable features relying on OpenVDB" OFF)
241 option(WITH_OPENVDB_BLOSC "Enable blosc compression for OpenVDB, only enable if OpenVDB was built with blosc support" OFF)
242 option(WITH_OPENVDB_3_ABI_COMPATIBLE "Assume OpenVDB library has been compiled with version 3 ABI compatibility" OFF)
243 mark_as_advanced(WITH_OPENVDB_3_ABI_COMPATIBLE)
244
245 # GHOST Windowing Library Options
246 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
247 mark_as_advanced(WITH_GHOST_DEBUG)
248
249 option(WITH_GHOST_SDL    "Enable building Blender against SDL for windowing rather than the native APIs" OFF)
250 mark_as_advanced(WITH_GHOST_SDL)
251
252 if(WITH_X11)
253         option(WITH_GHOST_XDND    "Enable drag'n'drop support on X11 using XDND protocol" ON)
254 endif()
255
256 # Misc...
257 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
258 mark_as_advanced(WITH_HEADLESS)
259
260 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
261 option(WITH_SYSTEM_AUDASPACE "Build with external audaspace library installed on the system (only enable if you know what you're doing!)" OFF)
262 mark_as_advanced(WITH_AUDASPACE)
263 mark_as_advanced(WITH_SYSTEM_AUDASPACE)
264
265 if(NOT WITH_AUDASPACE)
266         set(WITH_SYSTEM_AUDASPACE OFF)
267 endif()
268
269 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
270 if(UNIX AND NOT APPLE)
271         option(WITH_OPENMP_STATIC "Link OpenMP statically (only used by the release environment)" OFF)
272         mark_as_advanced(WITH_OPENMP_STATIC)
273 endif()
274
275 if(WITH_X11)
276         option(WITH_X11_XINPUT    "Enable X11 Xinput (tablet support and unicode input)"  ON)
277         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"                       ON)
278         option(WITH_X11_XFIXES    "Enable X11 XWayland cursor warping workaround"         ON)
279         option(WITH_X11_ALPHA     "Enable X11 transparent background"                     ON)
280 endif()
281
282 if(UNIX AND NOT APPLE)
283         option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" OFF)
284         option(WITH_SYSTEM_GLES "Use OpenGL ES library provided by the operating system"           ON)
285 else()
286         # not an option for other OS's
287         set(WITH_SYSTEM_GLEW OFF)
288         set(WITH_SYSTEM_GLES OFF)
289 endif()
290
291
292 # (unix defaults to System OpenJPEG On)
293 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" OFF)
294
295 if(UNIX AND NOT APPLE)
296         option(WITH_SYSTEM_EIGEN3 "Use the systems Eigen3 library" OFF)
297 endif()
298
299
300 # Modifiers
301 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
302 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
303 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
304 # option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)  # this is now only available in a branch
305 # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
306 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
307
308 # Image format support
309 option(WITH_OPENIMAGEIO         "Enable OpenImageIO Support (http://www.openimageio.org)" ON)
310 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ${_init_IMAGE_OPENEXR})
311 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
312 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
313 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
314 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
315 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
316
317 # Audio/Video format support
318 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
319 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ${_init_CODEC_FFMPEG})
320 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
321
322 # Alembic support
323 option(WITH_ALEMBIC             "Enable Alembic Support" OFF)
324 option(WITH_ALEMBIC_HDF5        "Enable Legacy Alembic Support (not officially supported)" OFF)
325
326 # 3D format support
327 # Disable opencollada when we don't have precompiled libs
328 option(WITH_OPENCOLLADA   "Enable OpenCollada Support (http://www.opencollada.org)" ${_init_OPENCOLLADA})
329
330 # Sound output
331 option(WITH_SDL           "Enable SDL for sound and joystick support" ${_init_SDL})
332 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
333 option(WITH_JACK          "Enable JACK Support (http://www.jackaudio.org)" ${_init_JACK})
334 if(UNIX AND NOT APPLE)
335         option(WITH_JACK_DYNLOAD  "Enable runtime dynamic JACK libraries loading" OFF)
336 endif()
337 if(UNIX AND NOT APPLE)
338         option(WITH_SDL_DYNLOAD  "Enable runtime dynamic SDL libraries loading" OFF)
339 endif()
340
341 # Compression
342 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
343 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
344 if(UNIX AND NOT APPLE)
345         option(WITH_SYSTEM_LZO    "Use the system LZO library" OFF)
346 endif()
347
348 # Camera/motion tracking
349 option(WITH_LIBMV         "Enable Libmv structure from motion library" ON)
350 option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." OFF)
351 mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
352
353 # Logging/unbit test libraries.
354 option(WITH_SYSTEM_GFLAGS   "Use system-wide Gflags instead of a bundled one" OFF)
355 option(WITH_SYSTEM_GLOG     "Use system-wide Glog instead of a bundled one" OFF)
356 mark_as_advanced(WITH_SYSTEM_GFLAGS)
357 mark_as_advanced(WITH_SYSTEM_GLOG)
358
359 # Freestyle
360 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
361
362 # Misc
363 if(WIN32)
364         option(WITH_INPUT_IME "Enable Input Method Editor (IME) for complex Asian character input" ON)
365 endif()
366 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ${_init_INPUT_NDOF})
367 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
368 if(UNIX AND NOT APPLE)
369         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
370         option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
371         if(WITH_STATIC_LIBS)
372                 option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
373                 mark_as_advanced(WITH_BOOST_ICU)
374         endif()
375 endif()
376
377 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
378 if(WITH_PYTHON_INSTALL OR (WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE))
379         set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
380         mark_as_advanced(PYTHON_NUMPY_PATH)
381         set(PYTHON_NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_PATH}/numpy/core/include CACHE PATH "Path to the include directory of the numpy module")
382         mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIRS)
383 endif()
384 if(WITH_PYTHON_INSTALL)
385         option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
386
387         if(UNIX AND NOT APPLE)
388                 option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
389                 set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
390                 mark_as_advanced(PYTHON_REQUESTS_PATH)
391         endif()
392 endif()
393
394 option(WITH_CPU_SSE              "Enable SIMD instruction if they're detected on the host machine" ON)
395 mark_as_advanced(WITH_CPU_SSE)
396
397 # Cycles
398 option(WITH_CYCLES                                      "Enable Cycles Render Engine" ON)
399 option(WITH_CYCLES_STANDALONE           "Build Cycles standalone application" OFF)
400 option(WITH_CYCLES_STANDALONE_GUI       "Build Cycles standalone with GUI" OFF)
401 option(WITH_CYCLES_OSL                          "Build Cycles with OSL support" ${_init_CYCLES_OSL})
402 option(WITH_CYCLES_OPENSUBDIV           "Build Cycles with OpenSubdiv support" ${_init_CYCLES_OPENSUBDIV})
403 option(WITH_CYCLES_CUDA_BINARIES        "Build Cycles CUDA binaries" OFF)
404 option(WITH_CYCLES_CUBIN_COMPILER       "Build cubins with nvrtc based compiler instead of nvcc" OFF)
405 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")
406 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
407 unset(PLATFORM_DEFAULT)
408 option(WITH_CYCLES_LOGGING      "Build Cycles with logging support" ON)
409 option(WITH_CYCLES_DEBUG        "Build Cycles with extra debug capabilities" OFF)
410 option(WITH_CYCLES_NATIVE_ONLY  "Build Cycles with native kernel only (which fits current CPU, use for development only)" OFF)
411 mark_as_advanced(WITH_CYCLES_CUBIN_COMPILER)
412 mark_as_advanced(WITH_CYCLES_LOGGING)
413 mark_as_advanced(WITH_CYCLES_DEBUG)
414 mark_as_advanced(WITH_CYCLES_NATIVE_ONLY)
415
416 option(WITH_CYCLES_DEVICE_CUDA                          "Enable Cycles CUDA compute support" ON)
417 option(WITH_CYCLES_DEVICE_OPENCL                        "Enable Cycles OpenCL compute support" ON)
418 option(WITH_CYCLES_NETWORK                              "Enable Cycles compute over network support (EXPERIMENTAL and unfinished)" OFF)
419 mark_as_advanced(WITH_CYCLES_DEVICE_CUDA)
420 mark_as_advanced(WITH_CYCLES_DEVICE_OPENCL)
421 mark_as_advanced(WITH_CYCLES_NETWORK)
422
423 option(WITH_CUDA_DYNLOAD "Dynamically load CUDA libraries at runtime" ON)
424 mark_as_advanced(WITH_CUDA_DYNLOAD)
425
426 # LLVM
427 option(WITH_LLVM                                        "Use LLVM" OFF)
428 if(APPLE)
429         option(LLVM_STATIC                                      "Link with LLVM static libraries" ON) # we prefer static llvm build on Apple, dyn build possible though
430 else()
431         option(LLVM_STATIC                                      "Link with LLVM static libraries" OFF)
432 endif()
433 mark_as_advanced(LLVM_STATIC)
434
435 # disable for now, but plan to support on all platforms eventually
436 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" ON)
437 mark_as_advanced(WITH_MEM_JEMALLOC)
438
439 # currently only used for BLI_mempool
440 option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
441 mark_as_advanced(WITH_MEM_VALGRIND)
442
443 # Debug
444 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
445 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
446
447 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" ON)
448 mark_as_advanced(WITH_ASSERT_ABORT)
449
450 option(WITH_BOOST                                       "Enable features depending on boost" ON)
451
452 # Unit testsing
453 option(WITH_GTESTS "Enable GTest unit testing" OFF)
454 option(WITH_OPENGL_RENDER_TESTS "Enable OpenGL render related unit testing (Experimental)" OFF)
455 option(WITH_OPENGL_DRAW_TESTS "Enable OpenGL UI drawing related unit testing (Experimental)" OFF)
456
457
458 # Documentation
459 if(UNIX AND NOT APPLE)
460         option(WITH_DOC_MANPAGE "Create a manual page (Unix manpage)" OFF)
461 endif()
462
463
464 # OpenGL
465
466 option(WITH_OPENGL              "When off limits visibility of the opengl headers to just bf_gpu and gawain (temporary option for development purposes)" ON)
467 option(WITH_GLEW_ES             "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
468 option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)"       OFF)
469 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (thru either EGL or the AGL/WGL/XGL 'es20' profile)"                                  OFF)
470
471 mark_as_advanced(
472         WITH_OPENGL
473         WITH_GLEW_ES
474         WITH_GL_EGL
475         WITH_GL_PROFILE_ES20
476 )
477
478 if(WIN32)
479         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)
480         mark_as_advanced(WITH_GL_ANGLE)
481 endif()
482
483 if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
484         message(WARNING Ignoring WITH_SYSTEM_GLEW and using WITH_GLEW_ES)
485         set(WITH_SYSTEM_GLEW OFF)
486 endif()
487
488 if(WIN32)
489         getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
490         set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
491 endif()
492
493 # Compiler toolchain
494 if(CMAKE_COMPILER_IS_GNUCC)
495         option(WITH_LINKER_GOLD "Use ld.gold linker which is usually faster than ld.bfd" ON)
496         mark_as_advanced(WITH_LINKER_GOLD)
497 endif()
498
499 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
500         option(WITH_COMPILER_ASAN "Build and link against address sanitizer (only for Debug & RelWithDebInfo targets)." OFF)
501         mark_as_advanced(WITH_COMPILER_ASAN)
502
503         if(WITH_COMPILER_ASAN)
504                 set(_asan_defaults "\
505 -fsanitize=address \
506 -fsanitize=bool \
507 -fsanitize=bounds \
508 -fsanitize=enum \
509 -fsanitize=float-cast-overflow \
510 -fsanitize=float-divide-by-zero \
511 -fsanitize=nonnull-attribute \
512 -fsanitize=returns-nonnull-attribute \
513 -fsanitize=signed-integer-overflow \
514 -fsanitize=undefined \
515 -fsanitize=vla-bound \
516 -fno-sanitize=alignment \
517 ")
518
519                 if(NOT MSVC) # not all sanitizers are supported with clang-cl, these two however are very vocal about it
520                         set(_asan_defaults "${_asan_defaults} -fsanitize=leak -fsanitize=object-size" )
521                 endif()
522                 set(COMPILER_ASAN_CFLAGS "${_asan_defaults}" CACHE STRING "C flags for address sanitizer")
523                 mark_as_advanced(COMPILER_ASAN_CFLAGS)
524                 set(COMPILER_ASAN_CXXFLAGS "${_asan_defaults}" CACHE STRING "C++ flags for address sanitizer")
525                 mark_as_advanced(COMPILER_ASAN_CXXFLAGS)
526
527                 unset(_asan_defaults)
528
529                 if(NOT MSVC)
530                         find_library(COMPILER_ASAN_LIBRARY asan ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
531                 else()
532                         find_library( COMPILER_ASAN_LIBRARY NAMES clang_rt.asan-x86_64
533                                 PATHS
534                                 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LLVM\\LLVM;]/lib/clang/7.0.0/lib/windows
535                                 [HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LLVM\\LLVM;]/lib/clang/6.0.0/lib/windows
536                         )
537                 endif()
538                 mark_as_advanced(COMPILER_ASAN_LIBRARY)
539         endif()
540 endif()
541
542 # Dependency graph
543 option(WITH_LEGACY_DEPSGRAPH "Build Blender with legacy dependency graph" ON)
544 mark_as_advanced(WITH_LEGACY_DEPSGRAPH)
545
546 if(WIN32)
547         # Use hardcoded paths or find_package to find externals
548         option(WITH_WINDOWS_FIND_MODULES "Use find_package to locate libraries" OFF)
549         mark_as_advanced(WITH_WINDOWS_FIND_MODULES)
550
551         option(WITH_WINDOWS_CODESIGN "Use signtool to sign the final binary." OFF)
552         mark_as_advanced(WITH_WINDOWS_CODESIGN)
553
554         set(WINDOWS_CODESIGN_PFX CACHE FILEPATH  "Path to pfx file to use for codesigning.")
555         mark_as_advanced(WINDOWS_CODESIGN_PFX)
556
557         set(WINDOWS_CODESIGN_PFX_PASSWORD CACHE STRING  "password for pfx file used for codesigning.")
558         mark_as_advanced(WINDOWS_CODESIGN_PFX_PASSWORD)
559
560         option(WINDOWS_USE_VISUAL_STUDIO_FOLDERS "Organize the visual studio project according to source folders." ON)
561         mark_as_advanced(WINDOWS_USE_VISUAL_STUDIO_FOLDERS)
562 endif()
563
564 # avoid using again
565 option_defaults_clear()
566
567 # end option(...)
568
569
570
571 # By default we want to install to the directory we are compiling our executables
572 # unless specified otherwise, which we currently do not allow
573 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
574         if(WIN32)
575                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
576         elseif(APPLE)
577                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
578         else()
579                 if(WITH_INSTALL_PORTABLE)
580                         set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH} CACHE PATH "default install path" FORCE)
581                 endif()
582         endif()
583 endif()
584
585
586
587 # Apple
588
589 if(APPLE)
590         include(platform_apple_xcode)
591 endif()
592
593
594 #-----------------------------------------------------------------------------
595 # Check for conflicting/unsupported configurations
596
597 if(NOT WITH_BLENDER AND NOT WITH_CYCLES_STANDALONE)
598         message(FATAL_ERROR
599                 "At least one of WITH_BLENDER or WITH_CYCLES_STANDALONE "
600                 "must be enabled, nothing to do!"
601         )
602 endif()
603
604 if(NOT WITH_CXX11)
605         if(WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE)
606                 message(FATAL_ERROR "WITH_AUDASPACE requires WITH_CXX11")
607         endif()
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 dont 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) # dont 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 endianess 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         if(WITH_SYSTEM_OPENJPEG)
968                 # dealt with above
969                 set(OPENJPEG_DEFINES "")
970         else()
971                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
972                 set(OPENJPEG_DEFINES "-DOPJ_STATIC")
973         endif()
974         # Special handling of Windows platform where openjpeg is always static.
975         if(WIN32)
976                 set(OPENJPEG_DEFINES "-DOPJ_STATIC")
977         endif()
978 endif()
979
980 if(NOT WITH_SYSTEM_EIGEN3)
981         set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3)
982 endif()
983
984 #-----------------------------------------------------------------------------
985 # Configure OpenGL.
986
987 find_package(OpenGL)
988 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
989
990 if(WITH_OPENGL)
991         add_definitions(-DWITH_OPENGL)
992 endif()
993
994 if(WITH_SYSTEM_GLES)
995         find_package_wrapper(OpenGLES)
996 endif()
997
998 if(WITH_GL_PROFILE_ES20)
999         if(WITH_SYSTEM_GLES)
1000                 if(NOT OPENGLES_LIBRARY)
1001                         message(FATAL_ERROR
1002                                 "Unable to find OpenGL ES libraries. "
1003                                 "Install them or disable WITH_SYSTEM_GLES."
1004                         )
1005                 endif()
1006
1007                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_LIBRARY)
1008
1009         else()
1010                 set(OPENGLES_LIBRARY "" CACHE FILEPATH "OpenGL ES 2.0 library file")
1011                 mark_as_advanced(OPENGLES_LIBRARY)
1012
1013                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
1014
1015                 if(NOT OPENGLES_LIBRARY)
1016                         message(FATAL_ERROR
1017                                 "To compile WITH_GL_EGL you need to set OPENGLES_LIBRARY "
1018                                 "to the file path of an OpenGL ES 2.0 library."
1019                         )
1020                 endif()
1021
1022         endif()
1023
1024         if(WIN32)
1025                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
1026
1027                 set(OPENGLES_DLL "" CACHE FILEPATH "OpenGL ES 2.0 redistributable DLL file")
1028                 mark_as_advanced(OPENGLES_DLL)
1029
1030                 if(NOT OPENGLES_DLL)
1031                         message(FATAL_ERROR
1032                                 "To compile WITH_GL_PROFILE_ES20 you need to set OPENGLES_DLL to the file "
1033                                 "path of an OpenGL ES 2.0 runtime dynamic link library (DLL)."
1034                         )
1035                 endif()
1036
1037                 if(WITH_GL_ANGLE)
1038                         list(APPEND GL_DEFINITIONS -DWITH_ANGLE)
1039
1040                         set(D3DCOMPILER_DLL "" CACHE FILEPATH "Direct3D Compiler redistributable DLL file (needed by ANGLE)")
1041
1042                         get_filename_component(D3DCOMPILER_FILENAME "${D3DCOMPILER_DLL}" NAME)
1043                         list(APPEND GL_DEFINITIONS "-DD3DCOMPILER=\"\\\"${D3DCOMPILER_FILENAME}\\\"\"")
1044
1045                         mark_as_advanced(D3DCOMPILER_DLL)
1046
1047                         if(D3DCOMPILER_DLL STREQUAL "")
1048                                 message(FATAL_ERROR
1049                                         "To compile WITH_GL_ANGLE you need to set D3DCOMPILER_DLL to the file "
1050                                         "path of a copy of the DirectX redistributable DLL file: D3DCompiler_46.dll"
1051                                 )
1052                         endif()
1053
1054                 endif()
1055
1056         endif()
1057
1058 else()
1059         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_gl_LIBRARY}")
1060
1061 endif()
1062
1063 if(WITH_GL_EGL)
1064         list(APPEND GL_DEFINITIONS -DWITH_GL_EGL)
1065
1066         if(WITH_SYSTEM_GLES)
1067                 if(NOT OPENGLES_EGL_LIBRARY)
1068                         message(FATAL_ERROR
1069                                 "Unable to find OpenGL ES libraries. "
1070                                 "Install them or disable WITH_SYSTEM_GLES."
1071                         )
1072                 endif()
1073
1074                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_EGL_LIBRARY)
1075
1076         else()
1077                 set(OPENGLES_EGL_LIBRARY "" CACHE FILEPATH "EGL library file")
1078                 mark_as_advanced(OPENGLES_EGL_LIBRARY)
1079
1080                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}" "${OPENGLES_EGL_LIBRARY}")
1081
1082                 if(NOT OPENGLES_EGL_LIBRARY)
1083                         message(FATAL_ERROR
1084                                 "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY "
1085                                 "to the file path of an EGL library."
1086                         )
1087                 endif()
1088
1089         endif()
1090
1091         if(WIN32)
1092                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
1093
1094                 set(OPENGLES_EGL_DLL "" CACHE FILEPATH "EGL redistributable DLL file")
1095                 mark_as_advanced(OPENGLES_EGL_DLL)
1096
1097                 if(NOT OPENGLES_EGL_DLL)
1098                         message(FATAL_ERROR
1099                                 "To compile WITH_GL_EGL you need to set OPENGLES_EGL_DLL "
1100                                 "to the file path of an EGL runtime dynamic link library (DLL)."
1101                         )
1102                 endif()
1103
1104         endif()
1105
1106 endif()
1107
1108 if(WITH_GL_PROFILE_ES20)
1109         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_ES20)
1110 else()
1111         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_CORE)
1112 endif()
1113
1114 if(WITH_GL_EGL)
1115         list(APPEND GL_DEFINITIONS -DWITH_EGL)
1116 endif()
1117
1118 #-----------------------------------------------------------------------------
1119 # Configure OpenMP.
1120 if(WITH_OPENMP)
1121         find_package(OpenMP)
1122         if(OPENMP_FOUND)
1123                 if(NOT WITH_OPENMP_STATIC)
1124                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1125                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1126                 else()
1127                         # Typically avoid adding flags as defines but we can't
1128                         # pass OpenMP flags to the linker for static builds, meaning
1129                         # we can't add any OpenMP related flags to CFLAGS variables
1130                         # since they're passed to the linker as well.
1131                         add_definitions("${OpenMP_C_FLAGS}")
1132
1133                         find_library_static(OpenMP_LIBRARIES gomp ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
1134                 endif()
1135         else()
1136                 set(WITH_OPENMP OFF)
1137         endif()
1138
1139         mark_as_advanced(
1140                 OpenMP_C_FLAGS
1141                 OpenMP_CXX_FLAGS
1142         )
1143 endif()
1144
1145 #-----------------------------------------------------------------------------
1146 # Configure GLEW
1147
1148 if(WITH_SYSTEM_GLEW)
1149         find_package(GLEW)
1150
1151         # Note: There is an assumption here that the system GLEW is not a static library.
1152
1153         if(NOT GLEW_FOUND)
1154                 message(FATAL_ERROR "GLEW is required to build Blender. Install it or disable WITH_SYSTEM_GLEW.")
1155         endif()
1156
1157         set(BLENDER_GLEW_LIBRARIES ${GLEW_LIBRARY})
1158 else()
1159         if(WITH_GLEW_ES)
1160                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew-es/include")
1161
1162                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC -DWITH_GLEW_ES)
1163
1164                 # These definitions remove APIs from glew.h, making GLEW smaller, and catching unguarded API usage
1165                 if(WITH_GL_PROFILE_ES20)
1166                         list(APPEND GL_DEFINITIONS -DGLEW_ES_ONLY)
1167                 else()
1168                         # No ES functions are needed
1169                         list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
1170                 endif()
1171
1172                 if(WITH_GL_PROFILE_ES20)
1173                         if(WITH_GL_EGL)
1174                                 list(APPEND GL_DEFINITIONS -DGLEW_USE_LIB_ES20)
1175                         endif()
1176
1177                         # ToDo: This is an experiment to eliminate ES 1 symbols,
1178                         # GLEW doesn't really properly provide this level of control
1179                         # (for example, without modification it eliminates too many symbols)
1180                         # so there are lots of modifications to GLEW to make this work,
1181                         # and no attempt to make it work beyond Blender at this point.
1182                         list(APPEND GL_DEFINITIONS -DGL_ES_VERSION_1_0=0 -DGL_ES_VERSION_CL_1_1=0 -DGL_ES_VERSION_CM_1_1=0)
1183                 endif()
1184
1185                 if(WITH_GL_EGL)
1186                         list(APPEND GL_DEFINITIONS -DGLEW_INC_EGL)
1187                 endif()
1188
1189                 set(BLENDER_GLEW_LIBRARIES extern_glew_es bf_intern_glew_mx)
1190
1191         else()
1192                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1193
1194                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC)
1195
1196                 # This won't affect the non-experimental glew library,
1197                 # but is used for conditional compilation elsewhere.
1198                 list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
1199
1200                 set(BLENDER_GLEW_LIBRARIES extern_glew)
1201
1202         endif()
1203
1204 endif()
1205
1206 list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
1207
1208 #-----------------------------------------------------------------------------
1209 # Configure Bullet
1210
1211 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
1212         find_package(Bullet)
1213         if(NOT BULLET_FOUND)
1214                 set(WITH_BULLET OFF)
1215         endif()
1216 else()
1217         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
1218         # set(BULLET_LIBRARIES "")
1219 endif()
1220
1221 #-----------------------------------------------------------------------------
1222 # Configure Python.
1223
1224 if(WITH_PYTHON_MODULE)
1225         add_definitions(-DPy_ENABLE_SHARED)
1226 endif()
1227
1228 #-----------------------------------------------------------------------------
1229 # Configure GLog/GFlags
1230
1231 if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING))
1232         if(WITH_SYSTEM_GFLAGS)
1233                 find_package(Gflags)
1234                 if(NOT GFLAGS_FOUND)
1235                         message(FATAL_ERROR "System wide Gflags is requested but was not found")
1236                 endif()
1237                 # FindGflags does not define this, and we are not even sure what to use here.
1238                 set(GFLAGS_DEFINES)
1239         else()
1240                 set(GFLAGS_DEFINES
1241                         -DGFLAGS_DLL_DEFINE_FLAG=
1242                         -DGFLAGS_DLL_DECLARE_FLAG=
1243                         -DGFLAGS_DLL_DECL=
1244                 )
1245                 set(GFLAGS_NAMESPACE "gflags")
1246                 set(GFLAGS_LIBRARIES extern_gflags)
1247                 set(GFLAGS_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/extern/gflags/src")
1248         endif()
1249
1250         if(WITH_SYSTEM_GLOG)
1251                 find_package(Glog)
1252                 if(NOT GLOG_FOUND)
1253                         message(FATAL_ERROR "System wide Glog is requested but was not found")
1254                 endif()
1255                 # FindGlog does not define this, and we are not even sure what to use here.
1256                 set(GLOG_DEFINES)
1257         else()
1258                 set(GLOG_DEFINES
1259                         -DGOOGLE_GLOG_DLL_DECL=
1260                 )
1261                 set(GLOG_LIBRARIES extern_glog)
1262                 if(WIN32)
1263                         set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/src/windows)
1264                 else()
1265                         set(GLOG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/glog/include)
1266                 endif()
1267         endif()
1268 endif()
1269
1270 #-----------------------------------------------------------------------------
1271 # Configure Ceres
1272
1273 if(WITH_LIBMV)
1274         # We always have C++11 which includes unordered_map.
1275         set(CERES_DEFINES -DCERES_STD_UNORDERED_MAP)
1276 endif()
1277
1278 #-----------------------------------------------------------------------------
1279 # Extra compile flags
1280
1281 if(CMAKE_COMPILER_IS_GNUCC)
1282
1283         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1284         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1285         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1286         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1287         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_VLA -Werror=vla)
1288         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1289         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1290         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1291         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1292         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1293         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1294         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1295         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1296         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
1297         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
1298         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1299         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
1300         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1301         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1302         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
1303         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_FORMAT_SIGN -Wformat-signedness)
1304         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_RESTRICT -Wrestrict)
1305
1306         # gcc 4.2 gives annoying warnings on every file with this
1307         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1308                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
1309         endif()
1310
1311         # versions before gcc4.6 give many BLI_math warnings
1312         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
1313                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
1314                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
1315         endif()
1316
1317         # versions before gcc4.8 include global name-space.
1318         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.8")
1319                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_SHADOW -Wshadow)
1320         endif()
1321
1322         # disable because it gives warnings for printf() & friends.
1323         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1324
1325         if(NOT APPLE)
1326                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1327         endif()
1328
1329         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1330         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1331         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1332         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
1333         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1334         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1335         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1336         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
1337         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1338         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1339         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1340         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1341         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_POINTER_ARITH -Wpointer-arith)
1342         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_PARAMETER -Wunused-parameter)
1343         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_WRITE_STRINGS -Wwrite-strings)
1344         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1345         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_FORMAT_SIGN -Wformat-signedness)
1346         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_RESTRICT -Wrestrict)
1347
1348         # gcc 4.2 gives annoying warnings on every file with this
1349         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1350                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
1351         endif()
1352
1353         # causes too many warnings
1354         if(NOT APPLE)
1355                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1356                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
1357         endif()
1358
1359         # Use 'ATTR_FALLTHROUGH' macro to suppress.
1360         if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "7.0"))
1361                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_IMPLICIT_FALLTHROUGH -Wimplicit-fallthrough=5)
1362                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_IMPLICIT_FALLTHROUGH -Wimplicit-fallthrough=5)
1363         endif()
1364
1365         # flags to undo strict flags
1366         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
1367         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
1368         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION         -Wno-unused-function)
1369         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_TYPE_LIMITS             -Wno-type-limits)
1370         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_INT_IN_BOOL_CONTEXT     -Wno-int-in-bool-context)
1371         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_FORMAT                  -Wno-format)
1372         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_SWITCH                  -Wno-switch)
1373
1374         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_CLASS_MEMACCESS     -Wno-class-memaccess)
1375
1376         if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "7.0"))
1377                 ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_IMPLICIT_FALLTHROUGH    -Wno-implicit-fallthrough)
1378         endif()
1379
1380         if(NOT APPLE)
1381                 ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1382         endif()
1383
1384 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
1385
1386         # strange, clang complains these are not supported, but then uses them.
1387         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1388         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1389         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1390         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1391         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1392         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1393         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1394         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1395         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1396
1397         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1398         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1399         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
1400         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
1401         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.
1402         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
1403         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
1404
1405         # gives too many unfixable warnings
1406         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
1407         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
1408
1409         # flags to undo strict flags
1410         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
1411         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
1412
1413         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
1414         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
1415         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
1416         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
1417         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
1418         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
1419         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
1420         ADD_CHECK_C_COMPILER_FLAG(C_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
1421
1422         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
1423         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
1424         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
1425         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
1426         ADD_CHECK_CXX_COMPILER_FLAG(CXX_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
1427
1428 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1429
1430         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1431         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1432         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1433
1434         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1435         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1436         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1437
1438         # disable numbered, false positives
1439         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556,858,597,177,1292,167,279,592,94,2722,3199")
1440         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556,858,597,177,1292,167,279,592,94,2722,3199")
1441 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
1442         # most msvc warnings are C & C++
1443         set(_WARNINGS
1444                 # warning level:
1445                 "/W3"
1446                 "/w34062"  # switch statement contains 'default' but no 'case' labels
1447                 # disable:
1448                 "/wd4018"  # signed/unsigned mismatch
1449                 "/wd4146"  # unary minus operator applied to unsigned type, result still unsigned
1450                 "/wd4065"  # switch statement contains 'default' but no 'case' labels
1451                 "/wd4127"  # conditional expression is constant
1452                 "/wd4181"  # qualifier applied to reference type; ignored
1453                 "/wd4200"  # zero-sized array in struct/union
1454                 "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
1455                 "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
1456                 "/wd4305"  # truncation from 'type1' to 'type2'
1457                 "/wd4800"  # forcing value to bool 'true' or 'false'
1458                 "/wd4828"  # The file contains a character that is illegal
1459                 # errors:
1460                 "/we4013"  # 'function' undefined; assuming extern returning int
1461                 "/we4133"  # incompatible pointer types
1462                 "/we4431"  # missing type specifier - int assumed
1463         )
1464
1465         string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
1466         set(C_WARNINGS "${_WARNINGS}")
1467         set(CXX_WARNINGS "${_WARNINGS}")
1468         unset(_WARNINGS)
1469 endif()
1470
1471 # ensure python header is found since detection can fail, this could happen
1472 # with _any_ library but since we used a fixed python version this tends to
1473 # be most problematic.
1474 if(WITH_PYTHON)
1475         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1476                 message(FATAL_ERROR
1477                         "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1478                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1479                         "to a valid python include path. Containing "
1480                         "Python.h for python version \"${PYTHON_VERSION}\""
1481                 )
1482         endif()
1483
1484         if(WIN32)
1485                 # pass, we have this in an archive to extract
1486         elseif((WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY) OR (WITH_AUDASPACE AND NOT WITH_SYSTEM_AUDASPACE))
1487                 if(("${PYTHON_NUMPY_PATH}" STREQUAL "") OR (${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
1488                         find_python_package(numpy)
1489                         unset(PYTHON_NUMPY_INCLUDE_DIRS CACHE)
1490                         set(PYTHON_NUMPY_INCLUDE_DIRS ${PYTHON_NUMPY_PATH}/numpy/core/include CACHE PATH "Path to the include directory of the numpy module")
1491                         mark_as_advanced(PYTHON_NUMPY_INCLUDE_DIRS)
1492                 endif()
1493         endif()
1494
1495         if(WIN32 OR APPLE)
1496                 # pass, we have this in lib/python/site-packages
1497         elseif(WITH_PYTHON_INSTALL_REQUESTS)
1498                 find_python_package(requests)
1499         endif()
1500 endif()
1501
1502 if(
1503         CMAKE_COMPILER_IS_GNUCC OR
1504         CMAKE_C_COMPILER_ID MATCHES "Clang" OR
1505         CMAKE_C_COMPILER_ID MATCHES "Intel"
1506 )
1507         # TODO(sergey): Do we want c++11 or gnu-c++11 here?
1508         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
1509 elseif(MSVC)
1510         # Nothing special is needed, C++11 features are available by default.
1511 else()
1512         message(FATAL_ERROR "Unknown compiler ${CMAKE_C_COMPILER_ID}, can't enable C++11 build")
1513 endif()
1514
1515 # Visual Studio has all standards it supports available by default
1516 # Clang on windows copies this behavior and does not support these switches
1517 if(
1518         CMAKE_COMPILER_IS_GNUCC OR
1519         (CMAKE_C_COMPILER_ID MATCHES "Clang" AND (NOT MSVC)) OR
1520         (CMAKE_C_COMPILER_ID MATCHES "Intel")
1521 )
1522         # Use C99 + GNU extensions, works with GCC, Clang, ICC
1523         if(WITH_C11)
1524                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
1525         else()
1526                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
1527         endif()
1528 endif()
1529
1530 # Include warnings first, so its possible to disable them with user defined flags
1531 # eg: -Wno-uninitialized
1532 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
1533 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
1534
1535 # defined above, platform specific but shared names
1536 mark_as_advanced(
1537         CYCLES_OSL
1538         OSL_LIB_EXEC
1539         OSL_COMPILER
1540         OSL_LIB_COMP
1541         OSL_LIB_QUERY
1542         OSL_INCLUDE_DIR
1543 )
1544
1545 mark_as_advanced(
1546         LLVM_CONFIG
1547         LLVM_ROOT_DIR
1548         LLVM_LIBRARY
1549         LLVM_VERSION
1550 )
1551
1552 #-------------------------------------------------------------------------------
1553 # Global Defines
1554
1555 # better not set includes here but this debugging option is off by default.
1556 if(WITH_CXX_GUARDEDALLOC)
1557         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1558         add_definitions(-DWITH_CXX_GUARDEDALLOC)
1559 endif()
1560
1561 if(WITH_ASSERT_ABORT)
1562         add_definitions(-DWITH_ASSERT_ABORT)
1563 endif()
1564
1565 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1566 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1567
1568 #-----------------------------------------------------------------------------
1569 # Libraries
1570
1571 if(WITH_GTESTS)
1572         include(GTestTesting)
1573 endif()
1574
1575 if(WITH_BLENDER)
1576         add_subdirectory(intern)
1577         add_subdirectory(extern)
1578
1579         # source after intern and extern to gather all
1580         # internal and external library information first, for test linking
1581         add_subdirectory(source)
1582 elseif(WITH_CYCLES_STANDALONE)
1583         add_subdirectory(intern/cycles)
1584         add_subdirectory(extern/clew)
1585         if(WITH_CUDA_DYNLOAD)
1586                 add_subdirectory(extern/cuew)
1587         endif()
1588         if(NOT WITH_SYSTEM_GLEW)
1589                 add_subdirectory(extern/glew)
1590         endif()
1591 endif()
1592
1593 #-----------------------------------------------------------------------------
1594 # Blender Application
1595 if(WITH_BLENDER)
1596         add_subdirectory(source/creator)
1597 endif()
1598
1599
1600 #-----------------------------------------------------------------------------
1601 # Testing
1602 add_subdirectory(tests)
1603
1604
1605 #-----------------------------------------------------------------------------
1606 # CPack for generating packages
1607 include(build_files/cmake/packaging.cmake)
1608
1609 #-----------------------------------------------------------------------------
1610 # Use dynamic loading for OpenMP
1611 if(WITH_BLENDER)
1612         openmp_delayload(blender)
1613 endif()
1614
1615 #-----------------------------------------------------------------------------
1616 # Print Final Configuration
1617
1618 if(FIRST_RUN)
1619
1620         set(_config_msg "\nBlender Configuration\n=====================")
1621
1622         function(info_cfg_option
1623                 _setting
1624                 )
1625
1626                 set(_msg "  - ${_setting}")
1627                 string(LENGTH "${_msg}" _len)
1628                 while("32" GREATER "${_len}")
1629                         set(_msg "${_msg} ")
1630                         math(EXPR _len "${_len} + 1")
1631                 endwhile()
1632
1633                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
1634         endfunction()
1635
1636         function(info_cfg_text
1637                 _text
1638                 )
1639
1640                 set(_config_msg "${_config_msg}\n\n  ${_text}" PARENT_SCOPE)
1641         endfunction()
1642
1643         message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
1644         message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
1645
1646         info_cfg_text("Build Options:")
1647         info_cfg_option(WITH_BULLET)
1648         info_cfg_option(WITH_IK_SOLVER)
1649         info_cfg_option(WITH_IK_ITASC)
1650         info_cfg_option(WITH_OPENCOLLADA)
1651         info_cfg_option(WITH_FFTW3)
1652         info_cfg_option(WITH_INTERNATIONAL)
1653         info_cfg_option(WITH_INPUT_NDOF)
1654         info_cfg_option(WITH_CYCLES)
1655         info_cfg_option(WITH_FREESTYLE)
1656         info_cfg_option(WITH_OPENCOLORIO)
1657         info_cfg_option(WITH_OPENVDB)
1658         info_cfg_option(WITH_ALEMBIC)
1659
1660         info_cfg_text("Compiler Options:")
1661         info_cfg_option(WITH_BUILDINFO)
1662         info_cfg_option(WITH_OPENMP)
1663         info_cfg_option(WITH_RAYOPTIMIZATION)
1664
1665         info_cfg_text("System Options:")
1666         info_cfg_option(WITH_INSTALL_PORTABLE)
1667         info_cfg_option(WITH_X11_ALPHA)
1668         info_cfg_option(WITH_X11_XF86VMODE)
1669         info_cfg_option(WITH_X11_XFIXES)
1670         info_cfg_option(WITH_X11_XINPUT)
1671         info_cfg_option(WITH_MEM_JEMALLOC)
1672         info_cfg_option(WITH_MEM_VALGRIND)
1673         info_cfg_option(WITH_SYSTEM_GLEW)
1674         info_cfg_option(WITH_SYSTEM_OPENJPEG)
1675
1676         info_cfg_text("Image Formats:")
1677         info_cfg_option(WITH_OPENIMAGEIO)
1678         info_cfg_option(WITH_IMAGE_CINEON)
1679         info_cfg_option(WITH_IMAGE_DDS)
1680         info_cfg_option(WITH_IMAGE_HDR)
1681         info_cfg_option(WITH_IMAGE_OPENEXR)
1682         info_cfg_option(WITH_IMAGE_OPENJPEG)
1683         info_cfg_option(WITH_IMAGE_TIFF)
1684
1685         info_cfg_text("Audio:")
1686         info_cfg_option(WITH_OPENAL)
1687         info_cfg_option(WITH_SDL)
1688         info_cfg_option(WITH_SDL_DYNLOAD)
1689         info_cfg_option(WITH_JACK)
1690         info_cfg_option(WITH_JACK_DYNLOAD)
1691         info_cfg_option(WITH_CODEC_AVI)
1692         info_cfg_option(WITH_CODEC_FFMPEG)
1693         info_cfg_option(WITH_CODEC_SNDFILE)
1694
1695         info_cfg_text("Compression:")
1696         info_cfg_option(WITH_LZMA)
1697         info_cfg_option(WITH_LZO)
1698
1699         info_cfg_text("Python:")
1700         info_cfg_option(WITH_PYTHON_INSTALL)
1701         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
1702         info_cfg_option(WITH_PYTHON_MODULE)
1703         info_cfg_option(WITH_PYTHON_SAFETY)
1704         if(APPLE)
1705                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
1706         endif()
1707
1708         info_cfg_text("Modifiers:")
1709         info_cfg_option(WITH_MOD_REMESH)
1710         info_cfg_option(WITH_MOD_FLUID)
1711         info_cfg_option(WITH_MOD_OCEANSIM)
1712
1713         info_cfg_text("OpenGL:")
1714         info_cfg_option(WITH_GLEW_ES)
1715         info_cfg_option(WITH_GL_EGL)
1716         info_cfg_option(WITH_GL_PROFILE_ES20)
1717         if(WIN32)
1718                 info_cfg_option(WITH_GL_ANGLE)
1719         endif()
1720
1721         info_cfg_text("")
1722
1723         message("${_config_msg}")
1724 endif()
1725
1726 if(0)
1727         print_all_vars()
1728 endif()