CMake: Fix indentation around LLVM detection code
[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 (${CMAKE_VERSION} VERSION_LESS 3.0))
51         # keep until CMake-3.0 is min requirement
52         cmake_policy(SET CMP0043 OLD)
53 endif()
54
55 if(NOT EXECUTABLE_OUTPUT_PATH)
56         set(FIRST_RUN TRUE)
57 else()
58         set(FIRST_RUN FALSE)
59 endif()
60
61 # this starts out unset
62 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
63
64 # avoid having empty buildtype
65 set(CMAKE_BUILD_TYPE_INIT "Release")
66
67 # quiet output for Makefiles, 'make -s' helps too
68 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
69
70 # global compile definitions since add_definitions() adds for all.
71 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
72 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
73 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
74 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
75
76 #-----------------------------------------------------------------------------
77 # Set policy
78
79 # see "cmake --help-policy CMP0003"
80 # So library linking is more sane
81 cmake_policy(SET CMP0003 NEW)
82
83 # So BUILDINFO and BLENDERPATH strings are automatically quoted
84 cmake_policy(SET CMP0005 NEW)
85
86 # So syntax problems are errors
87 cmake_policy(SET CMP0010 NEW)
88
89 # Input directories must have CMakeLists.txt
90 cmake_policy(SET CMP0014 NEW)
91
92 #-----------------------------------------------------------------------------
93 # Load some macros.
94 include(build_files/cmake/macros.cmake)
95
96
97 #-----------------------------------------------------------------------------
98 # Initialize project.
99
100 blender_project_hack_pre()
101
102 project(Blender)
103
104 blender_project_hack_post()
105
106 enable_testing()
107
108 #-----------------------------------------------------------------------------
109 # Redirect output files
110
111 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
112 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
113 set(TESTS_OUTPUT_DIR ${EXECUTABLE_OUTPUT_PATH}/tests CACHE INTERNAL "" FORCE)
114
115 #-----------------------------------------------------------------------------
116 # Set default config options
117
118 get_blender_version()
119
120
121 #-----------------------------------------------------------------------------
122 # Platform Specific Defaults
123
124 # list of var-names
125 set(_init_vars)
126
127 # initialize to ON
128 macro(option_defaults_init)
129         foreach(_var ${ARGV})
130                 set(${_var} ON)
131                 list(APPEND _init_vars "${_var}")
132         endforeach()
133         unset(_var)
134 endmacro()
135
136 # remove from namespace
137 macro(option_defaults_clear)
138         foreach(_var ${_init_vars})
139                 unset(${_var})
140         endforeach()
141         unset(_var)
142         unset(_init_vars)
143 endmacro()
144
145
146 # values to initialize WITH_****
147 option_defaults_init(
148         _init_BUILDINFO
149         _init_CODEC_FFMPEG
150         _init_CYCLES_OSL
151         _init_IMAGE_OPENEXR
152         _init_IMAGE_REDCODE
153         _init_INPUT_NDOF
154         _init_JACK
155         _init_LIBMV_SCHUR_SPECIALIZATION
156         _init_OPENCOLLADA
157         _init_OPENCOLORIO
158         _init_SDL
159         _init_FFTW3
160         _init_GAMEENGINE
161 )
162
163 # customize...
164 if(UNIX AND NOT APPLE)
165         # some of these libraries are problematic on Linux
166         # disable less important dependencies by default
167         set(_init_BUILDINFO                      OFF)
168         set(_init_CODEC_FFMPEG                   OFF)
169         set(_init_CYCLES_OSL                     OFF)
170         set(_init_IMAGE_OPENEXR                  OFF)
171         set(_init_IMAGE_REDCODE                  OFF)
172         set(_init_INPUT_NDOF                     OFF)
173         set(_init_JACK                           OFF)
174         set(_init_LIBMV_SCHUR_SPECIALIZATION     OFF)
175         set(_init_OPENCOLLADA                    OFF)
176         set(_init_OPENCOLORIO                    OFF)
177         set(_init_SDL                            OFF)
178         set(_init_FFTW3                          OFF)
179         set(_init_GAMEENGINE                     OFF)
180 endif()
181
182
183 #-----------------------------------------------------------------------------
184 # Options
185
186 # First platform spesific non-cached vars
187 if(UNIX AND NOT APPLE)
188         set(WITH_X11 ON)
189 endif()
190
191 # Blender internal features
192 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
193 mark_as_advanced(WITH_BLENDER)
194
195 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
196
197 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
198 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON) 
199 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
200 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distributions see this as a security issue, rather than have them patch it, make a build option.
201
202 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)
203 mark_as_advanced(WITH_PYTHON_SAFETY)
204 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)
205 if(APPLE)
206         option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
207 endif()
208
209 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ${_init_BUILDINFO})
210 if(${CMAKE_VERSION} VERSION_LESS 2.8.8)
211         # add_library OBJECT arg unsupported
212         set(WITH_BUILDINFO OFF)
213 endif()
214
215 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
216 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
217 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" ${_init_FFTW3})
218 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
219 option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
220 mark_as_advanced(WITH_SYSTEM_BULLET)
221 option(WITH_GAMEENGINE    "Enable Game Engine" ${_init_GAMEENGINE})
222 option(WITH_PLAYER        "Build Player" OFF)
223 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ${_init_OPENCOLORIO})
224 option(WITH_COMPOSITOR    "Enable the tile based nodal compositor" ON)
225
226 # GHOST Windowing Library Options
227 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
228 mark_as_advanced(WITH_GHOST_DEBUG)
229
230 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
231 mark_as_advanced(WITH_GHOST_SDL)
232
233 if(WITH_X11)
234         option(WITH_GHOST_XDND    "Enable drag'n'drop support on X11 using XDND protocol" ON)
235 endif()
236
237 # Misc...
238 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
239 mark_as_advanced(WITH_HEADLESS)
240
241 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
242 mark_as_advanced(WITH_AUDASPACE)
243
244 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
245
246 if(WITH_X11)
247         option(WITH_X11_XINPUT    "Enable X11 Xinput (tablet support and unicode input)"  ON)
248         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"                       ON)
249 endif()
250
251 if(UNIX AND NOT APPLE)
252         option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" ON)
253         option(WITH_SYSTEM_GLES "Use OpenGL ES library provided by the operating system"           ON)
254 else()
255         # not an option for other OS's
256         set(WITH_SYSTEM_GLEW OFF)
257         set(WITH_SYSTEM_GLES OFF)
258 endif()
259
260
261 # (unix defaults to System OpenJPEG On)
262 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" OFF)
263
264 if(UNIX AND NOT APPLE)
265         option(WITH_SYSTEM_EIGEN3 "Use the systems Eigen3 library" OFF)
266 endif()
267
268
269 # Modifiers
270 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
271 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
272 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
273 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
274 # option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)  # this is now only available in a branch
275 # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
276 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
277
278 # Image format support
279 option(WITH_OPENIMAGEIO         "Enable OpenImageIO Support (http://www.openimageio.org)" ON)
280 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ${_init_IMAGE_OPENEXR})
281 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
282 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
283 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
284 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
285 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
286 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" ${_init_IMAGE_REDCODE})
287 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
288
289 # Audio/Video format support
290 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
291 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" ${_init_CODEC_FFMPEG})
292 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
293
294 if(APPLE)
295         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" ON)
296 endif()
297
298 # 3D format support
299 # Disable opencollada when we don't have precompiled libs
300 option(WITH_OPENCOLLADA   "Enable OpenCollada Support (http://www.opencollada.org)" ${_init_OPENCOLLADA})
301
302 # Sound output
303 option(WITH_SDL           "Enable SDL for sound and joystick support" ${_init_SDL})
304 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
305 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" ${_init_JACK})
306 if(UNIX AND NOT APPLE)
307         option(WITH_JACK_DYNLOAD  "Enable runtime dynamic Jack libraries loading" OFF)
308 endif()
309 if(UNIX AND NOT APPLE)
310         option(WITH_SDL_DYNLOAD  "Enable runtime dynamic SDL libraries loading" OFF)
311 endif()
312
313 # Compression
314 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
315 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
316 if(UNIX AND NOT APPLE)
317         option(WITH_SYSTEM_LZO    "Use the system LZO library" OFF)
318 endif()
319
320 # Camera/motion tracking
321 option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
322 option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." ${_init_LIBMV_SCHUR_SPECIALIZATION})
323 mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
324
325 # Freestyle
326 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
327
328 # Misc
329 if(WIN32)
330         option(WITH_INPUT_IME "Enable Input Method Editor (IME) for complex Asian character input" ON)
331 endif()
332 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ${_init_INPUT_NDOF})
333 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
334 option(WITH_OPENNL        "Enable use of Open Numerical Library" ON)
335 if(UNIX AND NOT APPLE)
336         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
337         option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
338         if(WITH_STATIC_LIBS)
339                 option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
340                 mark_as_advanced(WITH_BOOST_ICU)
341         endif()
342 endif()
343 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
344 option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
345 set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
346 mark_as_advanced(PYTHON_NUMPY_PATH)
347 option(WITH_CPU_SSE              "Enable SIMD instruction if they're detected on the host machine" ON)
348 mark_as_advanced(WITH_CPU_SSE)
349
350 if(UNIX AND NOT APPLE)
351         option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
352         set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
353         mark_as_advanced(PYTHON_REQUESTS_PATH)
354 endif()
355
356 # Cycles
357 option(WITH_CYCLES                                      "Enable cycles Render Engine" ON)
358 option(WITH_CYCLES_STANDALONE           "Build cycles standalone application" OFF)
359 option(WITH_CYCLES_STANDALONE_GUI       "Build cycles standalone with GUI" OFF)
360 option(WITH_CYCLES_OSL                          "Build Cycles with OSL support" ${_init_CYCLES_OSL})
361 option(WITH_CYCLES_CUDA_BINARIES        "Build cycles CUDA binaries" OFF)
362 set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_50 sm_52 CACHE STRING "CUDA architectures to build binaries for")
363 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
364 unset(PLATFORM_DEFAULT)
365 option(WITH_CYCLES_LOGGING      "Build cycles with logging support" ON)
366 option(WITH_CYCLES_DEBUG        "Build cycles with extra debug capabilities" OFF)
367 mark_as_advanced(WITH_CYCLES_LOGGING)
368 mark_as_advanced(WITH_CYCLES_DEBUG)
369
370 # LLVM
371 option(WITH_LLVM                                        "Use LLVM" OFF)
372 if(APPLE)
373         option(LLVM_STATIC                                      "Link with LLVM static libraries" ON) # we prefer static llvm build on Apple, dyn build possible though
374 else()
375         option(LLVM_STATIC                                      "Link with LLVM static libraries" OFF)
376 endif()
377 mark_as_advanced(LLVM_STATIC)
378
379 # disable for now, but plan to support on all platforms eventually
380 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" ON)
381 mark_as_advanced(WITH_MEM_JEMALLOC)
382
383 # currently only used for BLI_mempool
384 option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
385 mark_as_advanced(WITH_MEM_VALGRIND)
386
387 # Debug
388 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
389 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
390
391 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
392 mark_as_advanced(WITH_ASSERT_ABORT)
393
394 option(WITH_BOOST                                       "Enable features depending on boost" ON)
395
396 # Unit testsing
397 option(WITH_GTESTS "Enable GTest unit testing" OFF)
398
399
400 # Documentation
401 if(UNIX AND NOT APPLE)
402         option(WITH_DOC_MANPAGE "Create a manual page (Unix manpage)" OFF)
403 endif()
404
405
406 # OpenGL
407
408 option(WITH_GLEW_MX             "Support multiple GLEW contexts (experimental)"                                                                     OFF )
409 option(WITH_GLEW_ES             "Switches to experimental copy of GLEW that has support for OpenGL ES. (temporary option for development purposes)" OFF)
410 option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of the platform specific OpenGL system library (CGL, glX, or WGL)"       OFF)
411 option(WITH_GL_PROFILE_COMPAT   "Support using the OpenGL 'compatibility' profile. (deprecated)"                                                    ON )
412 option(WITH_GL_PROFILE_CORE     "Support using the OpenGL 3.2+ 'core' profile."                                                                     OFF)
413 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (thru either EGL or the AGL/WGL/XGL 'es20' profile)"                                  OFF)
414
415 mark_as_advanced(
416         WITH_GLEW_MX
417         WITH_GLEW_ES
418         WITH_GL_EGL
419         WITH_GL_PROFILE_COMPAT
420         WITH_GL_PROFILE_CORE
421         WITH_GL_PROFILE_ES20
422 )
423
424 if(WITH_GL_PROFILE_COMPAT)
425         set(WITH_GLU ON)
426 else()
427         set(WITH_GLU OFF)
428 endif()
429
430 if(WIN32)
431         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)
432         mark_as_advanced(WITH_GL_ANGLE)
433 endif()
434
435 if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
436         message(WARNING Ignoring WITH_SYSTEM_GLEW and using WITH_GLEW_ES)
437         set(WITH_SYSTEM_GLEW OFF)
438 endif()
439
440 if(MSVC)
441         getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
442         set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
443 endif()
444
445 # Experimental support of C++11
446 option(WITH_CPP11 "Build with C++11 standard enabled, for development use only!" OFF)
447 mark_as_advanced(WITH_CPP11)
448
449 # Dependency graph
450 option(WITH_LEGACY_DEPSGRAPH "Build Blender with legacy dependency graph" ON)
451 mark_as_advanced(WITH_LEGACY_DEPSGRAPH)
452
453 # avoid using again
454 option_defaults_clear()
455
456 # end option(...)
457
458
459
460 # By default we want to install to the directory we are compiling our executables
461 # unless specified otherwise, which we currently do not allow
462 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
463         if(MSVC)
464                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
465         elseif(APPLE)
466                 set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
467         else()
468                 if(WITH_INSTALL_PORTABLE)
469                         set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH} CACHE PATH "default install path" FORCE)
470                 endif()
471         endif()
472 endif()
473
474
475
476 # Apple
477
478 if(APPLE)
479         if(${CMAKE_VERSION} VERSION_LESS 3.0) # else breaks setting CMP0043 policy
480                 cmake_minimum_required(VERSION 2.8.8)
481                 cmake_policy(VERSION 2.8.8)
482         endif()
483
484         if(NOT CMAKE_OSX_ARCHITECTURES)
485                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
486                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
487                 FORCE)
488         endif()
489         
490         execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
491         if(${MAC_SYS} MATCHES 14)
492                 set(OSX_SYSTEM 10.10)
493                 # throw an error here, older cmake cannot handle 2 digit subversion!
494                 cmake_minimum_required(VERSION 3.0.0)
495         elseif(${MAC_SYS} MATCHES 13)
496                 set(OSX_SYSTEM 10.9)
497         elseif(${MAC_SYS} MATCHES 12)
498                 set(OSX_SYSTEM 10.8)
499         elseif(${MAC_SYS} MATCHES 11)
500                 set(OSX_SYSTEM 10.7)
501         elseif(${MAC_SYS} MATCHES 10)
502                 set(OSX_SYSTEM 10.6)
503         elseif(${MAC_SYS} MATCHES 9)
504                 set(OSX_SYSTEM 10.5)
505         else()
506                 set(OSX_SYSTEM unsupported)
507         endif()
508         message(STATUS "Detected system-version: " ${OSX_SYSTEM})
509         
510         # workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not take xcode-select path into accout
511         # but would always look into /Applications/Xcode.app while dev versions are named Xcode<version>-DP<preview_number>
512         execute_process(COMMAND xcode-select --print-path  OUTPUT_VARIABLE XCODE_CHECK OUTPUT_STRIP_TRAILING_WHITESPACE)
513         string(REPLACE "/Contents/Developer" "" XCODE_BUNDLE ${XCODE_CHECK}) # truncate to bundlepath in any case
514         message(STATUS "Xcode-bundle : " ${XCODE_BUNDLE})
515         
516         if(${CMAKE_GENERATOR} MATCHES "Xcode")
517         
518                 if(${XCODE_VERSION} VERSION_GREATER 4.2) # earlier xcode has no bundled developer dir, no sense in getting xcode path from
519                         string(SUBSTRING "${XCODE_CHECK}" 14 6 DP_NAME) # reduce to XCode name without dp extension
520                         if(${DP_NAME} MATCHES Xcode5)
521                                 set(XCODE_VERSION 5)
522                         endif()
523                 endif()
524
525                 ##### cmake incompatibility with xcode  4.3 and higher #####
526                 if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
527                         message(FATAL_ERROR "Xcode 4.3 and higher must be used with cmake 2.8-8 or higher")
528                 endif()
529                 ### end cmake incompatibility with xcode 4.3 and higher ###
530                 
531                 if(${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4 AND ${XCODE_VERSION} VERSION_LESS 4.3)
532                         # Xcode 4 defaults to the Apple LLVM Compiler.
533                         # Override the default compiler selection because Blender only compiles with gcc up to xcode 4.2
534                         set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
535                         message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
536                 endif()
537         else() # unix makefile generator does not fill XCODE_VERSION var, so we get it with a command
538                 execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILD_NR)
539                 string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
540                 unset(XCODE_VERS_BUILD_NR)
541         endif()
542         
543         message(STATUS "Detected Xcode-version: " ${XCODE_VERSION})
544
545         if(${XCODE_VERSION} VERSION_LESS 4.3)
546                 set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)  # use guaranteed existing sdk
547         else()
548                 # note: xcode-select path could be ambigous, cause /Applications/Xcode.app/Contents/Developer or /Applications/Xcode.app would be allowed
549                 # so i use a selfcomposed bundlepath here  
550                 set(OSX_SYSROOT_PREFIX ${XCODE_BUNDLE}/Contents/Developer/Platforms/MacOSX.platform)
551                 message(STATUS "OSX_SYSROOT_PREFIX: " ${OSX_SYSROOT_PREFIX})
552                 set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
553                 set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
554                 if(${CMAKE_GENERATOR} MATCHES "Xcode")
555                         set(CMAKE_XCODE_ATTRIBUTE_SDKROOT macosx${OSX_SYSTEM}) # to silence sdk not found warning, just overrides CMAKE_OSX_SYSROOT
556                 endif()
557         endif()
558
559         if(OSX_SYSTEM MATCHES 10.9)
560                 set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT}) # make sure syslibs and headers are looked up in sdk ( expecially for 10.9 openGL atm. )
561         endif()
562
563         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
564                 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.6" CACHE STRING "" FORCE) # 10.6 is our min. target, if you use higher sdk, weak linking happens
565         endif()
566         
567         if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
568                 # force CMAKE_OSX_DEPLOYMENT_TARGET for makefiles, will not work else ( cmake bug ? )
569                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
570                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
571                 add_definitions("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
572         endif()
573
574         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
575 endif()
576
577
578 #-----------------------------------------------------------------------------
579 # Check for conflicting/unsupported configurations
580
581 if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_STANDALONE)
582         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER or WITH_CYCLES_STANDALONE must be enabled, nothing to do!")
583 endif()
584
585 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
586         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
587 endif()
588
589 if(NOT WITH_AUDASPACE)
590         if(WITH_OPENAL)
591                 message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
592         endif()
593         if(WITH_JACK)
594                 message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
595         endif()
596         if(WITH_GAMEENGINE)
597                 message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
598         endif()
599 endif()
600
601 if(NOT WITH_SDL AND WITH_GHOST_SDL)
602         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
603 endif()
604
605 if(WITH_IMAGE_REDCODE AND ((NOT WITH_IMAGE_OPENJPEG) OR (NOT WITH_CODEC_FFMPEG)))
606         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG and WITH_CODEC_FFMPEG")
607 endif()
608
609 # python module, needs some different options
610 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
611         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
612 endif()
613
614 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
615         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
616 endif()
617
618
619 # may as well build python module without a UI
620 if(WITH_PYTHON_MODULE)
621         set(WITH_HEADLESS ON)
622 endif()
623
624 if(NOT WITH_PYTHON)
625         set(WITH_CYCLES OFF)
626 endif()
627
628 # enable boost for cycles, audaspace or i18n
629 # otherwise if the user disabled
630 if(NOT WITH_BOOST)
631         # Explicitly disabled. so disable all deps.
632         macro(set_and_warn
633                 _setting _val)
634                 if(${${_setting}})
635                         message(STATUS "'WITH_BOOST' is disabled: forceing 'set(${_setting} ${_val})'")
636                 endif()
637                 set(${_setting} ${_val})
638         endmacro()
639
640         set_and_warn(WITH_CYCLES         OFF)
641         set_and_warn(WITH_AUDASPACE      OFF)
642         set_and_warn(WITH_INTERNATIONAL  OFF)
643
644         set_and_warn(WITH_OPENAL         OFF)  # depends on AUDASPACE
645         set_and_warn(WITH_GAMEENGINE     OFF)  # depends on AUDASPACE
646 elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_AUDASPACE OR WITH_INTERNATIONAL)
647         # Keep enabled
648 else()
649         # Enabled but we don't need it
650         set(WITH_BOOST OFF)
651 endif()
652
653 # auto enable openimageio for cycles
654 if(WITH_CYCLES)
655         set(WITH_OPENIMAGEIO ON)
656
657         # auto enable llvm for cycles_osl
658         if(WITH_CYCLES_OSL)
659                 set(WITH_LLVM ON CACHE BOOL "" FORCE)
660         endif()
661 else()
662         set(WITH_CYCLES_OSL OFF)
663 endif()
664
665 # auto enable openimageio linking dependencies
666 if(WITH_OPENIMAGEIO)
667         set(WITH_IMAGE_OPENEXR ON)
668         set(WITH_IMAGE_TIFF ON)
669 endif()
670
671 # don't store paths to libs for portable distribution
672 if(WITH_INSTALL_PORTABLE)
673         set(CMAKE_SKIP_BUILD_RPATH TRUE)
674 endif()
675
676 if(WITH_GHOST_SDL OR WITH_HEADLESS)
677         set(WITH_X11           OFF)
678         set(WITH_X11_XINPUT    OFF)
679         set(WITH_X11_XF86VMODE OFF)
680         set(WITH_GHOST_XDND    OFF)
681         set(WITH_INPUT_IME     OFF)
682 endif()
683
684 if(WITH_CPU_SSE)
685         TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
686 else()
687         message(STATUS "SSE and SSE2 optimizations are DISABLED!")
688         set(COMPILER_SSE_FLAG)
689         set(COMPILER_SSE2_FLAG)
690 endif()
691
692 TEST_STDBOOL_SUPPORT()
693 if(HAVE_STDBOOL_H)
694         add_definitions(-DHAVE_STDBOOL_H)
695 endif()
696
697 #-----------------------------------------------------------------------------
698 # Check for valid directories
699 # ... a partial checkout may cause this.
700 #
701 # note: we need to check for a known subdir in both cases.
702 #       since uninitialized git submodules will give blank dirs
703
704 if(WITH_INTERNATIONAL)
705         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
706                 message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
707                                                 "This is a 'git submodule', which are known not to work with bridges to other version "
708                                                 "control systems, disabling 'WITH_INTERNATIONAL'.")
709                 set(WITH_INTERNATIONAL OFF)
710         endif()
711 endif()
712
713 if(WITH_PYTHON)
714         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
715                 message(WARNING "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
716                                                 "This is a 'git submodule', which are known not to work with bridges to other version "
717                                                 "control systems: * CONTINUING WITHOUT ADDONS *")
718         endif()
719 endif()
720
721 #-----------------------------------------------------------------------------
722 # Initialize un-cached vars, avoid unused warning
723
724 # linux only, not cached
725 set(WITH_BINRELOC OFF)
726
727 # MAXOSX only, set to avoid uninitialized
728 set(EXETYPE "")
729
730 # C/C++ flags
731 set(PLATFORM_CFLAGS)
732
733 # these are added to later on.
734 set(C_WARNINGS)
735 set(CXX_WARNINGS)
736
737 # for gcc -Wno-blah-blah
738 set(CC_REMOVE_STRICT_FLAGS)
739
740 # libraries to link the binary with passed to target_link_libraries()
741 # known as LLIBS to scons
742 set(PLATFORM_LINKLIBS "")
743
744 # Added to linker flags in setup_liblinks
745 # - CMAKE_EXE_LINKER_FLAGS
746 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
747 set(PLATFORM_LINKFLAGS "")
748 set(PLATFORM_LINKFLAGS_DEBUG "")
749
750
751 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
752 # On Unix:
753 #   cmake ../blender \
754 #         -D PYTHON_VERSION=3.4 \
755 #         -D PYTHON_INCLUDE_DIR=/opt/py34/include/python3.4d \
756 #         -D PYTHON_LIBRARY=/opt/py34/lib/libpython3.4d.so
757 #
758 # On Macs:
759 #   cmake ../blender \
760 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4 \
761 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/config \
762 #         -G Xcode
763 #
764 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
765
766 #-----------------------------------------------------------------------------
767 #Platform specifics
768
769 if(WITH_X11)
770         find_package(X11 REQUIRED)
771
772         find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
773         mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
774
775         list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
776
777         if(WITH_X11_XINPUT)
778                 if(X11_Xinput_LIB)
779                         list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
780                 else()
781                         set(WITH_X11_XINPUT OFF)
782                 endif()
783         endif()
784
785         if(WITH_X11_XF86VMODE)
786                 # XXX, why dont cmake make this available?
787                 find_library(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
788                 mark_as_advanced(X11_Xxf86vmode_LIB)
789                 if(X11_Xxf86vmode_LIB)
790                         list(APPEND PLATFORM_LINKLIBS ${X11_Xxf86vmode_LIB})
791                 else()
792                         set(WITH_X11_XF86VMODE OFF)
793                 endif()
794         endif()
795
796 endif()
797
798 if(UNIX AND NOT APPLE)
799         macro(find_package_wrapper)
800                 if(WITH_STATIC_LIBS)
801                         set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
802                         set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
803                 endif()
804                 find_package(${ARGV})
805                 if(WITH_STATIC_LIBS)
806                         set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
807                         unset(_cmake_find_library_suffixes_back)
808                 endif()
809         endmacro()
810
811         find_package_wrapper(JPEG REQUIRED)
812         find_package_wrapper(PNG REQUIRED)
813         find_package_wrapper(ZLIB REQUIRED)
814         find_package_wrapper(Freetype REQUIRED)
815
816         if(WITH_LZO AND WITH_SYSTEM_LZO)
817                 find_package_wrapper(LZO)
818                 if(NOT LZO_FOUND)
819                         message(FATAL_ERROR "Failed finding system LZO version!")
820                 endif()
821         endif()
822
823         if(WITH_SYSTEM_EIGEN3)
824                 find_package_wrapper(Eigen3)
825                 if(NOT EIGEN3_FOUND)
826                         message(FATAL_ERROR "Failed finding system Eigen3 version!")
827                 endif()
828         endif()
829         # else values are set below for all platforms
830
831         if(WITH_PYTHON)
832                 # No way to set py34. remove for now.
833                 # find_package(PythonLibs)
834
835                 # Use our own instead, since wothout py is such a rare case,
836                 # require this package
837                 # XXX Linking errors with debian static python :/
838 #               find_package_wrapper(PythonLibsUnix REQUIRED)
839                 find_package(PythonLibsUnix REQUIRED)
840         endif()
841
842         if(WITH_IMAGE_OPENEXR)
843                 find_package_wrapper(OpenEXR)  # our own module
844                 if(NOT OPENEXR_FOUND)
845                         set(WITH_IMAGE_OPENEXR OFF)
846                 endif()
847         endif()
848
849         if(WITH_IMAGE_OPENJPEG)
850                 find_package_wrapper(OpenJPEG)
851                 if(NOT OPENJPEG_FOUND)
852                         set(WITH_IMAGE_OPENJPEG OFF)
853                 endif()
854         endif()
855
856         if(WITH_IMAGE_TIFF)
857                 # XXX Linking errors with debian static tiff :/
858 #               find_package_wrapper(TIFF)
859                 find_package(TIFF)
860                 if(NOT TIFF_FOUND)
861                         set(WITH_IMAGE_TIFF OFF)
862                 endif()
863         endif()
864
865         # Audio IO
866         if(WITH_OPENAL)
867                 find_package_wrapper(OpenAL)
868                 if(NOT OPENAL_FOUND)
869                         set(WITH_OPENAL OFF)
870                 endif()
871         endif()
872
873         if(WITH_SDL)
874                 if(WITH_SDL_DYNLOAD)
875                         set(SDL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/extern/sdlew/include/SDL2")
876                         set(SDL_LIBRARY)
877                 else()
878                         find_package_wrapper(SDL2)
879                         if(SDL2_FOUND)
880                                 # Use same names for both versions of SDL until we move to 2.x.
881                                 set(SDL_INCLUDE_DIR "${SDL2_INCLUDE_DIR}")
882                                 set(SDL_LIBRARY "${SDL2_LIBRARY}")
883                                 set(SDL_FOUND "${SDL2_FOUND}")
884                         else()
885                                 find_package_wrapper(SDL)
886                         endif()
887                         mark_as_advanced(
888                                 SDL_INCLUDE_DIR
889                                 SDL_LIBRARY
890                         )
891                         # unset(SDLMAIN_LIBRARY CACHE)
892                         if(NOT SDL_FOUND)
893                                 set(WITH_SDL OFF)
894                         endif()
895                 endif()
896         endif()
897
898         if(WITH_JACK)
899                 find_package_wrapper(Jack)
900                 if(NOT JACK_FOUND)
901                         set(WITH_JACK OFF)
902                 endif()
903         endif()
904
905         # Codecs
906         if(WITH_CODEC_SNDFILE)
907                 find_package_wrapper(SndFile)
908                 if(NOT SNDFILE_FOUND)
909                         set(WITH_CODEC_SNDFILE OFF)
910                 endif()
911         endif()
912
913         if(WITH_CODEC_FFMPEG)
914                 set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
915                 set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
916
917                 mark_as_advanced(FFMPEG)
918
919                 # lame, but until we have proper find module for ffmpeg
920                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
921                 if(EXISTS "${FFMPEG}/include/ffmpeg/")
922                         list(APPEND FFMPEG_INCLUDE_DIRS "${FFMPEG}/include/ffmpeg")
923                 endif()
924                 # end lameness
925
926                 mark_as_advanced(FFMPEG_LIBRARIES)
927                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
928         endif()
929
930         if(WITH_FFTW3)
931                 find_package_wrapper(Fftw3)
932                 if(NOT FFTW3_FOUND)
933                         set(WITH_FFTW3 OFF)
934                 endif()
935         endif()
936
937         if(WITH_OPENCOLLADA)
938                 find_package_wrapper(OpenCOLLADA)
939                 if(OPENCOLLADA_FOUND)
940                         find_package_wrapper(XML2)
941                         find_package_wrapper(PCRE)
942                 else()
943                         set(WITH_OPENCOLLADA OFF)
944                 endif()
945         endif()
946
947         if(WITH_MEM_JEMALLOC)
948                 find_package_wrapper(JeMalloc)
949                 if(NOT JEMALLOC_FOUND)
950                         set(WITH_MEM_JEMALLOC OFF)
951                 endif()
952         endif()
953
954         if(WITH_INPUT_NDOF)
955                 find_package_wrapper(Spacenav)
956                 if(NOT SPACENAV_FOUND)
957                         set(WITH_INPUT_NDOF OFF)
958                 endif()
959
960                 # use generic names within blenders buildsystem.
961                 if(SPACENAV_FOUND)
962                         set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
963                         set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
964                 endif()
965         endif()
966
967         if(WITH_CYCLES_OSL)
968                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
969                 if(NOT OSL_ROOT)
970                         set(OSL_ROOT ${CYCLES_OSL})
971                 endif()
972                 find_package_wrapper(OpenShadingLanguage)
973                 if(OSL_FOUND)
974                         if(${OSL_LIBRARY_VERSION_MAJOR} EQUAL "1" AND ${OSL_LIBRARY_VERSION_MINOR} LESS "6")
975                                 # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
976                                 # otherwise LLVM is missing the osl_allocate_closure_component function
977                                 set(OSL_LIBRARIES ${OSL_OSLCOMP_LIBRARY} -Wl,--whole-archive ${OSL_OSLEXEC_LIBRARY} -Wl,--no-whole-archive ${OSL_OSLQUERY_LIBRARY})
978                         endif()
979                 else()
980                         message(STATUS "OSL not found, disabling it from Cycles")
981                         set(WITH_CYCLES_OSL OFF)
982                 endif()
983         endif()
984
985         if(WITH_BOOST)
986                 # uses in build instructions to override include and library variables
987                 if(NOT BOOST_CUSTOM)
988                         if(WITH_STATIC_LIBS)
989                                 set(Boost_USE_STATIC_LIBS ON)
990                         endif()
991                         set(Boost_USE_MULTITHREADED ON)
992                         set(__boost_packages filesystem regex system thread date_time)
993                         if(WITH_CYCLES_OSL)
994                                 if(NOT (${OSL_LIBRARY_VERSION_MAJOR} EQUAL "1" AND ${OSL_LIBRARY_VERSION_MINOR} LESS "6"))
995                                         list(APPEND __boost_packages wave)
996                                 else()
997                                 endif()
998                         endif()
999                         if(WITH_INTERNATIONAL)
1000                                 list(APPEND __boost_packages locale)
1001                         endif()
1002                         if(WITH_CYCLES_NETWORK)
1003                                 list(APPEND __boost_packages serialization)
1004                         endif()
1005                         find_package(Boost 1.48 COMPONENTS ${__boost_packages})
1006                         if(NOT Boost_FOUND)
1007                                 # try to find non-multithreaded if -mt not found, this flag
1008                                 # doesn't matter for us, it has nothing to do with thread
1009                                 # safety, but keep it to not disturb build setups
1010                                 set(Boost_USE_MULTITHREADED OFF)
1011                                 find_package(Boost 1.48 COMPONENTS ${__boost_packages})
1012                         endif()
1013                         unset(__boost_packages)
1014                         if(Boost_USE_STATIC_LIBS AND WITH_BOOST_ICU)
1015                                 find_package(IcuLinux)
1016                         endif()
1017                         mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
1018                 endif()
1019
1020                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
1021                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
1022                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
1023                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
1024         endif()
1025
1026         if(WITH_OPENIMAGEIO)
1027                 find_package_wrapper(OpenImageIO)
1028                 if(NOT OPENIMAGEIO_PUGIXML_FOUND AND WITH_CYCLES_STANDALONE)
1029                         find_package_wrapper(PugiXML)
1030                 else()
1031                         set(PUGIXML_INCLUDE_DIR "${OPENIMAGEIO_INCLUDE_DIR/OpenImageIO}")
1032                         set(PUGIXML_LIBRARIES "")
1033                 endif()
1034
1035                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
1036                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
1037                 set(OPENIMAGEIO_DEFINITIONS "")
1038
1039                 if(WITH_IMAGE_TIFF)
1040                         list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}")
1041                 endif()
1042                 if(WITH_IMAGE_OPENEXR)
1043                         list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}")
1044                 endif()
1045
1046                 if(NOT OPENIMAGEIO_FOUND)
1047                         set(WITH_OPENIMAGEIO OFF)
1048                         message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
1049                 endif()
1050         endif()
1051
1052         if(WITH_OPENCOLORIO)
1053                 find_package_wrapper(OpenColorIO)
1054
1055                 set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
1056                 set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
1057                 set(OPENCOLORIO_DEFINITIONS)
1058
1059                 if(NOT OPENCOLORIO_FOUND)
1060                         set(WITH_OPENCOLORIO OFF)
1061                         message(STATUS "OpenColorIO not found")
1062                 endif()
1063         endif()
1064
1065         if(WITH_LLVM)
1066         find_package_wrapper(LLVM)
1067
1068         if(NOT LLVM_FOUND)
1069                         set(WITH_LLVM OFF)
1070                         message(STATUS "LLVM not found")
1071                 endif()
1072         endif()
1073
1074         if(WITH_LLVM OR WITH_SDL_DYNLOAD)
1075                 # Fix for conflict with Mesa llvmpipe
1076                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--version-script='${CMAKE_SOURCE_DIR}/source/creator/blender.map'")
1077         endif()
1078
1079         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
1080         list(APPEND PLATFORM_LINKLIBS -lutil -lc -lm)
1081
1082         find_package(Threads REQUIRED)
1083         list(APPEND PLATFORM_LINKLIBS ${CMAKE_THREAD_LIBS_INIT})
1084         # used by other platforms
1085         set(PTHREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
1086
1087         if(CMAKE_DL_LIBS)
1088                 list(APPEND PLATFORM_LINKLIBS ${CMAKE_DL_LIBS})
1089         endif()
1090
1091         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
1092                 if(NOT WITH_PYTHON_MODULE)
1093                         # binreloc is linux only
1094                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
1095                         set(WITH_BINRELOC ON)
1096                 endif()
1097         endif()
1098
1099         # lfs on glibc, all compilers should use
1100         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1101
1102         # GNU Compiler
1103         if(CMAKE_COMPILER_IS_GNUCC)
1104                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
1105
1106                 if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "5.0")
1107                         # GCC5 uses gnu11, until we update, force c89
1108                         # though some c11 features can still be used.
1109                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu89")
1110                 endif()
1111
1112                 # use ld.gold linker if available, could make optional
1113                 execute_process(
1114                         COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version
1115                         ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
1116                 if("${LD_VERSION}" MATCHES "GNU gold")
1117                         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=gold")
1118                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold")
1119                 else()
1120                         message(STATUS "GNU gold linker isn't available, using the default system linker.")
1121                 endif()
1122                 unset(LD_VERSION)
1123
1124         # CLang is the same as GCC for now.
1125         elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
1126                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
1127         # Solaris CC
1128         elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro")
1129                 set(PLATFORM_CFLAGS "-pipe -features=extensions -fPIC -D__FUNCTION__=__func__")
1130                 
1131         # Intel C++ Compiler
1132         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
1133                 # think these next two are broken
1134                 find_program(XIAR xiar)
1135                 if(XIAR)
1136                         set(CMAKE_AR "${XIAR}")
1137                 endif()
1138                 mark_as_advanced(XIAR)
1139
1140                 find_program(XILD xild)
1141                 if(XILD)
1142                         set(CMAKE_LINKER "${XILD}")
1143                 endif()
1144                 mark_as_advanced(XILD)
1145
1146                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
1147                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
1148
1149                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
1150                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
1151                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
1152         endif()
1153
1154 elseif(WIN32)
1155
1156         add_definitions(-DWIN32)
1157
1158         if(MSVC)
1159
1160                 # needed for some MSVC installations
1161                 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
1162                 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
1163                 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
1164
1165                 list(APPEND PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid psapi Dbghelp)
1166
1167                 if(WITH_INPUT_IME)
1168                         list(APPEND PLATFORM_LINKLIBS imm32)
1169                 endif()
1170
1171                 add_definitions(
1172                         -D_CRT_NONSTDC_NO_DEPRECATE
1173                         -D_CRT_SECURE_NO_DEPRECATE
1174                         -D_SCL_SECURE_NO_DEPRECATE
1175                         -D_CONSOLE
1176                         -D_LIB
1177                 )
1178
1179                 # MSVC11 needs _ALLOW_KEYWORD_MACROS to build
1180                 add_definitions(-D_ALLOW_KEYWORD_MACROS)
1181
1182                 if(CMAKE_CL_64)
1183                         # We want to support Vista level ABI for x64
1184                         add_definitions(-D_WIN32_WINNT=0x600)
1185                 endif()
1186
1187                 # Make cmake find the msvc redistributables
1188                 set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
1189                 include(InstallRequiredSystemLibraries)
1190
1191                 set(CMAKE_CXX_FLAGS "/nologo /J /Gd /EHsc /MP" CACHE STRING "MSVC MT C++ flags " FORCE)
1192                 set(CMAKE_C_FLAGS   "/nologo /J /Gd /MP"       CACHE STRING "MSVC MT C++ flags " FORCE)
1193
1194                 if(CMAKE_CL_64)
1195                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1196                 else()
1197                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
1198                 endif()
1199                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1200                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1201                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1202                 if(CMAKE_CL_64)
1203                         set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1204                 else()
1205                         set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
1206                 endif()
1207                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1208                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
1209                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
1210
1211
1212                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
1213
1214                 # MSVC only, Mingw doesnt need
1215                 if(CMAKE_CL_64)
1216                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
1217                 else()
1218                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
1219                 endif()
1220
1221                 set(PLATFORM_LINKFLAGS_DEBUG "/IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
1222
1223                 if(NOT DEFINED LIBDIR)
1224                         # Setup 64bit and 64bit windows systems
1225                         if(CMAKE_CL_64)
1226                                 message(STATUS "64 bit compiler detected.")
1227                                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64_vc12)
1228                         else()
1229                                 message(STATUS "32 bit compiler detected.")
1230                                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows_vc12)
1231                         endif()
1232                 else()
1233                         message(STATUS using LIBDIR  ${LIBDIR})
1234                 endif()
1235
1236                 # Add each of our libraries to our cmake_prefix_path so find_package() could work
1237                 file(GLOB children RELATIVE ${LIBDIR} ${LIBDIR}/*)
1238                 foreach(child ${children})
1239                 if(IS_DIRECTORY ${LIBDIR}/${child})
1240                         list(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
1241                 endif()
1242                 endforeach()
1243
1244                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
1245                 set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz_st.lib)
1246                 set(ZLIB_INCLUDE_DIR ${LIBDIR}/zlib/include)
1247                 set(ZLIB_LIBRARY ${LIBDIR}/zlib/lib/libz_st.lib)
1248                 set(ZLIB_DIR ${LIBDIR}/zlib)
1249                 #find_package(zlib) # we want to find before finding things that depend on it like png
1250
1251
1252                 find_package(png)
1253                 if(NOT PNG_FOUND)
1254                         message(WARNING "Using HARDCODED libpng locations")
1255                         set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
1256                         set(PNG_LIBRARIES libpng)
1257                         set(PNG "${LIBDIR}/png")
1258                         set(PNG_INCLUDE_DIRS "${PNG}/include")
1259                         set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1260                 endif()
1261
1262                 if(MSVC)
1263                         set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
1264                 endif()
1265                 find_package(jpeg REQUIRED)
1266
1267                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
1268                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
1269
1270                 set(FREETYPE ${LIBDIR}/freetype)
1271                 set(FREETYPE_INCLUDE_DIRS
1272                         ${LIBDIR}/freetype/include
1273                         ${LIBDIR}/freetype/include/freetype2
1274                 )
1275                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
1276                 find_package(freetype REQUIRED)
1277
1278                 if(WITH_FFTW3)
1279                         set(FFTW3 ${LIBDIR}/fftw3)
1280                         set(FFTW3_LIBRARIES libfftw)
1281                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1282                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1283                 endif()
1284
1285                 if(WITH_OPENCOLLADA)
1286                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1287
1288                         set(OPENCOLLADA_INCLUDE_DIRS
1289                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1290                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1291                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1292                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1293                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1294                         )
1295
1296                         set(OPENCOLLADA_LIBRARIES
1297                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
1298                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
1299                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
1300                                 ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
1301                                 ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
1302                                 ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
1303                                 ${OPENCOLLADA}/lib/opencollada/xml.lib
1304                                 ${OPENCOLLADA}/lib/opencollada/buffer.lib
1305                                 ${OPENCOLLADA}/lib/opencollada/ftoa.lib
1306                         )
1307
1308                         if(NOT WITH_LLVM)
1309                                 list(APPEND OPENCOLLADA_LIBRARIES ${OPENCOLLADA}/lib/opencollada/UTF.lib)
1310                         endif()
1311
1312                         set(PCRE_LIBRARIES
1313                                 ${OPENCOLLADA}/lib/opencollada/pcre.lib
1314                         )
1315                 endif()
1316
1317                 if(WITH_CODEC_FFMPEG)
1318                         set(FFMPEG_INCLUDE_DIRS
1319                                 ${LIBDIR}/ffmpeg/include
1320                                 ${LIBDIR}/ffmpeg/include/msvc
1321                         )
1322                         find_package(FFMPEG)
1323                         if(NOT FFMPEG_FOUND)
1324                                 message(WARNING "Using HARDCODED ffmpeg locations")
1325                                 set(FFMPEG_LIBRARY_VERSION 55)
1326                                 set(FFMPEG_LIBRARY_VERSION_AVU 52)
1327                                 set(FFMPEG_LIBRARIES
1328                                         ${LIBDIR}/ffmpeg/lib/avcodec-${FFMPEG_LIBRARY_VERSION}.lib
1329                                         ${LIBDIR}/ffmpeg/lib/avformat-${FFMPEG_LIBRARY_VERSION}.lib
1330                                         ${LIBDIR}/ffmpeg/lib/avdevice-${FFMPEG_LIBRARY_VERSION}.lib
1331                                         ${LIBDIR}/ffmpeg/lib/avutil-${FFMPEG_LIBRARY_VERSION_AVU}.lib
1332                                         ${LIBDIR}/ffmpeg/lib/swscale-2.lib
1333                                         )
1334                         endif()
1335                 endif()
1336
1337                 if(WITH_IMAGE_OPENEXR)
1338                         set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
1339                         set(OPENEXR_VERSION "2.1")
1340                         find_package(OPENEXR REQUIRED)
1341                         if(NOT OPENEXR_FOUND)
1342                                 message(WARNING "Using HARDCODED OpenEXR locations")
1343                                 set(OPENEXR ${LIBDIR}/openexr)
1344                                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1345                                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1346                                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1347                                 set(OPENEXR_LIBRARIES
1348                                         ${OPENEXR_LIBPATH}/Iex-2_2.lib
1349                                         ${OPENEXR_LIBPATH}/Half.lib
1350                                         ${OPENEXR_LIBPATH}/IlmImf-2_2.lib
1351                                         ${OPENEXR_LIBPATH}/Imath-2_2.lib
1352                                         ${OPENEXR_LIBPATH}/IlmThread-2_2.lib
1353                                 )
1354                         endif()
1355                 endif()
1356
1357                 if(WITH_IMAGE_TIFF)
1358                 # Try to find tiff first then complain and set static and maybe wrong paths
1359                 find_package(TIFF)
1360                 if(NOT TIFF_FOUND)
1361                         message(WARNING "Using HARDCODED libtiff locations")
1362                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
1363                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
1364                 endif()
1365                 endif()
1366
1367                 if(WITH_JACK)
1368                         set(JACK_INCLUDE_DIRS
1369                                 ${LIBDIR}/jack/include/jack
1370                                 ${LIBDIR}/jack/include
1371                         )
1372                         set(JACK_LIBRARIES optimized ${LIBDIR}/jack/lib/libjack.lib debug ${LIBDIR}/jack/lib/libjack_d.lib)
1373                 endif()
1374
1375                 if(WITH_PYTHON)
1376                         set(PYTHON_VERSION 3.4) # CACHE STRING)
1377
1378                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1379                         # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
1380                         set(PYTHON_LIBRARY ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.lib)
1381                         unset(_PYTHON_VERSION_NO_DOTS)
1382
1383                         # Shared includes for both vc2008 and vc2010
1384                         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
1385
1386                         # uncached vars
1387                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1388                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1389                 endif()
1390
1391                 if(WITH_BOOST)
1392                         if(WITH_CYCLES_OSL)
1393                                 set(boost_extra_libs wave)
1394                         endif()
1395                         if(WITH_INTERNATIONAL)
1396                                 list(APPEND boost_extra_libs locale)
1397                         endif()
1398                         set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
1399                         set(Boost_USE_MULTITHREADED ON) # suffix -mt
1400                         set(Boost_USE_STATIC_LIBS ON) # suffix -s
1401                         find_package(Boost COMPONENTS date_time filesystem thread regex system ${boost_extra_libs})
1402                         if(NOT Boost_FOUND)
1403                                 message(WARNING "USING HARDCODED boost locations")
1404                                 set(BOOST ${LIBDIR}/boost)
1405                                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1406                                 if(MSVC12)
1407                                         set(BOOST_LIBPATH ${BOOST}/lib)
1408                                         set(BOOST_POSTFIX "vc120-mt-s-1_55.lib")
1409                                         set(BOOST_DEBUG_POSTFIX "vc120-mt-sgd-1_55.lib")
1410                                 else()
1411                                         set(BOOST_LIBPATH ${BOOST}/lib)
1412                                         set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
1413                                         set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_49.lib")
1414                                 endif()
1415                                 set(BOOST_LIBRARIES
1416                                         optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
1417                                         optimized libboost_regex-${BOOST_POSTFIX}
1418                                         optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
1419                                         debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
1420                                         debug libboost_regex-${BOOST_DEBUG_POSTFIX}
1421                                         debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
1422                                 if(WITH_CYCLES_OSL)
1423                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1424                                                 optimized libboost_wave-${BOOST_POSTFIX}
1425                                                 debug libboost_wave-${BOOST_DEBUG_POSTFIX})
1426                                 endif()
1427                                 if(WITH_INTERNATIONAL)
1428                                         set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1429                                                 optimized libboost_locale-${BOOST_POSTFIX}
1430                                                 debug libboost_locale-${BOOST_DEBUG_POSTFIX})
1431                                 endif()
1432                         else() # we found boost using find_package
1433                                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
1434                                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
1435                                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
1436                         endif()
1437                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
1438                 endif()
1439                         
1440                 if(WITH_OPENIMAGEIO)
1441                         find_package(OpenImageIO)
1442                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1443                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1444                         set(OIIO_OPTIMIZED optimized OpenImageIO optimized OpenImageIO_Util)
1445                         set(OIIO_DEBUG debug OpenImageIO_d debug OpenImageIO_Util_d)
1446                         set(OPENIMAGEIO_LIBRARIES ${OIIO_OPTIMIZED} ${OIIO_DEBUG})
1447                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1448                         set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
1449                         set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
1450                         set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe")
1451                         add_definitions(-DOIIO_STATIC_BUILD)
1452                 endif()
1453
1454                 if(WITH_LLVM)
1455                         set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
1456                         file(GLOB LLVM_LIBRARY_OPTIMIZED ${LLVM_ROOT_DIR}/lib/*.lib)
1457
1458                         if(EXISTS ${LLVM_ROOT_DIR}/debug/lib)
1459                                 foreach(LLVM_OPTIMIZED_LIB ${LLVM_LIBRARY_OPTIMIZED})
1460                                         get_filename_component(LIBNAME ${LLVM_OPTIMIZED_LIB} ABSOLUTE)
1461                                         list(APPEND LLVM_LIBS optimized ${LIBNAME})
1462                                 endforeach(LLVM_OPTIMIZED_LIB)
1463                         
1464                                 file(GLOB LLVM_LIBRARY_DEBUG ${LLVM_ROOT_DIR}/debug/lib/*.lib)
1465
1466                                 foreach(LLVM_DEBUG_LIB ${LLVM_LIBRARY_DEBUG})
1467                                         get_filename_component(LIBNAME ${LLVM_DEBUG_LIB} ABSOLUTE)
1468                                         list(APPEND LLVM_LIBS debug ${LIBNAME})
1469                                 endforeach(LLVM_DEBUG_LIB)
1470
1471                                 set(LLVM_LIBRARY ${LLVM_LIBS})
1472                         else()
1473                                 message(WARNING "LLVM debug libs not present on this system. Using release libs for debug builds.")
1474                                 set(LLVM_LIBRARY ${LLVM_LIBRARY_OPTIMIZED})
1475                         endif()
1476                         
1477                 endif()
1478         
1479                 if(WITH_OPENCOLORIO)
1480                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1481                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1482                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1483                         set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
1484                         set(OPENCOLORIO_DEFINITIONS)
1485                 endif()
1486                 
1487
1488                 if(WITH_MOD_CLOTH_ELTOPO)
1489                         set(LAPACK ${LIBDIR}/lapack)
1490                         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
1491                         set(LAPACK_LIBPATH ${LAPACK}/lib)
1492                         set(LAPACK_LIBRARIES
1493                                 ${LIBDIR}/lapack/lib/libf2c.lib
1494                                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
1495                                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
1496                         )
1497                 endif()
1498
1499                 if(WITH_SDL)
1500                         set(SDL ${LIBDIR}/sdl)
1501                         set(SDL_INCLUDE_DIR ${SDL}/include)
1502                         set(SDL_LIBRARY SDL2)
1503                         set(SDL_LIBPATH ${SDL}/lib)
1504                 endif()
1505
1506                 # used in many places so include globally, like OpenGL
1507                 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
1508
1509         elseif(CMAKE_COMPILER_IS_GNUCC)
1510                 # keep GCC specific stuff here
1511                 include(CheckCSourceCompiles)
1512                 # Setup 64bit and 64bit windows systems
1513                 CHECK_C_SOURCE_COMPILES("
1514                         #ifndef __MINGW64__
1515                         #error
1516                         #endif
1517                         int main(void) { return 0; }
1518                         " 
1519                         WITH_MINGW64)
1520                 
1521                 if(WITH_MINGW64)
1522                         message(STATUS "Compiling for 64 bit with MinGW-w64.")
1523                         execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
1524                         if(GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
1525                                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64_gcc49)
1526                         else()
1527                                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
1528                         endif()
1529                 else()
1530                         message(STATUS "Compiling for 32 bit with MinGW-w32.")
1531                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
1532                         
1533                         if(WITH_RAYOPTIMIZATION)
1534                                 message(WARNING "MinGW-w32 is known to be unstable with 'WITH_RAYOPTIMIZATION' option enabled.")
1535                         endif()
1536                 endif()
1537                 
1538                 list(APPEND PLATFORM_LINKLIBS -lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi -ldbghelp)
1539
1540                 if(WITH_INPUT_IME)
1541                         list(APPEND PLATFORM_LINKLIBS -limm32)
1542                 endif()
1543
1544                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
1545
1546                 if(WITH_MINGW64)
1547                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
1548                         list(APPEND PLATFORM_LINKLIBS -lpthread)
1549                         
1550                         add_definitions(-DFREE_WINDOWS64 -DMS_WIN64)
1551                 endif()
1552
1553                 add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1554
1555                 add_definitions(-DFREE_WINDOWS)
1556
1557                 set(PNG "${LIBDIR}/png")
1558                 set(PNG_INCLUDE_DIRS "${PNG}/include")
1559                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1560
1561                 if(WITH_MINGW64)
1562                         set(JPEG_LIBRARIES jpeg)
1563                 else()
1564                         set(JPEG_LIBRARIES libjpeg)
1565                 endif()
1566                 set(PNG_LIBRARIES png)
1567
1568                 set(ZLIB ${LIBDIR}/zlib)
1569                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
1570                 set(ZLIB_LIBPATH ${ZLIB}/lib)
1571                 set(ZLIB_LIBRARIES z)
1572
1573                 set(JPEG "${LIBDIR}/jpeg")
1574                 set(JPEG_INCLUDE_DIR "${JPEG}/include")
1575                 set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
1576                 
1577                 # comes with own pthread library
1578                 if(NOT WITH_MINGW64)
1579                         set(PTHREADS ${LIBDIR}/pthreads)
1580                         #set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
1581                         set(PTHREADS_LIBPATH ${PTHREADS}/lib)
1582                         set(PTHREADS_LIBRARIES pthreadGC2)
1583                 endif()
1584                 
1585                 set(FREETYPE ${LIBDIR}/freetype)
1586                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1587                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1588                 set(FREETYPE_LIBRARY freetype)
1589
1590                 if(WITH_FFTW3)
1591                         set(FFTW3 ${LIBDIR}/fftw3)
1592                         set(FFTW3_LIBRARIES fftw3)
1593                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1594                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1595                 endif()
1596
1597                 if(WITH_OPENCOLLADA)
1598                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1599                         set(OPENCOLLADA_INCLUDE_DIRS
1600                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1601                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1602                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1603                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1604                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1605                         )
1606                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib/opencollada)
1607                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver buffer ftoa xml)
1608                         set(PCRE_LIBRARIES pcre)
1609                 endif()
1610
1611                 if(WITH_CODEC_FFMPEG)
1612                         set(FFMPEG ${LIBDIR}/ffmpeg)
1613                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1614                         if(WITH_MINGW64)
1615                                 set(FFMPEG_LIBRARIES avcodec.dll avformat.dll avdevice.dll avutil.dll swscale.dll swresample.dll)
1616                         else()
1617                                 set(FFMPEG_LIBRARIES avcodec-55 avformat-55 avdevice-55 avutil-52 swscale-2)
1618                         endif()
1619                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1620                 endif()
1621
1622                 if(WITH_IMAGE_OPENEXR)
1623                         set(OPENEXR ${LIBDIR}/openexr)
1624                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1625                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1626                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
1627                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1628                 endif()
1629
1630                 if(WITH_IMAGE_TIFF)
1631                         set(TIFF ${LIBDIR}/tiff)
1632                         set(TIFF_LIBRARY tiff)
1633                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
1634                         set(TIFF_LIBPATH ${TIFF}/lib)
1635                 endif()
1636
1637                 if(WITH_JACK)
1638                         set(JACK ${LIBDIR}/jack)
1639                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
1640                         set(JACK_LIBRARIES jack)
1641                         set(JACK_LIBPATH ${JACK}/lib)
1642
1643                         # TODO, gives linking errors, force off
1644                         set(WITH_JACK OFF)
1645                 endif()
1646
1647                 if(WITH_PYTHON)
1648                         # normally cached but not since we include them with blender
1649                         set(PYTHON_VERSION 3.4) #  CACHE STRING)
1650                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1651                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
1652                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}mw.lib")  # CACHE FILEPATH)
1653                         unset(_PYTHON_VERSION_NO_DOTS)
1654
1655                         # uncached vars
1656                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1657                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1658                 endif()
1659
1660                 if(WITH_BOOST)
1661                         set(BOOST ${LIBDIR}/boost)
1662                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1663                         if(WITH_MINGW64)
1664                                 set(BOOST_POSTFIX "mgw47-mt-s-1_49")
1665                                 set(BOOST_DEBUG_POSTFIX "mgw47-mt-sd-1_49")
1666                         else()
1667                                 set(BOOST_POSTFIX "mgw46-mt-s-1_49")
1668                                 set(BOOST_DEBUG_POSTFIX "mgw46-mt-sd-1_49")
1669                         endif()
1670                         set(BOOST_LIBRARIES
1671                                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
1672                                 boost_regex-${BOOST_POSTFIX}
1673                                 boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
1674                                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
1675                                 boost_regex-${BOOST_DEBUG_POSTFIX}
1676                                 boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
1677                         if(WITH_INTERNATIONAL)
1678                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1679                                         optimized boost_locale-${BOOST_POSTFIX}
1680                                         debug boost_locale-${BOOST_DEBUG_POSTFIX}) 
1681                         endif()
1682                         if(WITH_CYCLES_OSL)
1683                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1684                                         optimized boost_wave-${BOOST_POSTFIX}
1685                                         debug boost_wave-${BOOST_DEBUG_POSTFIX}) 
1686                         endif()
1687                         set(BOOST_LIBPATH ${BOOST}/lib)
1688                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
1689                 endif()
1690                         
1691                 if(WITH_OPENIMAGEIO)
1692                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1693                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1694                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1695                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1696                         set(OPENIMAGEIO_DEFINITIONS "")
1697                         set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe")
1698                 endif()
1699                 
1700                 if(WITH_LLVM)
1701                         set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
1702                         set(LLVM_LIBPATH ${LLVM_ROOT_DIR}/lib)
1703                         # Explicitly set llvm lib order.
1704                         #---- WARNING ON GCC ORDER OF LIBS IS IMPORTANT, DO NOT CHANGE! ---------
1705                         set(LLVM_LIBRARY LLVMSelectionDAG LLVMCodeGen LLVMScalarOpts LLVMAnalysis LLVMArchive
1706                                 LLVMAsmParser LLVMAsmPrinter
1707                                 LLVMBitReader LLVMBitWriter
1708                                 LLVMDebugInfo LLVMExecutionEngine
1709                                 LLVMInstCombine LLVMInstrumentation
1710                                 LLVMInterpreter LLVMJIT
1711                                 LLVMLinker LLVMMC
1712                                 LLVMMCDisassembler LLVMMCJIT
1713                                 LLVMMCParser LLVMObject
1714                                 LLVMRuntimeDyld 
1715                                 LLVMSupport
1716                                 LLVMTableGen LLVMTarget
1717                                 LLVMTransformUtils LLVMVectorize
1718                                 LLVMX86AsmParser LLVMX86AsmPrinter
1719                                 LLVMX86CodeGen LLVMX86Desc
1720                                 LLVMX86Disassembler LLVMX86Info
1721                                 LLVMX86Utils LLVMipa
1722                                 LLVMipo LLVMCore)
1723                         # imagehelp is needed by LLVM 3.1 on MinGW, check lib\Support\Windows\Signals.inc
1724                         list(APPEND PLATFORM_LINKLIBS -limagehlp)
1725                 endif()
1726                 
1727                 if(WITH_OPENCOLORIO)
1728                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1729                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1730                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1731                         set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1732                         set(OPENCOLORIO_DEFINITIONS)
1733                 endif()
1734
1735                 if(WITH_SDL)
1736                         set(SDL ${LIBDIR}/sdl)
1737                         set(SDL_INCLUDE_DIR ${SDL}/include)
1738                         set(SDL_LIBRARY SDL)
1739                         set(SDL_LIBPATH ${SDL}/lib)
1740                 endif()
1741
1742                 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
1743
1744                 ## DISABLE - causes linking errors 
1745                 ## for re-distribution, so users dont need mingw installed
1746                 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")
1747
1748         endif()
1749         
1750         # Things common to both mingw and MSVC  should go here
1751
1752         set(WINTAB_INC ${LIBDIR}/wintab/include)
1753
1754         if(WITH_OPENAL)
1755                 set(OPENAL ${LIBDIR}/openal)
1756                 set(OPENALDIR ${LIBDIR}/openal)
1757                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
1758                 if(MSVC12)
1759                         set(OPENAL_LIBRARY openal32)
1760                 else()
1761                         set(OPENAL_LIBRARY wrap_oal)
1762                 endif()
1763                 set(OPENAL_LIBPATH ${OPENAL}/lib)
1764         endif()
1765
1766         if(WITH_CODEC_SNDFILE)
1767                 set(SNDFILE ${LIBDIR}/sndfile)
1768                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1769                 set(SNDFILE_LIBRARIES libsndfile-1)
1770                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
1771         endif()
1772
1773         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
1774                 add_definitions(-D__SSE__ -D__MMX__)
1775         endif()
1776
1777         if(WITH_CYCLES_OSL)
1778                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1779         
1780                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1781                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1782                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1783                 find_library(OSL_LIB_EXEC_DEBUG NAMES oslexec_d PATHS ${CYCLES_OSL}/lib)
1784                 find_library(OSL_LIB_COMP_DEBUG NAMES oslcomp_d PATHS ${CYCLES_OSL}/lib)
1785                 find_library(OSL_LIB_QUERY_DEBUG NAMES oslquery_d PATHS ${CYCLES_OSL}/lib)
1786                 list(APPEND OSL_LIBRARIES optimized ${OSL_LIB_COMP} optimized ${OSL_LIB_EXEC} optimized ${OSL_LIB_QUERY} debug ${OSL_LIB_EXEC_DEBUG} debug ${OSL_LIB_COMP_DEBUG} debug ${OSL_LIB_QUERY_DEBUG})
1787                 find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1788                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1789         
1790                 if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
1791                         set(OSL_FOUND TRUE)
1792                 else()
1793                         message(STATUS "OSL not found")
1794                         set(WITH_CYCLES_OSL OFF)
1795                 endif()
1796         endif()
1797
1798 elseif(APPLE)
1799
1800         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
1801                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/7/8/9
1802         endif()
1803
1804         if(WITH_LIBS10.5)
1805                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1806         else()
1807                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1808                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1809                 else()
1810                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1811                 endif()
1812         endif()
1813
1814
1815         if(WITH_OPENAL)
1816                 find_package(OpenAL)
1817                 if(OPENAL_FOUND)
1818                         set(WITH_OPENAL ON)
1819                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1820                 else()
1821                         set(WITH_OPENAL OFF)
1822                 endif()
1823         endif()
1824
1825         if(WITH_JACK)
1826                 find_library(JACK_FRAMEWORK
1827                         NAMES jackmp
1828                 )
1829                 set(JACK_INCLUDE_DIRS ${JACK_FRAMEWORK}/headers)
1830                 if(NOT JACK_FRAMEWORK)
1831                         set(WITH_JACK OFF)
1832                 endif()
1833         endif()
1834
1835         if(WITH_CODEC_SNDFILE)
1836                 set(SNDFILE ${LIBDIR}/sndfile)
1837                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1838                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1839                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1840         endif()
1841
1842         if(WITH_PYTHON)
1843                 # we use precompiled libraries for py 3.4 and up by default
1844                 set(PYTHON_VERSION 3.4)
1845                 if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
1846                         # normally cached but not since we include them with blender
1847                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
1848                         # set(PYTHON_EXECUTABLE "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1849                         set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
1850                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1851                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1852                 else()
1853                         # module must be compiled against Python framework
1854                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1855                         set(PYTHON_EXECUTABLE "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1856                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1857                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
1858                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1859                 endif()
1860                 
1861                 # uncached vars
1862                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1863                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1864         endif()
1865
1866         if(WITH_FFTW3)
1867                 set(FFTW3 ${LIBDIR}/fftw3)
1868                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1869                 set(FFTW3_LIBRARIES fftw3)
1870                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1871         endif()
1872
1873         set(PNG_LIBRARIES png)
1874         set(JPEG_LIBRARIES jpeg)
1875
1876         set(ZLIB /usr)
1877         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1878         set(ZLIB_LIBRARIES z bz2)
1879
1880         set(FREETYPE ${LIBDIR}/freetype)
1881         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1882         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1883         set(FREETYPE_LIBRARY freetype)
1884
1885         if(WITH_IMAGE_OPENEXR)
1886                 set(OPENEXR ${LIBDIR}/openexr)
1887                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1888                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1889                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1890                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1891         endif()
1892
1893         if(WITH_CODEC_FFMPEG)
1894                 set(FFMPEG ${LIBDIR}/ffmpeg)
1895                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1896                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1897                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1898         endif()
1899
1900         find_library(SYSTEMSTUBS_LIBRARY
1901                 NAMES
1902                 SystemStubs
1903                 PATHS
1904         )
1905         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1906         if(SYSTEMSTUBS_LIBRARY)
1907                 list(APPEND PLATFORM_LINKLIBS stdc++ SystemStubs)
1908         else()
1909                 list(APPEND PLATFORM_LINKLIBS stdc++)
1910         endif()
1911
1912         set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1913         set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1914         if(WITH_CODEC_QUICKTIME)
1915                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1916                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1917                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1918                         # libSDL still needs 32bit carbon quicktime
1919                 endif()
1920         endif()
1921
1922         # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1923         # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1924         if(WITH_INPUT_NDOF)
1925                 # This thread it *should* work and check the framework - campbell
1926                 # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1927                 find_library(3DCONNEXION_CLIENT_FRAMEWORK
1928                         NAMES 3DconnexionClient
1929                 )
1930                 if(NOT 3DCONNEXION_CLIENT_FRAMEWORK)
1931                         set(WITH_INPUT_NDOF OFF)
1932                 endif()
1933
1934                 if(WITH_INPUT_NDOF)
1935                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework 3DconnexionClient")
1936                         set(NDOF_INCLUDE_DIRS /Library/Frameworks/3DconnexionClient.framework/Headers )
1937                 endif()
1938         endif()
1939
1940         if(WITH_JACK)
1941                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework jackmp")
1942         endif()
1943         
1944         if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK)
1945                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")# force cmake to link right framework
1946         endif()
1947         
1948         if(WITH_OPENCOLLADA)
1949                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1950
1951                 set(OPENCOLLADA_INCLUDE_DIRS
1952                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1953                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1954                         ${LIBDIR}/opencollada/include/COLLADAFramework
1955                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1956                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1957                 )
1958
1959                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1960                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lxml2 -lbuffer -lftoa")
1961                 # Use UTF functions from collada if LLVM is not enabled
1962                 if(NOT WITH_LLVM)
1963                         set(OPENCOLLADA_LIBRARIES "${OPENCOLLADA_LIBRARIES} -lUTF")
1964                 endif()
1965                 # pcre is bundled with openCollada
1966                 #set(PCRE ${LIBDIR}/pcre)
1967                 #set(PCRE_LIBPATH ${PCRE}/lib)
1968                 set(PCRE_LIBRARIES pcre)
1969                 #libxml2 is used
1970                 #set(EXPAT ${LIBDIR}/expat)
1971                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1972                 set(EXPAT_LIB)
1973         endif()
1974
1975         if(WITH_SDL)
1976                 set(SDL ${LIBDIR}/sdl)
1977                 set(SDL_INCLUDE_DIR ${SDL}/include)
1978                 set(SDL_LIBRARY SDL2)
1979                 set(SDL_LIBPATH ${SDL}/lib)
1980                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -lazy_framework ForceFeedback")
1981         endif()
1982
1983         set(PNG "${LIBDIR}/png")
1984         set(PNG_INCLUDE_DIRS "${PNG}/include")
1985         set(PNG_LIBPATH ${PNG}/lib)
1986
1987         set(JPEG "${LIBDIR}/jpeg")
1988         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1989         set(JPEG_LIBPATH ${JPEG}/lib)
1990
1991         if(WITH_IMAGE_TIFF)
1992                 set(TIFF ${LIBDIR}/tiff)
1993                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1994                 set(TIFF_LIBRARY tiff)
1995                 set(TIFF_LIBPATH ${TIFF}/lib)
1996         endif()
1997
1998         if(WITH_INPUT_NDOF)
1999                 # linker needs "-weak_framework 3DconnexionClient"
2000         endif()
2001
2002         if(WITH_BOOST)
2003                 set(BOOST ${LIBDIR}/boost)
2004                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
2005                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt boost_wave-mt)
2006                 if(WITH_INTERNATIONAL)
2007                         list(APPEND BOOST_LIBRARIES boost_locale-mt)
2008                 endif()
2009                 if(WITH_CYCLES_NETWORK)
2010                         list(APPEND BOOST_LIBRARIES boost_serialization-mt)
2011                 endif()
2012                 set(BOOST_LIBPATH ${BOOST}/lib)
2013                 set(BOOST_DEFINITIONS)
2014         endif()
2015         
2016         if(WITH_INTERNATIONAL OR WITH_CODEC_FFMPEG)
2017                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -liconv") # boost_locale and ffmpeg needs it !
2018         endif()
2019
2020         if(WITH_OPENIMAGEIO)
2021                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
2022                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
2023                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO}/lib/libOpenImageIO.a ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
2024                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
2025                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
2026                 set(OPENIMAGEIO_IDIFF "${LIBDIR}/openimageio/bin/idiff")
2027         endif()
2028
2029         if(WITH_OPENCOLORIO)
2030                 set(OPENCOLORIO ${LIBDIR}/opencolorio)
2031                 set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
2032                 set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
2033                 set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
2034         endif()
2035
2036         if(WITH_LLVM)
2037                 set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
2038                 set(LLVM_VERSION "3.4" CACHE STRING     "Version of LLVM to use")
2039                 if(EXISTS "${LLVM_ROOT_DIR}/bin/llvm-config")
2040                         set(LLVM_CONFIG "${LLVM_ROOT_DIR}/bin/llvm-config")
2041                 else()
2042                         set(LLVM_CONFIG llvm-config)
2043                 endif()
2044                 execute_process(COMMAND ${LLVM_CONFIG} --version
2045                                 OUTPUT_VARIABLE LLVM_VERSION
2046                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
2047                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
2048                                 OUTPUT_VARIABLE LLVM_ROOT_DIR
2049                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
2050                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
2051                                 OUTPUT_VARIABLE LLVM_LIBPATH
2052                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
2053                 find_library(LLVM_LIBRARY
2054                              NAMES LLVMAnalysis # first of a whole bunch of libs to get
2055                              PATHS ${LLVM_LIBPATH})
2056
2057                 if(LLVM_LIBRARY AND LLVM_ROOT_DIR AND LLVM_LIBPATH)
2058                         if(LLVM_STATIC)
2059                                 # if static LLVM libraries were requested, use llvm-config to generate
2060                                 # the list of what libraries we need, and substitute that in the right
2061                                 # way for LLVM_LIBRARY.
2062                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
2063                                                 OUTPUT_VARIABLE LLVM_LIBRARY
2064                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
2065                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
2066                         else()
2067                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -lLLVM-3.4")
2068                         endif()
2069                 else()
2070                         message(FATAL_ERROR "LLVM not found.")
2071                 endif()
2072         endif()
2073
2074         if(WITH_CYCLES_OSL)
2075                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
2076         
2077                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
2078                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
2079                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
2080                 # WARNING! depends on correct order of OSL libs linking
2081                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -force_load ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
2082                 find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
2083                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
2084         
2085                 if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
2086                         set(OSL_FOUND TRUE)
2087                 else()
2088                         message(STATUS "OSL not found")
2089                         set(WITH_CYCLES_OSL OFF)
2090                 endif()
2091         endif()
2092         
2093         if(WITH_OPENMP)
2094                 execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE COMPILER_VENDOR)
2095                 string(SUBSTRING "${COMPILER_VENDOR}" 0 5 VENDOR_NAME) # truncate output
2096                 if(${VENDOR_NAME} MATCHES "Apple") # Apple does not support OpenMP reliable with gcc and not with clang
2097                         set(WITH_OPENMP OFF)
2098                 else() # vanilla gcc or clang_omp support OpenMP
2099                         message(STATUS "Using special OpenMP enabled compiler !") # letting find_package(OpenMP) module work for gcc
2100                         if(CMAKE_C_COMPILER_ID MATCHES "Clang") # clang-omp in darwin libs
2101                                 set(OPENMP_FOUND ON)
2102                                 set(OpenMP_C_FLAGS "-fopenmp" CACHE STRING "C compiler flags for OpenMP parallization" FORCE)
2103                                 set(OpenMP_CXX_FLAGS "-fopenmp" CACHE STRING "C++ compiler flags for OpenMP parallization" FORCE)
2104                                 include_directories(${LIBDIR}/openmp/include)
2105                                 link_directories(${LIBDIR}/openmp/lib)
2106                                 # This is a workaround for our helperbinaries ( datatoc, masgfmt, ... ),
2107                                 # They are linked also to omp lib, so we need it in builddir for runtime exexcution, TODO: remove all unneeded dependencies from these
2108                                 execute_process(COMMAND ditto -arch ${CMAKE_OSX_ARCHITECTURES} ${LIBDIR}/openmp/lib/libiomp5.dylib ${CMAKE_BINARY_DIR}/Resources/lib/libiomp5.dylib) # for intermediate binaries, in respect to lib ID
2109                         endif()
2110                 endif()
2111         endif()
2112
2113         set(EXETYPE MACOSX_BUNDLE)
2114
2115         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
2116         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
2117         if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386")
2118                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -msse -msse2 -msse3 -mssse3")
2119                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic  -msse -msse2 -msse3 -mssse3")
2120                 if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang")
2121                         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
2122                         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
2123                 endif()
2124         else()
2125                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
2126                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
2127         endif()
2128
2129         if(${XCODE_VERSION} VERSION_EQUAL 5 OR ${XCODE_VERSION} VERSION_GREATER 5)
2130                 # Xcode 5 is always using CLANG, which has too low template depth of 128 for libmv
2131                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
2132         endif()
2133         # Get rid of eventually clashes, we export some symbols explicite as local
2134         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Xlinker -unexported_symbols_list -Xlinker ${CMAKE_SOURCE_DIR}/source/creator/osx_locals.map")
2135 endif()
2136
2137 #-----------------------------------------------------------------------------
2138 # Common.
2139
2140 if(APPLE OR WIN32)
2141         if(NOT EXISTS "${LIBDIR}/")
2142                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
2143         endif()
2144 endif()
2145
2146 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
2147         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
2148 endif()
2149
2150 if(WITH_CYCLES)
2151         if(NOT WITH_OPENIMAGEIO)
2152                 message(FATAL_ERROR "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
2153         endif()
2154         if(NOT WITH_BOOST)
2155                 message(FATAL_ERROR "Cycles requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
2156         endif()
2157
2158         if(WITH_CYCLES_OSL)
2159                 if(NOT WITH_LLVM)
2160                         message(FATAL_ERROR "Cycles OSL requires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
2161                 endif()
2162         endif()
2163 endif()
2164
2165 if(WITH_INTERNATIONAL)
2166         if(NOT WITH_BOOST)
2167                 message(FATAL_ERROR "Internationalization requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_INTERNATIONAL")
2168         endif()
2169 endif()
2170
2171 # See TEST_SSE_SUPPORT() for how this is defined.
2172
2173 if(WITH_RAYOPTIMIZATION)
2174         if(SUPPORT_SSE_BUILD)
2175                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
2176                 add_definitions(-D__SSE__ -D__MMX__)
2177         endif()
2178         if(SUPPORT_SSE2_BUILD)
2179                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
2180                 add_definitions(-D__SSE2__)
2181                 if(NOT SUPPORT_SSE_BUILD) # dont double up
2182                         add_definitions(-D__MMX__)
2183                 endif()
2184         endif()
2185 endif()
2186
2187
2188 # set the endian define
2189 if(MSVC)
2190         # for some reason this fails on msvc
2191         add_definitions(-D__LITTLE_ENDIAN__)
2192         
2193 # OSX-Note: as we do crosscompiling with specific set architecture,
2194 # endianess-detection and autosetting is counterproductive
2195 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
2196
2197 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
2198         add_definitions(-D__LITTLE_ENDIAN__)
2199 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)            
2200         add_definitions(-D__BIG_ENDIAN__)
2201         
2202 else()
2203         include(TestBigEndian)
2204         test_big_endian(_SYSTEM_BIG_ENDIAN)
2205         if(_SYSTEM_BIG_ENDIAN)
2206                 add_definitions(-D__BIG_ENDIAN__)
2207         else()
2208                 add_definitions(-D__LITTLE_ENDIAN__)
2209         endif()
2210         unset(_SYSTEM_BIG_ENDIAN)
2211 endif()
2212
2213
2214 if(WITH_IMAGE_OPENJPEG)
2215         if(WITH_SYSTEM_OPENJPEG)
2216                 # dealt with above
2217         else()
2218                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
2219                 add_definitions(-DOPJ_STATIC)
2220         endif()
2221 endif()
2222
2223 if(WITH_IMAGE_REDCODE)
2224         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
2225         set(REDCODE_INC ${REDCODE})
2226 endif()
2227
2228 if(NOT WITH_SYSTEM_EIGEN3)
2229         set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3)
2230 endif()
2231
2232 #-----------------------------------------------------------------------------
2233 # Configure OpenGL.
2234
2235 find_package(OpenGL)
2236 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
2237
2238 if(WITH_GLU)
2239         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_glu_LIBRARY}")
2240         list(APPEND GL_DEFINITIONS -DWITH_GLU)
2241 endif()
2242
2243 if(WITH_SYSTEM_GLES)
2244         find_package_wrapper(OpenGLES)
2245 endif()
2246
2247 if(WITH_GL_PROFILE_COMPAT OR WITH_GL_PROFILE_CORE)
2248         list(APPEND BLENDER_GL_LIBRARIES "${OPENGL_gl_LIBRARY}")
2249
2250 elseif(WITH_GL_PROFILE_ES20)
2251         if(WITH_SYSTEM_GLES)
2252                 if(NOT OPENGLES_LIBRARY)
2253                         message(FATAL_ERROR "Unable to find OpenGL ES libraries.  Install them or disable WITH_SYSTEM_GLES.")
2254                 endif()
2255
2256                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_LIBRARY)
2257
2258         else()
2259                 set(OPENGLES_LIBRARY "" CACHE FILEPATH "OpenGL ES 2.0 library file")
2260                 mark_as_advanced(OPENGLES_LIBRARY)
2261
2262                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
2263
2264                 if(NOT OPENGLES_LIBRARY)
2265                         message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_LIBRARY to the file path of an OpenGL ES 2.0 library.")
2266                 endif()
2267
2268         endif()
2269
2270         if(WIN32)
2271                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
2272
2273                 set(OPENGLES_DLL "" CACHE FILEPATH "OpenGL ES 2.0 redistributable DLL file")
2274                 mark_as_advanced(OPENGLES_DLL)
2275
2276                 if(NOT OPENGLES_DLL)
2277                         message(FATAL_ERROR "To compile WITH_GL_PROFILE_ES20 you need to set OPENGLES_DLL to the file path of an OpenGL ES 2.0 runtime dynamic link library (DLL).")
2278                 endif()
2279
2280                 if(WITH_GL_ANGLE)
2281                         list(APPEND GL_DEFINITIONS -DWITH_ANGLE)
2282
2283                         set(D3DCOMPILER_DLL "" CACHE FILEPATH "Direct3D Compiler redistributable DLL file (needed by ANGLE)")
2284
2285                         get_filename_component(D3DCOMPILER_FILENAME "${D3DCOMPILER_DLL}" NAME)
2286                         list(APPEND GL_DEFINITIONS "-DD3DCOMPILER=\"\\\"${D3DCOMPILER_FILENAME}\\\"\"")
2287
2288                         mark_as_advanced(D3DCOMPILER_DLL)
2289
2290                         if(D3DCOMPILER_DLL STREQUAL "")
2291                                 message(FATAL_ERROR "To compile WITH_GL_ANGLE you need to set D3DCOMPILER_DLL to the file path of a copy of the DirectX redistributable DLL file: D3DCompiler_46.dll")
2292                         endif()
2293
2294                 endif()
2295
2296         endif()
2297
2298 endif()
2299
2300 if(WITH_GL_EGL)
2301         list(APPEND GL_DEFINITIONS -DWITH_GL_EGL)
2302
2303         if(WITH_SYSTEM_GLES)
2304                 if(NOT OPENGLES_EGL_LIBRARY)
2305                         message(FATAL_ERROR "Unable to find OpenGL ES libraries.  Install them or disable WITH_SYSTEM_GLES.")
2306                 endif()
2307
2308                 list(APPEND BLENDER_GL_LIBRARIES OPENGLES_EGL_LIBRARY)
2309
2310         else()
2311                 set(OPENGLES_EGL_LIBRARY "" CACHE FILEPATH "EGL library file")
2312                 mark_as_advanced(OPENGLES_EGL_LIBRARY)
2313
2314                 list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}" "${OPENGLES_EGL_LIBRARY}")
2315
2316                 if(NOT OPENGLES_EGL_LIBRARY)
2317                         message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY to the file path of an EGL library.")
2318                 endif()
2319
2320         endif()
2321
2322         if(WIN32)
2323                 # Setup paths to files needed to install and redistribute Windows Blender with OpenGL ES
2324
2325                 set(OPENGLES_EGL_DLL "" CACHE FILEPATH "EGL redistributable DLL file")
2326                 mark_as_advanced(OPENGLES_EGL_DLL)
2327
2328                 if(NOT OPENGLES_EGL_DLL)
2329                         message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_EGL_DLL to the file path of an EGL runtime dynamic link library (DLL).")
2330                 endif()
2331
2332         endif()
2333
2334 endif()
2335
2336 if(WITH_GL_PROFILE_COMPAT)
2337         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_COMPAT)
2338 endif()
2339
2340 if(WITH_GL_PROFILE_CORE)
2341         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_CORE)
2342 endif()
2343
2344 if(WITH_GL_PROFILE_ES20)
2345         list(APPEND GL_DEFINITIONS -DWITH_GL_PROFILE_ES20)
2346 endif()
2347
2348 if(WITH_GL_EGL)
2349         list(APPEND GL_DEFINITIONS -DWITH_EGL)
2350 endif()
2351
2352 #-----------------------------------------------------------------------------
2353 # Configure OpenMP.
2354 if(WITH_OPENMP)
2355         find_package(OpenMP)
2356         if(OPENMP_FOUND)
2357                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
2358                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
2359         else()
2360                 set(WITH_OPENMP OFF)
2361         endif()
2362
2363         mark_as_advanced(
2364                 OpenMP_C_FLAGS
2365                 OpenMP_CXX_FLAGS
2366         )
2367 endif()
2368
2369 #-----------------------------------------------------------------------------
2370 # Configure GLEW
2371
2372 if(WITH_GLEW_MX)
2373         list(APPEND GL_DEFINITIONS -DWITH_GLEW_MX)
2374 endif()
2375
2376 if(WITH_SYSTEM_GLEW)
2377         find_package(GLEW)
2378
2379         # Note: There is an assumption here that the system GLEW is not a static library.
2380
2381         if(NOT GLEW_FOUND)
2382                 message(FATAL_ERROR "GLEW is required to build Blender. Install it or disable WITH_SYSTEM_GLEW.")
2383         endif()
2384
2385         if(WITH_GLEW_MX)
2386                 set(BLENDER_GLEW_LIBRARIES ${GLEW_MX_LIBRARY})
2387         else()
2388                 set(BLENDER_GLEW_LIBRARIES ${GLEW_LIBRARY})
2389         endif()
2390 else()
2391         if(WITH_GLEW_ES)
2392                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew-es/include")
2393
2394                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC -DWITH_GLEW_ES)
2395
2396                 # These definitions remove APIs from glew.h, making GLEW smaller, and catching unguarded API usage
2397                 if(NOT WITH_GL_PROFILE_ES20)
2398                         # No ES functions are needed
2399                         list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
2400                 elseif(NOT (WITH_GL_PROFILE_CORE OR WITH_GL_PROFILE_COMPAT))
2401                         # ES is enabled, but the other functions are all disabled
2402                         list(APPEND GL_DEFINITIONS -DGLEW_ES_ONLY)
2403                 endif()
2404
2405                 if(WITH_GL_PROFILE_ES20)
2406                         if(WITH_GL_EGL)
2407                                 list(APPEND GL_DEFINITIONS -DGLEW_USE_LIB_ES20)
2408                         endif()
2409
2410                         # ToDo: This is an experiment to eliminate ES 1 symbols,
2411                         # GLEW doesn't really properly provide this level of control
2412                         # (for example, without modification it eliminates too many symbols)
2413                         # so there are lots of modifications to GLEW to make this work,
2414                         # and no attempt to make it work beyond Blender at this point.
2415                         list(APPEND GL_DEFINITIONS -DGL_ES_VERSION_1_0=0 -DGL_ES_VERSION_CL_1_1=0 -DGL_ES_VERSION_CM_1_1=0)
2416                 endif()
2417
2418                 if(WITH_GL_EGL)
2419                         list(APPEND GL_DEFINITIONS -DGLEW_INC_EGL)
2420                 endif()
2421
2422                 set(BLENDER_GLEW_LIBRARIES extern_glew_es bf_intern_glew_mx)
2423
2424         else()
2425                 set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
2426
2427                 list(APPEND GL_DEFINITIONS -DGLEW_STATIC)
2428
2429                 # This won't affect the non-experimental glew library, 
2430                 # but is used for conditional compilation elsewhere.
2431                 list(APPEND GL_DEFINITIONS -DGLEW_NO_ES)
2432
2433                 set(BLENDER_GLEW_LIBRARIES extern_glew)
2434
2435         endif()
2436
2437 endif()
2438
2439 if(NOT WITH_GLU)
2440         list(APPEND GL_DEFINITIONS -DGLEW_NO_GLU)
2441 endif()
2442
2443 #-----------------------------------------------------------------------------
2444 # Configure Bullet
2445
2446 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
2447         find_package(Bullet)
2448         if(NOT BULLET_FOUND)
2449                 set(WITH_BULLET OFF)
2450         endif()
2451 else()
2452         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
2453         # set(BULLET_LIBRARIES "")
2454 endif()
2455
2456 #-----------------------------------------------------------------------------
2457 # Configure Python.
2458
2459 if(WITH_PYTHON_MODULE)
2460         add_definitions(-DPy_ENABLE_SHARED)
2461 endif()
2462
2463 #-----------------------------------------------------------------------------
2464 # Extra compile flags
2465
2466 if(CMAKE_COMPILER_IS_GNUCC)
2467
2468         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2469         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
2470         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2471         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2472         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2473         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
2474         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2475         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2476         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2477         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2478         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2479         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2480         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
2481         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
2482         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
2483         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2484         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
2485         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2486         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2487         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
2488         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_FORMAT_SIGN -Wformat-signedness)
2489
2490         # gcc 4.2 gives annoying warnings on every file with this
2491         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2492                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
2493         endif()
2494
2495         # versions before gcc4.6 give many BLI_math warnings
2496         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
2497                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
2498                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
2499         endif()
2500
2501         # disable because it gives warnings for printf() & friends.
2502         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
2503
2504         if(NOT APPLE)
2505                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2506         endif()
2507
2508         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2509         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2510         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2511         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
2512         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
2513         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
2514         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
2515         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
2516         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2517         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2518         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2519         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2520         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2521         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_POINTER_ARITH -Wpointer-arith)
2522         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_PARAMETER -Wunused-parameter)
2523         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_WRITE_STRINGS -Wwrite-strings)
2524         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
2525         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_FORMAT_SIGN -Wformat-signedness)
2526
2527         # gcc 4.2 gives annoying warnings on every file with this
2528         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
2529                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
2530         endif()
2531
2532         # causes too many warnings
2533         if(NOT APPLE)
2534                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
2535                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
2536         endif()
2537
2538         # flags to undo strict flags
2539         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
2540         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
2541
2542         if(NOT APPLE)
2543                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
2544         endif()
2545
2546 elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
2547
2548         if(APPLE AND WITH_OPENMP) # we need the Intel omp lib linked here to not fail all tests due presence of -fopenmp !
2549                 set(CMAKE_REQUIRED_FLAGS "-L${LIBDIR}/openmp/lib -liomp5") # these are only used for the checks
2550         endif()
2551
2552         # strange, clang complains these are not supported, but then yses them.
2553         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2554         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2555         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2556         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2557         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2558         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2559         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2560         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2561         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2562         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2563
2564         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2565         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2566         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
2567         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
2568         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.
2569         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
2570         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
2571
2572         # gives too many unfixable warnings
2573         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
2574         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
2575
2576         # flags to undo strict flags
2577         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
2578         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
2579
2580         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
2581         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INCOMPAT_PTR_DISCARD_QUAL -Wno-incompatible-pointer-types-discards-qualifiers)
2582         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
2583         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
2584         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
2585         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
2586         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
2587         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
2588
2589         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
2590         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
2591         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
2592         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
2593         ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
2594
2595 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
2596
2597         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2598         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2599         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2600
2601         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2602         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2603         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2604
2605         # disable numbered, false positives
2606         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
2607         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
2608 elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
2609         # most msvc warnings are C & C++
2610         set(_WARNINGS
2611                 # warning level:
2612                 "/W3"
2613                 "/w34062"  # switch statement contains 'default' but no 'case' labels
2614                 # disable:
2615                 "/wd4018"  # signed/unsigned mismatch
2616                 "/wd4065"  # switch statement contains 'default' but no 'case' labels
2617                 "/wd4127"  # conditional expression is constant
2618                 "/wd4181"  # qualifier applied to reference type; ignored
2619                 "/wd4200"  # zero-sized array in struct/union
2620                 "/wd4244"  # conversion from 'type1' to 'type2', possible loss of data
2621                 "/wd4267"  # conversion from 'size_t' to 'type', possible loss of data
2622                 "/wd4305"  # truncation from 'type1' to 'type2'
2623                 "/wd4800"  # forcing value to bool 'true' or 'false'
2624                 # errors:
2625                 "/we4013"  # 'function' undefined; assuming extern returning int
2626                 "/we4431"  # missing type specifier - int assumed
2627         )
2628
2629         string(REPLACE ";" " " _WARNINGS "${_WARNINGS}")
2630         set(C_WARNINGS "${_WARNINGS}")
2631         set(CXX_WARNINGS "${_WARNINGS}")
2632         unset(_WARNINGS)
2633 endif()
2634
2635 # ensure python header is found since detection can fail, this could happen
2636 # with _any_ library but since we used a fixed python version this tends to
2637 # be most problematic.
2638 if(WITH_PYTHON)
2639         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
2640                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
2641                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
2642                                                         "to a valid python include path. Containing "
2643                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
2644         endif()
2645
2646         if(WIN32)
2647                 # pass, we have this in an archive to extract
2648         elseif(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
2649                 find_python_package(numpy)
2650         endif()
2651
2652         if(WIN32 OR APPLE)
2653                 # pass, we have this in lib/python/site-packages
2654         elseif(WITH_PYTHON_INSTALL_REQUESTS)
2655                 find_python_package(requests)
2656         endif()
2657 endif()
2658
2659 if(WITH_CPP11)
2660         if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
2661                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
2662         elseif(MSVC12)
2663                 # Nothing special is needed, C++11 features are available by default.
2664         else()
2665                 message(FATAL_ERROR "Compiler ${CMAKE_C_COMPILER_ID} is not supported for C++11 build yet")
2666         endif()
2667 endif()
2668
2669 # Include warnings first, so its possible to disable them with user defined flags
2670 # eg: -Wno-uninitialized
2671 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
2672 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
2673
2674 # defined above, platform spesific but shared names
2675 mark_as_advanced(
2676         CYCLES_OSL
2677         OSL_LIB_EXEC
2678         OSL_COMPILER
2679         OSL_LIB_COMP
2680         OSL_LIB_QUERY
2681         OSL_INCLUDE_DIR
2682 )
2683
2684 mark_as_advanced(
2685         LLVM_CONFIG
2686         LLVM_ROOT_DIR
2687         LLVM_LIBRARY
2688         LLVM_VERSION
2689 )
2690
2691 #-------------------------------------------------------------------------------
2692 # Global Defines
2693
2694 # better not set includes here but this debugging option is off by default.
2695 if(WITH_CXX_GUARDEDALLOC)
2696         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
2697         add_definitions(-DWITH_CXX_GUARDEDALLOC)
2698 endif()
2699
2700 if(WITH_ASSERT_ABORT)
2701         add_definitions(-DWITH_ASSERT_ABORT)
2702 endif()
2703
2704 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
2705 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
2706
2707 #-----------------------------------------------------------------------------
2708 # Libraries
2709
2710 if(WITH_GTESTS)
2711         include(GTestTesting)
2712 endif()
2713
2714 if(WITH_BLENDER OR WITH_PLAYER)
2715         add_subdirectory(intern)
2716         add_subdirectory(extern)
2717
2718         # source after intern and extern to gather all
2719         # internal and external library information first, for test linking
2720         add_subdirectory(source)
2721 elseif(WITH_CYCLES_STANDALONE)
2722         add_subdirectory(intern/cycles)
2723         add_subdirectory(extern/clew)
2724         add_subdirectory(extern/cuew)
2725         if(NOT WITH_SYSTEM_GLEW)
2726                 add_subdirectory(extern/glew)
2727         endif()
2728 endif()
2729
2730 #-----------------------------------------------------------------------------
2731 # Blender Application
2732 if(WITH_BLENDER)
2733         add_subdirectory(source/creator)
2734 endif()
2735
2736
2737 #-----------------------------------------------------------------------------
2738 # Blender Player
2739 if(WITH_PLAYER)
2740         add_subdirectory(source/blenderplayer)
2741 endif()
2742
2743
2744 #-----------------------------------------------------------------------------
2745 # Testing
2746 add_subdirectory(tests)
2747
2748
2749 #-----------------------------------------------------------------------------
2750 # CPack for generating packages
2751 include(build_files/cmake/packaging.cmake)
2752
2753
2754 #-----------------------------------------------------------------------------
2755 # Print Final Configuration
2756
2757 if(FIRST_RUN)
2758
2759         set(_config_msg "\nBlender Configuration\n=====================")
2760
2761         function(info_cfg_option
2762                 _setting
2763                 )
2764
2765                 set(_msg "  - ${_setting}")
2766                 string(LENGTH "${_msg}" _len)
2767                 while("32" GREATER "${_len}")
2768                         set(_msg "${_msg} ")
2769                          math(EXPR _len "${_len} + 1")
2770                 endwhile()
2771
2772                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
2773         endfunction()
2774
2775         function(info_cfg_text
2776                 _text
2777                 )
2778
2779                 set(_config_msg "${_config_msg}\n\n  ${_text}" PARENT_SCOPE)
2780         endfunction()
2781
2782         message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
2783         message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
2784
2785         info_cfg_text("Build Options:")
2786         info_cfg_option(WITH_GAMEENGINE)
2787         info_cfg_option(WITH_PLAYER)
2788         info_cfg_option(WITH_BULLET)
2789         info_cfg_option(WITH_IK_SOLVER)
2790         info_cfg_option(WITH_IK_ITASC)
2791         info_cfg_option(WITH_OPENCOLLADA)
2792         info_cfg_option(WITH_FFTW3)
2793         info_cfg_option(WITH_INTERNATIONAL)
2794         info_cfg_option(WITH_INPUT_NDOF)
2795         info_cfg_option(WITH_CYCLES)
2796         info_cfg_option(WITH_FREESTYLE)
2797         info_cfg_option(WITH_OPENCOLORIO)
2798
2799         info_cfg_text("Compiler Options:")
2800         info_cfg_option(WITH_BUILDINFO)
2801         info_cfg_option(WITH_OPENMP)
2802         info_cfg_option(WITH_RAYOPTIMIZATION)
2803
2804         info_cfg_text("System Options:")
2805         info_cfg_option(WITH_INSTALL_PORTABLE)
2806         info_cfg_option(WITH_X11_XF86VMODE)
2807         info_cfg_option(WITH_X11_XINPUT)
2808         info_cfg_option(WITH_MEM_JEMALLOC)
2809         info_cfg_option(WITH_MEM_VALGRIND)
2810         info_cfg_option(WITH_SYSTEM_GLEW)
2811         info_cfg_option(WITH_SYSTEM_OPENJPEG)
2812
2813         info_cfg_text("Image Formats:")
2814         info_cfg_option(WITH_OPENIMAGEIO)
2815         info_cfg_option(WITH_IMAGE_CINEON)
2816         info_cfg_option(WITH_IMAGE_DDS)
2817         info_cfg_option(WITH_IMAGE_HDR)
2818         info_cfg_option(WITH_IMAGE_OPENEXR)
2819         info_cfg_option(WITH_IMAGE_OPENJPEG)
2820         info_cfg_option(WITH_IMAGE_REDCODE)
2821         info_cfg_option(WITH_IMAGE_TIFF)
2822
2823         info_cfg_text("Audio:")
2824         info_cfg_option(WITH_OPENAL)
2825         info_cfg_option(WITH_SDL)
2826         info_cfg_option(WITH_SDL_DYNLOAD)
2827         info_cfg_option(WITH_JACK)
2828         info_cfg_option(WITH_JACK_DYNLOAD)
2829         info_cfg_option(WITH_CODEC_AVI)
2830         info_cfg_option(WITH_CODEC_FFMPEG)
2831         info_cfg_option(WITH_CODEC_SNDFILE)
2832
2833         info_cfg_text("Compression:")
2834         info_cfg_option(WITH_LZMA)
2835         info_cfg_option(WITH_LZO)
2836
2837         info_cfg_text("Python:")
2838         info_cfg_option(WITH_PYTHON_INSTALL)
2839         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
2840         info_cfg_option(WITH_PYTHON_MODULE)
2841         info_cfg_option(WITH_PYTHON_SAFETY)
2842         if(APPLE)
2843                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
2844         endif()
2845
2846         info_cfg_text("Modifiers:")
2847         info_cfg_option(WITH_MOD_BOOLEAN)
2848         info_cfg_option(WITH_MOD_REMESH)
2849         info_cfg_option(WITH_MOD_FLUID)
2850         info_cfg_option(WITH_MOD_OCEANSIM)
2851
2852         info_cfg_text("OpenGL:")
2853         info_cfg_option(WITH_GLEW_ES)
2854         info_cfg_option(WITH_GLU)
2855         info_cfg_option(WITH_GL_EGL)
2856         info_cfg_option(WITH_GL_PROFILE_COMPAT)
2857         info_cfg_option(WITH_GL_PROFILE_CORE)
2858         info_cfg_option(WITH_GL_PROFILE_ES20)
2859         if(WIN32)
2860                 info_cfg_option(WITH_GL_ANGLE)
2861         endif()
2862
2863         info_cfg_text("Other:")
2864         info_cfg_option(WITH_OPENNL)
2865
2866         # debug
2867         message(STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}")
2868
2869         info_cfg_text("")
2870
2871         message("${_config_msg}")
2872 endif()
2873
2874 if(0)
2875         print_all_vars()
2876 endif()
2877