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