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