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