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