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