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