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