Merge branch 'master' into blender2.8
[blender.git] / CMakeLists.txt
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # The Original Code is Copyright (C) 2006, Blender Foundation
18 # All rights reserved.
19 #
20 # The Original Code is: all of this file.
21 #
22 # Contributor(s): Jacques Beaurain.
23 #
24 # ***** END GPL LICENSE BLOCK *****
25
26 #-----------------------------------------------------------------------------
27 # We don't allow in-source builds. This causes no end of troubles because
28 # all out-of-source builds will use the CMakeCache.txt file there and even
29 # build the libs and objects in it.
30
31 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
32         if(NOT DEFINED WITH_IN_SOURCE_BUILD)
33                 message(FATAL_ERROR
34                         "CMake generation for blender is not allowed within the source directory!"
35                         "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
36                         "\n "
37                         "\n rm CMakeCache.txt"
38                         "\n cd .."
39                         "\n mkdir cmake-make"
40                         "\n cd cmake-make"
41                         "\n cmake ../blender"
42                         "\n "
43                         "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
44                 )
45         endif()
46 endif()
47
48 cmake_minimum_required(VERSION 2.8)
49
50 if(NOT EXECUTABLE_OUTPUT_PATH)
51         set(FIRST_RUN TRUE)
52 else()
53         set(FIRST_RUN FALSE)
54 endif()
55
56 # this starts out unset
57 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
58 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/platform")
59
60 # avoid having empty buildtype
61 set(CMAKE_BUILD_TYPE_INIT "Release")
62
63 # quiet output for Makefiles, 'make -s' helps too
64 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
65
66 # global compile definitions since add_definitions() adds for all.
67
68 if(NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
69         set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
70                 $<$<CONFIG:Debug>:DEBUG;_DEBUG>
71                 $<$<CONFIG:Release>:NDEBUG>
72                 $<$<CONFIG:MinSizeRel>:NDEBUG>
73                 $<$<CONFIG:RelWithDebInfo>:NDEBUG>
74         )
75 else()
76         # keep until CMake-3.0 is min requirement
77         set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
78         set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
79         set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
80         set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
81 endif()
82
83 #-----------------------------------------------------------------------------
84 # Set policy
85
86 # see "cmake --help-policy CMP0003"
87 # So library linking is more sane
88 cmake_policy(SET CMP0003 NEW)
89
90 # So BUILDINFO and BLENDERPATH strings are automatically quoted
91 cmake_policy(SET CMP0005 NEW)
92
93 # So syntax problems are errors
94 cmake_policy(SET CMP0010 NEW)
95
96 # Input directories must have CMakeLists.txt
97 cmake_policy(SET CMP0014 NEW)
98
99 #-----------------------------------------------------------------------------
100 # Load some macros.
101 include(build_files/cmake/macros.cmake)
102
103
104 #-----------------------------------------------------------------------------
105 # Initialize project.
106
107 blender_project_hack_pre()
108
109 project(Blender)
110
111 blender_project_hack_post()
112
113 enable_testing()
114
115 #-----------------------------------------------------------------------------
116 # Redirect output files
117
118 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
119 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
120 set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests CACHE INTERNAL "" FORCE)
121
122 #-----------------------------------------------------------------------------
123 # Set default config options
124
125 get_blender_version()
126
127
128 #-----------------------------------------------------------------------------
129 # Platform Specific Defaults
130
131 # list of var-names
132 set(_init_vars)
133
134 # initialize to ON
135 macro(option_defaults_init)
136         foreach(_var ${ARGV})
137                 set(${_var} ON)
138                 list(APPEND _init_vars "${_var}")
139         endforeach()
140         unset(_var)
141 endmacro()
142
143 # remove from namespace
144 macro(option_defaults_clear)
145         foreach(_var ${_init_vars})
146                 unset(${_var})
147         endforeach()
148         unset(_var)
149         unset(_init_vars)
150 endmacro()
151
152
153 # values to initialize WITH_****
154 option_defaults_init(
155         _init_BUILDINFO
156         _init_CODEC_FFMPEG
157         _init_CYCLES_OSL
158         _init_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
449
450 # Documentation
451 if(UNIX AND NOT APPLE)
452         option(WITH_DOC_MANPAGE "Create a manual page (Unix manpage)" OFF)
453 endif()
454
455
456 # OpenGL
457
458 option(WITH_GLEW_MX             "Support multiple GLEW contexts (experimental)"                                                                     OFF )
459 option(WITH_GLEW_ES             "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
460 option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)"       OFF)
461 option(WITH_GL_PROFILE_COMPAT   "Support using the OpenGL 'compatibility' profile. (deprecated)"                                                    ON )
462 option(WITH_GL_PROFILE_CORE     "Support using the OpenGL 3.2+ 'core' profile."                                                                     OFF)
463 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (thru either EGL or the AGL/WGL/XGL 'es20' profile)"                                  OFF)
464
465 mark_as_advanced(
466         WITH_GLEW_MX
467         WITH_GLEW_ES
468         WITH_GL_EGL
469         WITH_GL_PROFILE_COMPAT
470         WITH_GL_PROFILE_CORE
471         WITH_GL_PROFILE_ES20
472 )
473
474 if(WITH_GL_PROFILE_COMPAT)
475         set(WITH_GLU ON)
476 else()
477         set(WITH_GLU OFF)
478 endif()
479
480 if(WIN32)
481         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)
482         mark_as_advanced(WITH_GL_ANGLE)
483 endif()
484
485 if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
486         message(WARNING Ignoring WITH_SYSTEM_GLEW and using WITH_GLEW_ES)
487         set(WITH_SYSTEM_GLEW OFF)
488 endif()
489
490 if(WIN32)
491         getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
492         set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
493 endif()
494
495 # Experimental support of C11 and C++11
496 #
497 # We default options to whatever default standard in the current compiler.
498 if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0") AND (NOT WITH_CXX11))
499         set(_c11_init ON)
500         set(_cxx11_init ON)
501 else()
502         set(_c11_init OFF)
503         set(_cxx11_init OFF)
504 endif()
505
506 option(WITH_C11 "Build with C11 standard enabled, for development use only!" ${_c11_init})
507 mark_as_advanced(WITH_C11)
508 option(WITH_CXX11 "Build with C++11 standard enabled, for development use only!" ${_cxx11_init})
509 mark_as_advanced(WITH_CXX11)
510
511 # Compiler toolchain
512 if(CMAKE_COMPILER_IS_GNUCC)
513         option(WITH_LINKER_GOLD "Use ld.gold linker which is usually faster than ld.bfd" ON)
514         mark_as_advanced(WITH_LINKER_GOLD)
515 endif()
516
517 # Dependency graph
518 option(WITH_LEGACY_DEPSGRAPH "Build Blender with legacy dependency graph" ON)
519 mark_as_advanced(WITH_LEGACY_DEPSGRAPH)
520
521 # Use hardcoded paths or find_package to find externals
522 option(WITH_WINDOWS_FIND_MODULES "Use find_package to locate libraries" OFF)
523 mark_as_advanced(WITH_WINDOWS_FIND_MODULES)
524
525 option(WITH_WINDOWS_CODESIGN "Use signtool to sign the final binary." OFF)
526 mark_as_advanced(WITH_WINDOWS_CODESIGN)
527
528 set(WINDOWS_CODESIGN_PFX CACHE FILEPATH  "Path to pfx file to use for codesigning.")
529 mark_as_advanced(WINDOWS_CODESIGN_PFX)
530
531 set(WINDOWS_CODESIGN_PFX_PASSWORD CACHE STRING  "password for pfx file used for codesigning.")
532 mark_as_advanced(WINDOWS_CODESIGN_PFX_PASSWORD)
533
534 # avoid using again
535 option_defaults_clear()
536
537 # end option(...)
538
539
540
541 # By default we want to install to the directory we are compiling our executables
542 # unless specified otherwise, which we currently do not allow
543 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
544         if(WIN32)
545                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
546         elseif(APPLE)
547                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
548         else()
549                 if(WITH_INSTALL_PORTABLE)
550                         set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH} CACHE PATH "default install path" FORCE)
551                 endif()
552         endif()
553 endif()
554
555
556
557 # Apple
558
559 if(APPLE)
560         # require newer cmake on osx because of version handling,
561         # older cmake cannot handle 2 digit subversion!
562         cmake_minimum_required(VERSION 3.0.0)
563
564         if(NOT CMAKE_OSX_ARCHITECTURES)
565                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
566                         "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
567                         FORCE)
568         endif()
569
570         if(NOT DEFINED OSX_SYSTEM)
571                 execute_process(
572                         COMMAND xcodebuild -version -sdk macosx SDKVersion
573                         OUTPUT_VARIABLE OSX_SYSTEM
574                         OUTPUT_STRIP_TRAILING_WHITESPACE)
575         endif()
576
577         # workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not
578         # take xcode-select path into account but would always look  into /Applications/Xcode.app
579         # while dev versions are named Xcode<version>-DP<preview_number>
580         execute_process(
581                 COMMAND xcode-select --print-path
582                 OUTPUT_VARIABLE XCODE_CHECK OUTPUT_STRIP_TRAILING_WHITESPACE)
583         string(REPLACE "/Contents/Developer" "" XCODE_BUNDLE ${XCODE_CHECK}) # truncate to bundlepath in any case
584         
585         if(${CMAKE_GENERATOR} MATCHES "Xcode")
586         
587                 # earlier xcode has no bundled developer dir, no sense in getting xcode path from
588                 if(${XCODE_VERSION} VERSION_GREATER 4.2) 
589                         # reduce to XCode name without dp extension
590                         string(SUBSTRING "${XCODE_CHECK}" 14 6 DP_NAME) 
591                         if(${DP_NAME} MATCHES Xcode5)
592                                 set(XCODE_VERSION 5)
593                         endif()
594                 endif()
595
596                 ##### cmake incompatibility with xcode  4.3 and higher #####
597                 if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
598                         message(FATAL_ERROR "Xcode 4.3 and higher must be used with cmake 2.8-8 or higher")
599                 endif()
600                 ### end cmake incompatibility with xcode 4.3 and higher ###
601                 
602                 if(${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4 AND ${XCODE_VERSION} VERSION_LESS 4.3)
603                         # Xcode 4 defaults to the Apple LLVM Compiler.
604                         # Override the default compiler selection because Blender only compiles with gcc up to xcode 4.2
605                         set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
606                         message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
607                 endif()
608         else() # unix makefile generator does not fill XCODE_VERSION var, so we get it with a command
609                 execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILD_NR)
610                 string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
611                 unset(XCODE_VERS_BUILD_NR)
612         endif()
613
614         message(STATUS "Detected OS X ${OSX_SYSTEM} and Xcode ${XCODE_VERSION} at ${XCODE_BUNDLE}")
615
616         if(${XCODE_VERSION} VERSION_LESS 4.3)
617                 # use guaranteed existing sdk
618                 set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)
619         else()
620                 # note: xcode-select path could be ambigous,
621                 # cause /Applications/Xcode.app/Contents/Developer or /Applications/Xcode.app would be allowed
622                 # so i use a selfcomposed bundlepath here  
623                 set(OSX_SYSROOT_PREFIX ${XCODE_BUNDLE}/Contents/Developer/Platforms/MacOSX.platform)
624                 message(STATUS "OSX_SYSROOT_PREFIX: " ${OSX_SYSROOT_PREFIX})
625                 set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
626                 set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
627                 if(${CMAKE_GENERATOR} MATCHES "Xcode")
628                         # to silence sdk not found warning, just overrides CMAKE_OSX_SYSROOT
629                         set(CMAKE_XCODE_ATTRIBUTE_SDKROOT macosx${OSX_SYSTEM})
630                 endif()
631         endif()
632
633         if(OSX_SYSTEM MATCHES 10.9)
634                 # make sure syslibs and headers are looked up in sdk ( expecially for 10.9 openGL atm. )
635                 set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT})
636         endif()
637
638         if(WITH_CXX11)
639                 # 10.9 is our min. target, if you use higher sdk, weak linking happens
640                 if(CMAKE_OSX_DEPLOYMENT_TARGET)
641                         if(${CMAKE_OSX_DEPLOYMENT_TARGET} VERSION_LESS 10.9)
642                                 message(STATUS "Setting deployment target to 10.9, lower versions are incompatible with WITH_CXX11")
643                                 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "" FORCE)
644                         endif()
645                 else()
646                         set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "" FORCE)
647                 endif()
648         else()
649                 if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
650                         # 10.6 is our min. target, if you use higher sdk, weak linking happens
651                         set(CMAKE_OSX_DEPLOYMENT_TARGET "10.6" CACHE STRING "" FORCE)
652                 endif()
653         endif()
654         
655         if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
656                 # force CMAKE_OSX_DEPLOYMENT_TARGET for makefiles, will not work else ( cmake bug ? )
657                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
658                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
659                 add_definitions("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
660         endif()
661 endif()
662
663
664 #-----------------------------------------------------------------------------
665 # Check for conflicting/unsupported configurations
666
667 if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_STANDALONE)
668         message(FATAL_ERROR
669                 "At least one of WITH_BLENDER or WITH_PLAYER or "
670                 "WITH_CYCLES_STANDALONE must be enabled, nothing to do!"
671         )
672 endif()
673
674 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
675         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
676 endif()
677
678 if(NOT WITH_AUDASPACE)
679         if(WITH_OPENAL)
680                 message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
681         endif()
682         if(WITH_JACK)
683                 message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
684         endif()
685         if(WITH_GAMEENGINE)
686                 message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
687         endif()
688 endif()
689
690 if(NOT WITH_SDL AND WITH_GHOST_SDL)
691         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
692 endif()
693
694 # python module, needs some different options
695 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
696         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
697 endif()
698
699 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
700         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
701 endif()
702
703
704 # may as well build python module without a UI
705 if(WITH_PYTHON_MODULE)
706         set(WITH_HEADLESS ON)
707 endif()
708
709 if(NOT WITH_PYTHON)
710         set(WITH_CYCLES OFF)
711 endif()
712
713 # enable boost for cycles, audaspace or i18n
714 # otherwise if the user disabled
715 if(NOT WITH_BOOST)
716         # Explicitly disabled. so disable all deps.
717         macro(set_and_warn
718                 _setting _val)
719                 if(${${_setting}})
720                         message(STATUS "'WITH_BOOST' is disabled: forceing 'set(${_setting} ${_val})'")
721                 endif()
722                 set(${_setting} ${_val})
723         endmacro()
724
725         set_and_warn(WITH_CYCLES         OFF)
726         set_and_warn(WITH_AUDASPACE      OFF)
727         set_and_warn(WITH_INTERNATIONAL  OFF)
728         set_and_warn(WITH_OPENVDB        OFF)
729         set_and_warn(WITH_OPENCOLORIO    OFF)
730         set_and_warn(WITH_MOD_BOOLEAN    OFF)
731
732         set_and_warn(WITH_OPENAL         OFF)  # depends on AUDASPACE
733         set_and_warn(WITH_GAMEENGINE     OFF)  # depends on AUDASPACE
734         set_and_warn(WITH_PLAYER         OFF)  # depends on GAMEENGINE
735 elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_AUDASPACE OR WITH_INTERNATIONAL OR
736        WITH_OPENVDB OR WITH_OPENCOLORIO OR WITH_MOD_BOOLEAN)
737         # Keep enabled
738 else()
739         # New dependency graph needs either Boost or C++11 for function bindings.
740         if(NOT WITH_CXX11)
741                 # Enabled but we don't need it
742                 set(WITH_BOOST OFF)
743         endif()
744 endif()
745
746 # auto enable openimageio for cycles
747 if(WITH_CYCLES)
748         set(WITH_OPENIMAGEIO ON)
749
750         # auto enable llvm for cycles_osl
751         if(WITH_CYCLES_OSL)
752                 set(WITH_LLVM ON CACHE BOOL "" FORCE)
753         endif()
754 else()
755         set(WITH_CYCLES_OSL OFF)
756 endif()
757
758 # auto enable openimageio linking dependencies
759 if(WITH_OPENIMAGEIO)
760         set(WITH_IMAGE_OPENEXR ON)
761         set(WITH_IMAGE_TIFF ON)
762 endif()
763
764 # auto enable alembic linking dependencies
765 if(WITH_ALEMBIC)
766         set(WITH_IMAGE_OPENEXR ON)
767 endif()
768
769 # don't store paths to libs for portable distribution
770 if(WITH_INSTALL_PORTABLE)
771         set(CMAKE_SKIP_BUILD_RPATH TRUE)
772 endif()
773
774 if(WITH_GHOST_SDL OR WITH_HEADLESS)
775         set(WITH_X11           OFF)
776         set(WITH_X11_XINPUT    OFF)
777         set(WITH_X11_XF86VMODE OFF)
778         set(WITH_X11_ALPHA     OFF)
779         set(WITH_GHOST_XDND    OFF)
780         set(WITH_INPUT_IME     OFF)
781 endif()
782
783 if(WITH_CPU_SSE)
784         TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
785 else()
786         message(STATUS "SSE and SSE2 optimizations are DISABLED!")
787         set(COMPILER_SSE_FLAG)
788         set(COMPILER_SSE2_FLAG)
789 endif()
790
791 if(WITH_BUILDINFO)
792         find_package(Git)
793         if(NOT GIT_FOUND)
794                 message(WARNING "Git was not found, disabling WITH_BUILDINFO")
795                 set(WITH_BUILDINFO OFF)
796         endif()
797 endif()
798
799 TEST_SHARED_PTR_SUPPORT()
800 TEST_UNORDERED_MAP_SUPPORT()
801
802 if(WITH_AUDASPACE)
803         if(WITH_SYSTEM_AUDASPACE)
804                 set(AUDASPACE_DEFINITIONS
805                         -DWITH_AUDASPACE
806                         -DWITH_SYSTEM_AUDASPACE
807                         "-DAUD_DEVICE_H=<AUD_Device.h>"
808                         "-DAUD_SPECIAL_H=<AUD_Special.h>"
809                         "-DAUD_SOUND_H=<AUD_Sound.h>"
810                         "-DAUD_HANDLE_H=<AUD_Handle.h>"
811                         "-DAUD_SEQUENCE_H=<AUD_Sequence.h>"
812                         "-DAUD_TYPES_H=<AUD_Types.h>"
813                         "-DAUD_PYTHON_H=<python/PyAPI.h>"
814                 )
815         else()
816                 set(AUDASPACE_C_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/intern/audaspace/intern")
817                 set(AUDASPACE_PY_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/intern/audaspace/intern")
818                 set(AUDASPACE_DEFINITIONS
819                         -DWITH_AUDASPACE
820                         "-DAUD_DEVICE_H=<AUD_C-API.h>"
821                         "-DAUD_SPECIAL_H=<AUD_C-API.h>"
822                         "-DAUD_SOUND_H=<AUD_C-API.h>"
823                         "-DAUD_HANDLE_H=<AUD_C-API.h>"
824                         "-DAUD_SEQUENCE_H=<AUD_C-API.h>"
825                         "-DAUD_TYPES_H=<AUD_Space.h>"
826                 )
827         endif()
828 endif()
829
830 #-----------------------------------------------------------------------------
831 # Check for valid directories
832 # ... a partial checkout may cause this.
833 #
834 # note: we need to check for a known subdir in both cases.
835 #       since uninitialized git submodules will give blank dirs
836
837 if(WITH_INTERNATIONAL)
838         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
839                 message(WARNING
840                         "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
841                         "This is a 'git submodule', which are known not to work with bridges to other version "
842                         "control systems, disabling 'WITH_INTERNATIONAL'."
843                 )
844                 set(WITH_INTERNATIONAL OFF)
845         endif()
846 endif()
847
848 if(WITH_PYTHON)
849         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
850                 message(WARNING
851                         "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
852                         "This is a 'git submodule', which are known not to work with bridges to other version "
853                         "control systems: * CONTINUING WITHOUT ADDONS *"
854                 )
855         endif()
856 endif()
857
858 #-----------------------------------------------------------------------------
859 # Initialize un-cached vars, avoid unused warning
860
861 # linux only, not cached
862 set(WITH_BINRELOC OFF)
863
864 # MAXOSX only, set to avoid uninitialized
865 set(EXETYPE "")
866
867 # C/C++ flags
868 set(PLATFORM_CFLAGS)
869
870 # these are added to later on.
871 set(C_WARNINGS)
872 set(CXX_WARNINGS)
873
874 # for gcc -Wno-blah-blah
875 set(CC_REMOVE_STRICT_FLAGS)
876
877 # libraries to link the binary with passed to target_link_libraries()
878 # known as LLIBS to scons
879 set(PLATFORM_LINKLIBS "")
880
881 # Added to linker flags in setup_liblinks
882 # - CMAKE_EXE_LINKER_FLAGS
883 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
884 set(PLATFORM_LINKFLAGS "")
885 set(PLATFORM_LINKFLAGS_DEBUG "")
886
887
888 #-----------------------------------------------------------------------------
889 #Platform specifics
890
891 if(WITH_X11)
892         find_package(X11 REQUIRED)
893
894         find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
895         mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
896
897         list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
898
899         if(WITH_X11_XINPUT)
900                 if(X11_Xinput_LIB)
901                         list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
902                 else()
903                         set(WITH_X11_XINPUT OFF)
904                 endif()
905         endif()
906
907         if(WITH_X11_XF86VMODE)
908                 # XXX, why dont cmake make this available?
909                 find_library(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
910                 mark_as_advanced(X11_Xxf86vmode_LIB)
911                 if(X11_Xxf86vmode_LIB)
912                         list(APPEND PLATFORM_LINKLIBS ${X11_Xxf86vmode_LIB})
913                 else()
914                         set(WITH_X11_XF86VMODE OFF)
915                 endif()
916         endif()
917
918         if(WITH_X11_ALPHA)
919                 find_library(X11_Xrender_LIB Xrender  ${X11_LIB_SEARCH_PATH})
920                 mark_as_advanced(X11_Xrender_LIB)
921                 if (X11_Xrender_LIB)
922                         list(APPEND PLATFORM_LINKLIBS ${X11_Xrender_LIB})
923                 else()
924                         set(WITH_X11_ALPHA OFF)
925                 endif()
926         endif()
927
928 endif()
929
930
931 # ----------------------------------------------------------------------------
932 # Main Platform Checks
933 #
934 # - UNIX
935 # - WIN32
936 # - APPLE
937
938 if(UNIX AND NOT APPLE)
939         include(platform_unix)
940 elseif(WIN32)
941         include(platform_win32)
942 elseif(APPLE)
943         include(platform_apple)
944 endif()
945
946 #-----------------------------------------------------------------------------
947 # Common.
948
949 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
950         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
951 endif()
952
953 if(WITH_CYCLES)
954         if(NOT WITH_OPENIMAGEIO)
955                 message(FATAL_ERROR
956                         "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. "
957                         "Configure OIIO or disable WITH_CYCLES"
958                 )
959         endif()
960         if(NOT WITH_BOOST)
961                 message(FATAL_ERROR
962                         "Cycles requires WITH_BOOST, the library may not have been found. "
963                         "Configure BOOST or disable WITH_CYCLES"
964                 )
965         endif()
966
967         if(WITH_CYCLES_OSL)
968                 if(NOT WITH_LLVM)
969                         message(FATAL_ERROR
970                                 "Cycles OSL requires WITH_LLVM, the library may not have been found. "
971                                 "Configure LLVM or disable WITH_CYCLES_OSL"
972                         )
973                 endif()
974         endif()
975 endif()
976
977 if(WITH_INTERNATIONAL)
978         if(NOT WITH_BOOST)
979                 message(FATAL_ERROR
980                         "Internationalization requires WITH_BOOST, the library may not have been found. "
981                         "Configure BOOST or disable WITH_INTERNATIONAL"
982                 )
983         endif()
984 endif()
985
986 # See TEST_SSE_SUPPORT() for how this is defined.
987
988 # Do it globally, SSE2 is required for quite some time now.
989 # Doing it now allows to use SSE/SSE2 in inline headers.
990 if(SUPPORT_SSE_BUILD)
991         set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
992         add_definitions(-D__SSE__ -D__MMX__)
993 endif()
994 if(SUPPORT_SSE2_BUILD)
995         set(PLATFORM_CFLAGS " ${PLATFORM_CFLAGS} ${COMPILER_SSE2_FLAG}")
996         add_definitions(-D__SSE2__)
997         if(NOT SUPPORT_SSE_BUILD) # dont double up
998                 add_definitions(-D__MMX__)
999         endif()
1000 endif()
1001
1002
1003 # set the endian define
1004 if(MSVC)
1005         # for some reason this fails on msvc
1006         add_definitions(-D__LITTLE_ENDIAN__)
1007         
1008 # OSX-Note: as we do crosscompiling with specific set architecture,
1009 # endianess-detection and autosetting is counterproductive
1010 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
1011
1012 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
1013         add_definitions(-D__LITTLE_ENDIAN__)
1014 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)            
1015         add_definitions(-D__BIG_ENDIAN__)
1016         
1017 else()
1018         include(TestBigEndian)
1019         test_big_endian(_SYSTEM_BIG_ENDIAN)
1020         if(_SYSTEM_BIG_ENDIAN)
1021                 add_definitions(-D__BIG_ENDIAN__)
1022         else()
1023                 add_definitions(-D__LITTLE_ENDIAN__)
1024         endif()
1025         unset(_SYSTEM_BIG_ENDIAN)
1026 endif()
1027 if(WITH_IMAGE_OPENJPEG)
1028         if(WITH_SYSTEM_OPENJPEG)
1029                 # dealt with above
1030                 set(OPENJPEG_DEFINES "")
1031         else()
1032                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
1033                 set(OPENJPEG_DEFINES "-DOPJ_STATIC")
1034         endif()
1035         # Special handling of Windows platform where openjpeg is always static.
1036         if(WIN32)
1037                 set(OPENJPEG_DEFINES "-DOPJ_STATIC")
1038         endif()
1039 endif()
1040
1041 if(NOT WITH_SYSTEM_EIGEN3)
1042         set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3)
1043 endif()
1044
1045 #-----------------------------------------------------------------------------
1046 # Configure OpenGL.
1047
1048 find_package(OpenGL)
1049 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
1050
1051 if(WITH_GLU)
1052         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_glu_LIBRARY}")
1053         list(APPEND GL_DEFINITIONS -DWITH_GLU)
1054 endif()
1055
1056 if(WITH_SYSTEM_GLES)
1057         find_package_wrapper(OpenGLES)
1058 endif()
1059
1060 if(WITH_GL_PROFILE_COMPAT OR WITH_GL_PROFILE_CORE)
1061         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_gl_LIBRARY}")
1062
1063 elseif(WITH_GL_PROFILE_ES20)
1064         if(WITH_SYSTEM_GLES)
1065                 if(NOT OPENGLES_LIBRARY)
1066                         message(FATAL_ERROR
1067                                 "Unable to find OpenGL ES libraries. "
1068                                 "Install them or disable WITH_SYSTEM_GLES."
1069                         )
1070                 endif()
1071
1072                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_LIBRARY)
1073
1074         else()
1075                 set(OPENGLES_LIBRARY "" CACHE FILEPATH "OpenGL ES 2.0 library file")
1076                 mark_as_advanced(OPENGLES_LIBRARY)
1077
1078                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
1079
1080                 if(NOT OPENGLES_LIBRARY)
1081                         message(FATAL_ERROR
1082                                 "To compile WITH_GL_EGL you need to set OPENGLES_LIBRARY "
1083                                 "to the file path of an OpenGL ES 2.0 library."
1084                         )
1085                 endif()
1086
1087         endif()
1088
1089         if(WIN32)
1090                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
1091
1092                 set(OPENGLES_DLL "" CACHE FILEPATH "OpenGL ES 2.0 redistributable DLL file")
1093                 mark_as_advanced(OPENGLES_DLL)
1094
1095                 if(NOT OPENGLES_DLL)
1096                         message(FATAL_ERROR
1097                                 "To compile WITH_GL_PROFILE_ES20 you need to set OPENGLES_DLL to the file "
1098                                 "path of an OpenGL ES 2.0 runtime dynamic link library (DLL)."
1099                         )
1100                 endif()
1101
1102                 if(WITH_GL_ANGLE)
1103                         list(APPEND GL_DEFINITIONS -DWITH_ANGLE)
1104
1105                         set(D3DCOMPILER_DLL "" CACHE FILEPATH "Direct3D Compiler redistributable DLL file (needed by ANGLE)")
1106
1107                         get_filename_component(D3DCOMPILER_FILENAME "${D3DCOMPILER_DLL}" NAME)
1108                         list(APPEND GL_DEFINITIONS "-DD3DCOMPILER=\"\\\"${D3DCOMPILER_FILENAME}\\\"\"")
1109
1110                         mark_as_advanced(D3DCOMPILER_DLL)
1111
1112                         if(D3DCOMPILER_DLL STREQUAL "")
1113                                 message(FATAL_ERROR
1114                                         "To compile WITH_GL_ANGLE you need to set D3DCOMPILER_DLL to the file "
1115                                         "path of a copy of the DirectX redistributable DLL file: D3DCompiler_46.dll"
1116                                 )
1117                         endif()
1118
1119                 endif()
1120
1121         endif()
1122
1123 endif()
1124
1125 if(WITH_GL_EGL)
1126         list(APPEND GL_DEFINITIONS -DWITH_GL_EGL)
1127
1128         if(WITH_SYSTEM_GLES)
1129                 if(NOT OPENGLES_EGL_LIBRARY)
1130                         message(FATAL_ERROR
1131                                 "Unable to find OpenGL ES libraries. "
1132                                 "Install them or disable WITH_SYSTEM_GLES."
1133                         )
1134                 endif()
1135
1136                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_EGL_LIBRARY)
1137
1138         else()
1139                 set(OPENGLES_EGL_LIBRARY "" CACHE FILEPATH "EGL library file")
1140                 mark_as_advanced(OPENGLES_EGL_LIBRARY)
1141
1142                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}" "${OPENGLES_EGL_LIBRARY}")
1143
1144                 if(NOT OPENGLES_EGL_LIBRARY)
1145                         message(FATAL_ERROR
1146                                 "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY "
1147                                 "to the file path of an EGL library."
1148                         )
1149                 endif()
1150
1151         endif()
1152
1153         if(WIN32)
1154                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
1155
1156                 set(OPENGLES_EGL_DLL "" CACHE FILEPATH "EGL redistributable DLL file")
1157                 mark_as_advanced(OPENGLES_EGL_DLL)
1158
1159                 if(NOT OPENGLES_EGL_DLL)
1160                         message(FATAL_ERROR
1161                                 "To compile WITH_GL_EGL you need to set OPENGLES_EGL_DLL "
1162                                 "to the file path of an EGL runtime dynamic link library (DLL)."
1163                         )
1164                 endif()
1165
1166         endif()
1167
1168 endif()
1169
1170 if(WITH_GL_PROFILE_COMPAT)
1171         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_COMPAT)
1172 endif()
1173
1174 if(WITH_GL_PROFILE_CORE)
1175         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_CORE)
1176 endif()
1177
1178 if(WITH_GL_PROFILE_ES20)
1179         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_ES20)
1180 endif()
1181
1182 if(WITH_GL_EGL)
1183         list(APPEND GL_DEFINITIONS -DWITH_EGL)
1184 endif()
1185
1186 #-----------------------------------------------------------------------------
1187 # Configure OpenMP.
1188 if(WITH_OPENMP)
1189         find_package(OpenMP)
1190         if(OPENMP_FOUND)
1191                 if(NOT WITH_OPENMP_STATIC)
1192                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1193                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1194                 else()
1195                         # Typically avoid adding flags as defines but we can't
1196                         # pass OpenMP flags to the linker for static builds, meaning
1197                         # we can't add any OpenMP related flags to CFLAGS variables
1198                         # since they're passed to the linker as well.
1199                         add_definitions("${OpenMP_C_FLAGS}")
1200
1201                         find_library_static(OpenMP_LIBRARIES gomp ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
1202                 endif()
1203         else()
1204                 set(WITH_OPENMP OFF)
1205         endif()
1206
1207         mark_as_advanced(
1208                 OpenMP_C_FLAGS
1209                 OpenMP_CXX_FLAGS
1210         )
1211 endif()
1212
1213 #-----------------------------------------------------------------------------
1214 # Configure GLEW
1215
1216 if(WITH_GLEW_MX)
1217         list(APPEND GL_DEFINITIONS -DWITH_GLEW_MX)
1218 endif()
1219
1220 if(WITH_SYSTEM_GLEW)
1221         find_package(GLEW)
1222
1223         # Note: There is an assumption here that the system GLEW is not a static library.
1224
1225         if(NOT GLEW_FOUND)
1226                 message(FATAL_ERROR "GLEW is required to build Blender. Install it or disable WITH_SYSTEM_GLEW.")
1227         endif()
1228
1229         if(WITH_GLEW_MX)
1230                 set(BLENDER_GLEW_LIBRARIES ${GLEW_MX_LIBRARY})
1231         else()
1232                 set(BLENDER_GLEW_LIBRARIES ${GLEW_LIBRARY})
1233         endif()
1234 else()
1235         if(WITH_GLEW_ES)
1236                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew-es/include")
1237
1238                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC -DWITH_GLEW_ES)
1239
1240                 # These definitions remove APIs from glew.h, making GLEW smaller, and catching unguarded API usage
1241                 if(NOT WITH_GL_PROFILE_ES20)
1242                         # No ES functions are needed
1243                         list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
1244                 elseif(NOT (WITH_GL_PROFILE_CORE OR WITH_GL_PROFILE_COMPAT))
1245                         # ES is enabled, but the other functions are all disabled
1246                         list(APPEND GL_DEFINITIONS -DGLEW_ES_ONLY)
1247                 endif()
1248
1249                 if(WITH_GL_PROFILE_ES20)
1250                         if(WITH_GL_EGL)
1251                                 list(APPEND GL_DEFINITIONS -DGLEW_USE_LIB_ES20)
1252                         endif()
1253
1254                         # ToDo: This is an experiment to eliminate ES 1 symbols,
1255                         # GLEW doesn't really properly provide this level of control
1256                         # (for example, without modification it eliminates too many symbols)
1257                         # so there are lots of modifications to GLEW to make this work,
1258                         # and no attempt to make it work beyond Blender at this point.
1259                         list(APPEND GL_DEFINITIONS -DGL_ES_VERSION_1_0=0 -DGL_ES_VERSION_CL_1_1=0 -DGL_ES_VERSION_CM_1_1=0)
1260                 endif()
1261
1262                 if(WITH_GL_EGL)
1263                         list(APPEND GL_DEFINITIONS -DGLEW_INC_EGL)
1264                 endif()
1265
1266                 set(BLENDER_GLEW_LIBRARIES extern_glew_es bf_intern_glew_mx)
1267
1268         else()
1269                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1270
1271                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC)
1272
1273                 # This won't affect the non-experimental glew library, 
1274                 # but is used for conditional compilation elsewhere.
1275                 list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
1276
1277                 set(BLENDER_GLEW_LIBRARIES extern_glew)
1278
1279         endif()
1280
1281 endif()
1282
1283 if(NOT WITH_GLU)
1284         list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
1285 endif()
1286
1287 #-----------------------------------------------------------------------------
1288 # Configure Bullet
1289
1290 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
1291         find_package(Bullet)
1292         if(NOT BULLET_FOUND)
1293                 set(WITH_BULLET OFF)
1294         endif()
1295 else()
1296         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
1297         # set(BULLET_LIBRARIES "")
1298 endif()
1299
1300 #-----------------------------------------------------------------------------
1301 # Configure Python.
1302
1303 if(WITH_PYTHON_MODULE)
1304         add_definitions(-DPy_ENABLE_SHARED)
1305 endif()
1306
1307 #-----------------------------------------------------------------------------
1308 # Configure GLog/GFlags
1309
1310 if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING))
1311         set(GLOG_DEFINES
1312                 -DGOOGLE_GLOG_DLL_DECL=
1313         )
1314
1315         set(GFLAGS_DEFINES
1316                 -DGFLAGS_DLL_DEFINE_FLAG=
1317                 -DGFLAGS_DLL_DECLARE_FLAG=
1318                 -DGFLAGS_DLL_DECL=
1319         )
1320 endif()
1321
1322 #-----------------------------------------------------------------------------
1323 # Configure Ceres
1324
1325 if(WITH_LIBMV)
1326         set(CERES_DEFINES)
1327
1328         if(WITH_CXX11)
1329                 # nothing to be done
1330         elseif(SHARED_PTR_FOUND)
1331                 if(SHARED_PTR_TR1_MEMORY_HEADER)
1332                         list(APPEND CERES_DEFINES -DCERES_TR1_MEMORY_HEADER)
1333                 endif()
1334                 if(SHARED_PTR_TR1_NAMESPACE)
1335                         list(APPEND CERES_DEFINES -DCERES_TR1_SHARED_PTR)
1336                 endif()
1337         else()
1338                 message(FATAL_ERROR "Ceres: Unable to find shared_ptr.")
1339         endif()
1340
1341         if(WITH_CXX11)
1342                 list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP)
1343         elseif(HAVE_STD_UNORDERED_MAP_HEADER)
1344                 if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
1345                         list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP)
1346                 else()
1347                         if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
1348                                 list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
1349                         else()
1350                                 list(APPEND CERES_DEFINES -DCERES_NO_UNORDERED_MAP)
1351                                 message(STATUS "Ceres: Replacing unordered_map/set with map/set (warning: slower!)")
1352                         endif()
1353                 endif()
1354         else()
1355                 if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
1356                         list(APPEND CERES_DEFINES -DCERES_TR1_UNORDERED_MAP)
1357                 else()
1358                         list(APPEND CERES_DEFINES -DCERES_NO_UNORDERED_MAP)
1359                         message(STATUS "Ceres: Replacing unordered_map/set with map/set (warning: slower!)")
1360                 endif()
1361         endif()
1362 endif()
1363
1364 #-----------------------------------------------------------------------------
1365 # Extra compile flags
1366
1367 if(CMAKE_COMPILER_IS_GNUCC)
1368
1369         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1370         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1371         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1372         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1373         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_VLA -Werror=vla)
1374         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1375         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1376         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1377         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1378         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1379         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1380         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1381         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1382         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
1383         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
1384         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1385         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
1386         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1387         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1388         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
1389         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_FORMAT_SIGN -Wformat-signedness)
1390
1391         # gcc 4.2 gives annoying warnings on every file with this
1392         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1393                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
1394         endif()
1395
1396         # versions before gcc4.6 give many BLI_math warnings
1397         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
1398                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
1399                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
1400         endif()
1401
1402         # versions before gcc4.8 include global name-space.
1403         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.8")
1404                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_SHADOW -Wshadow)
1405         endif()
1406
1407         # disable because it gives warnings for printf() & friends.
1408         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1409
1410         if(NOT APPLE)
1411                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1412         endif()
1413
1414         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1415         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1416         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1417         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
1418         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1419         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1420         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1421         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
1422         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1423         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1424         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1425         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1426         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_POINTER_ARITH -Wpointer-arith)
1427         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_PARAMETER -Wunused-parameter)
1428         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_WRITE_STRINGS -Wwrite-strings)
1429         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1430         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_FORMAT_SIGN -Wformat-signedness)
1431
1432         # gcc 4.2 gives annoying warnings on every file with this
1433         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1434                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
1435         endif()
1436
1437         # causes too many warnings
1438         if(NOT APPLE)
1439                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1440                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
1441         endif()
1442
1443         # flags to undo strict flags
1444         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
1445         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
1446
1447         if(NOT APPLE)
1448                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1449         endif()
1450
1451 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
1452
1453         if(APPLE AND WITH_OPENMP) # we need the Intel omp lib linked here to not fail all tests due presence of -fopenmp !
1454                 set(CMAKE_REQUIRED_FLAGS "-L${LIBDIR}/openmp/lib -liomp5") # these are only used for the checks
1455         endif()
1456
1457         # strange, clang complains these are not supported, but then yses them.
1458         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1459         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1460         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1461         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1462         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1463         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1464         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1465         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1466         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1467
1468         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1469         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
1470         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
1471         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
1472         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.
1473         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
1474         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
1475
1476         # gives too many unfixable warnings
1477         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
1478         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
1479
1480         # flags to undo strict flags
1481         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
1482         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
1483
1484         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
1485         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
1486         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
1487         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
1488         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
1489         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
1490         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
1491         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
1492
1493         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
1494         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
1495         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
1496         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
1497         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
1498
1499 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1500
1501         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1502         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1503         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1504
1505         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1506         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1507         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1508
1509         # disable numbered, false positives
1510         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
1511         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
1512 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
1513         # most msvc warnings are C & C++
1514         set(_WARNINGS
1515                 # warning level:
1516                 "/W3"
1517                 "/w34062"  # switch statement contains 'default' but no 'case' labels
1518                 # disable:
1519                 "/wd4018"  # signed/unsigned mismatch
1520                 "/wd4146"  # unary minus operator applied to unsigned type, result still unsigned
1521                 "/wd4065"  # switch statement contains 'default' but no 'case' labels
1522                 "/wd4127"  # conditional expression is constant
1523                 "/wd4181"  # qualifier applied to reference type; ignored
1524                 "/wd4200"  # zero-sized array in struct/union
1525                 "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
1526                 "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
1527                 "/wd4305"  # truncation from 'type1' to 'type2'
1528                 "/wd4800"  # forcing value to bool 'true' or 'false'
1529                 # errors:
1530                 "/we4013"  # 'function' undefined; assuming extern returning int
1531                 "/we4431"  # missing type specifier - int assumed
1532         )
1533
1534         string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
1535         set(C_WARNINGS "${_WARNINGS}")
1536         set(CXX_WARNINGS "${_WARNINGS}")
1537         unset(_WARNINGS)
1538 endif()
1539
1540 # ensure python header is found since detection can fail, this could happen
1541 # with _any_ library but since we used a fixed python version this tends to
1542 # be most problematic.
1543 if(WITH_PYTHON)
1544         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
1545                 message(FATAL_ERROR
1546                         "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
1547                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
1548                         "to a valid python include path. Containing "
1549                         "Python.h for python version \"${PYTHON_VERSION}\""
1550                 )
1551         endif()
1552
1553         if(WIN32 OR APPLE)
1554                 # pass, we have this in an archive to extract
1555         elseif(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
1556                 find_python_package(numpy)
1557         endif()
1558
1559         if(WIN32 OR APPLE)
1560                 # pass, we have this in lib/python/site-packages
1561         elseif(WITH_PYTHON_INSTALL_REQUESTS)
1562                 find_python_package(requests)
1563         endif()
1564 endif()
1565
1566 if(WITH_CXX11)
1567         if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
1568                 # TODO(sergey): Do we want c++11 or gnu-c++11 here?
1569                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
1570         elseif(MSVC12)
1571                 # Nothing special is needed, C++11 features are available by default.
1572         else()
1573                 message(FATAL_ERROR "Compiler ${CMAKE_C_COMPILER_ID} is not supported for C++11 build yet")
1574         endif()
1575 else()
1576         # GCC-6 switched to C++11 by default, which would break linking with existing libraries
1577         # by default. So we explicitly disable C++11 for a new GCC so no linking issues happens.
1578         if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0"))
1579                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++98")
1580                 # We also disable any of C++11 ABI from usage, so we wouldn't even try to
1581                 # link to stuff from std::__cxx11 namespace.
1582                 add_definitions("-D_GLIBCXX_USE_CXX11_ABI=0")
1583         endif()
1584 endif()
1585
1586 # Visual Studio has all standards it supports available by default
1587 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "Intel")
1588         # Use C99 + GNU extensions, works with GCC, Clang, ICC
1589         if(WITH_C11)
1590                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
1591         else()
1592                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
1593         endif()
1594 endif()
1595
1596 # Include warnings first, so its possible to disable them with user defined flags
1597 # eg: -Wno-uninitialized
1598 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
1599 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
1600
1601 # defined above, platform spesific but shared names
1602 mark_as_advanced(
1603         CYCLES_OSL
1604         OSL_LIB_EXEC
1605         OSL_COMPILER
1606         OSL_LIB_COMP
1607         OSL_LIB_QUERY
1608         OSL_INCLUDE_DIR
1609 )
1610
1611 mark_as_advanced(
1612         LLVM_CONFIG
1613         LLVM_ROOT_DIR
1614         LLVM_LIBRARY
1615         LLVM_VERSION
1616 )
1617
1618 #-------------------------------------------------------------------------------
1619 # Global Defines
1620
1621 # better not set includes here but this debugging option is off by default.
1622 if(WITH_CXX_GUARDEDALLOC)
1623         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
1624         add_definitions(-DWITH_CXX_GUARDEDALLOC)
1625 endif()
1626
1627 if(WITH_ASSERT_ABORT)
1628         add_definitions(-DWITH_ASSERT_ABORT)
1629 endif()
1630
1631 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
1632 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
1633
1634 #-----------------------------------------------------------------------------
1635 # Libraries
1636
1637 if(WITH_GTESTS)
1638         include(GTestTesting)
1639 endif()
1640
1641 if(WITH_BLENDER OR WITH_PLAYER)
1642         add_subdirectory(intern)
1643         add_subdirectory(extern)
1644
1645         # source after intern and extern to gather all
1646         # internal and external library information first, for test linking
1647         add_subdirectory(source)
1648 elseif(WITH_CYCLES_STANDALONE)
1649         add_subdirectory(intern/cycles)
1650         add_subdirectory(extern/clew)
1651         if(WITH_CUDA_DYNLOAD)
1652                 add_subdirectory(extern/cuew)
1653         endif()
1654         if(NOT WITH_SYSTEM_GLEW)
1655                 add_subdirectory(extern/glew)
1656         endif()
1657 endif()
1658
1659 #-----------------------------------------------------------------------------
1660 # Blender Application
1661 if(WITH_BLENDER)
1662         add_subdirectory(source/creator)
1663 endif()
1664
1665
1666 #-----------------------------------------------------------------------------
1667 # Blender Player
1668 if(WITH_PLAYER)
1669         add_subdirectory(source/blenderplayer)
1670 endif()
1671
1672
1673 #-----------------------------------------------------------------------------
1674 # Testing
1675 add_subdirectory(tests)
1676
1677
1678 #-----------------------------------------------------------------------------
1679 # CPack for generating packages
1680 include(build_files/cmake/packaging.cmake)
1681
1682 #-----------------------------------------------------------------------------
1683 # Use dynamic loading for OpenMP
1684 if(WITH_BLENDER)
1685         openmp_delayload(blender)
1686 endif(WITH_BLENDER)
1687 if(WITH_PLAYER)
1688         openmp_delayload(blenderplayer)
1689 endif(WITH_PLAYER)
1690
1691 #-----------------------------------------------------------------------------
1692 # Print Final Configuration
1693
1694 if(FIRST_RUN)
1695
1696         set(_config_msg "\nBlender Configuration\n=====================")
1697
1698         function(info_cfg_option
1699                 _setting
1700                 )
1701
1702                 set(_msg "  - ${_setting}")
1703                 string(LENGTH "${_msg}" _len)
1704                 while("32" GREATER "${_len}")
1705                         set(_msg "${_msg} ")
1706                         math(EXPR _len "${_len} + 1")
1707                 endwhile()
1708
1709                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
1710         endfunction()
1711
1712         function(info_cfg_text
1713                 _text
1714                 )
1715
1716                 set(_config_msg "${_config_msg}\n\n  ${_text}" PARENT_SCOPE)
1717         endfunction()
1718
1719         message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
1720         message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
1721
1722         info_cfg_text("Build Options:")
1723         info_cfg_option(WITH_GAMEENGINE)
1724         info_cfg_option(WITH_PLAYER)
1725         info_cfg_option(WITH_BULLET)
1726         info_cfg_option(WITH_IK_SOLVER)
1727         info_cfg_option(WITH_IK_ITASC)
1728         info_cfg_option(WITH_OPENCOLLADA)
1729         info_cfg_option(WITH_FFTW3)
1730         info_cfg_option(WITH_INTERNATIONAL)
1731         info_cfg_option(WITH_INPUT_NDOF)
1732         info_cfg_option(WITH_CYCLES)
1733         info_cfg_option(WITH_FREESTYLE)
1734         info_cfg_option(WITH_OPENCOLORIO)
1735         info_cfg_option(WITH_OPENVDB)
1736         info_cfg_option(WITH_ALEMBIC)
1737
1738         info_cfg_text("Compiler Options:")
1739         info_cfg_option(WITH_BUILDINFO)
1740         info_cfg_option(WITH_OPENMP)
1741         info_cfg_option(WITH_RAYOPTIMIZATION)
1742
1743         info_cfg_text("System Options:")
1744         info_cfg_option(WITH_INSTALL_PORTABLE)
1745         info_cfg_option(WITH_X11_ALPHA)
1746         info_cfg_option(WITH_X11_XF86VMODE)
1747         info_cfg_option(WITH_X11_XINPUT)
1748         info_cfg_option(WITH_MEM_JEMALLOC)
1749         info_cfg_option(WITH_MEM_VALGRIND)
1750         info_cfg_option(WITH_SYSTEM_GLEW)
1751         info_cfg_option(WITH_SYSTEM_OPENJPEG)
1752
1753         info_cfg_text("Image Formats:")
1754         info_cfg_option(WITH_OPENIMAGEIO)
1755         info_cfg_option(WITH_IMAGE_CINEON)
1756         info_cfg_option(WITH_IMAGE_DDS)
1757         info_cfg_option(WITH_IMAGE_HDR)
1758         info_cfg_option(WITH_IMAGE_OPENEXR)
1759         info_cfg_option(WITH_IMAGE_OPENJPEG)
1760         info_cfg_option(WITH_IMAGE_TIFF)
1761
1762         info_cfg_text("Audio:")
1763         info_cfg_option(WITH_OPENAL)
1764         info_cfg_option(WITH_SDL)
1765         info_cfg_option(WITH_SDL_DYNLOAD)
1766         info_cfg_option(WITH_JACK)
1767         info_cfg_option(WITH_JACK_DYNLOAD)
1768         info_cfg_option(WITH_CODEC_AVI)
1769         info_cfg_option(WITH_CODEC_FFMPEG)
1770         info_cfg_option(WITH_CODEC_SNDFILE)
1771
1772         info_cfg_text("Compression:")
1773         info_cfg_option(WITH_LZMA)
1774         info_cfg_option(WITH_LZO)
1775
1776         info_cfg_text("Python:")
1777         info_cfg_option(WITH_PYTHON_INSTALL)
1778         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
1779         info_cfg_option(WITH_PYTHON_MODULE)
1780         info_cfg_option(WITH_PYTHON_SAFETY)
1781         if(APPLE)
1782                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
1783         endif()
1784
1785         info_cfg_text("Modifiers:")
1786         info_cfg_option(WITH_MOD_BOOLEAN)
1787         info_cfg_option(WITH_MOD_REMESH)
1788         info_cfg_option(WITH_MOD_FLUID)
1789         info_cfg_option(WITH_MOD_OCEANSIM)
1790
1791         info_cfg_text("OpenGL:")
1792         info_cfg_option(WITH_GLEW_ES)
1793         info_cfg_option(WITH_GLU)
1794         info_cfg_option(WITH_GL_EGL)
1795         info_cfg_option(WITH_GL_PROFILE_COMPAT)
1796         info_cfg_option(WITH_GL_PROFILE_CORE)
1797         info_cfg_option(WITH_GL_PROFILE_ES20)
1798         if(WIN32)
1799                 info_cfg_option(WITH_GL_ANGLE)
1800         endif()
1801
1802         info_cfg_text("")
1803
1804         message("${_config_msg}")
1805 endif()
1806
1807 if(0)
1808         print_all_vars()
1809 endif()
1810