Cycles / OSL:
[blender.git] / CMakeLists.txt
1 # ***** BEGIN GPL LICENSE BLOCK *****
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # The Original Code is Copyright (C) 2006, Blender Foundation
18 # All rights reserved.
19 #
20 # The Original Code is: all of this file.
21 #
22 # Contributor(s): Jacques Beaurain.
23 #
24 # ***** END GPL LICENSE BLOCK *****
25
26 #-----------------------------------------------------------------------------
27 # We don't allow in-source builds. This causes no end of troubles because
28 # all out-of-source builds will use the CMakeCache.txt file there and even
29 # build the libs and objects in it.
30
31 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
32         if(NOT DEFINED WITH_IN_SOURCE_BUILD)
33                 message(FATAL_ERROR
34                         "CMake generation for blender is not allowed within the source directory!"
35                         "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
36                         "\n "
37                         "\n rm CMakeCache.txt"
38                         "\n cd .."
39                         "\n mkdir cmake-make"
40                         "\n cd cmake-make"
41                         "\n cmake ../blender"
42                         "\n "
43                         "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
44                 )
45         endif()
46 endif()
47
48 cmake_minimum_required(VERSION 2.8)
49
50 if(NOT EXECUTABLE_OUTPUT_PATH)
51         set(FIRST_RUN "TRUE")
52 endif()
53
54 # this starts out unset
55 list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
56
57 # avoid having empty buildtype
58 set(CMAKE_BUILD_TYPE_INIT "Release")
59
60 # quiet output for Makefiles, 'make -s' helps too
61 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
62
63 # global compile definitions since add_definitions() adds for all.
64 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
65 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
66 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
67 set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
68
69
70 #-----------------------------------------------------------------------------
71 # Set policy
72
73 # see "cmake --help-policy CMP0003"
74 # So library linking is more sane
75 cmake_policy(SET CMP0003 NEW)
76
77 # So BUILDINFO and BLENDERPATH strings are automatically quoted
78 cmake_policy(SET CMP0005 NEW)
79
80 # So syntax problems are errors
81 cmake_policy(SET CMP0010 NEW)
82
83 # Input directories must have CMakeLists.txt
84 cmake_policy(SET CMP0014 NEW)
85
86 #-----------------------------------------------------------------------------
87 # Load some macros.
88 include(build_files/cmake/macros.cmake)
89
90
91 #-----------------------------------------------------------------------------
92 # Initialize project.
93
94 blender_project_hack_pre()
95
96 project(Blender)
97
98 blender_project_hack_post()
99
100 enable_testing()
101
102 #-----------------------------------------------------------------------------
103 # Redirect output files
104
105 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE)
106 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE)
107
108 #-----------------------------------------------------------------------------
109 # Set default config options
110
111 get_blender_version()
112
113
114 # Blender internal features
115 option(WITH_BLENDER "Build blender (disable to build only the blender player)" ON)
116 mark_as_advanced(WITH_BLENDER)
117
118 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
119
120 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
121 option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default (recommend to leave off)" OFF)
122 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
123 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distributions see this as a security issue, rather than have them patch it, make a build option.
124
125 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)
126 option(WITH_PYTHON_MODULE "Enable building as a python module which runs without a user interface, like running regular blender in background mode (experimental, only enable for development)" OFF)
127 if(APPLE)
128         option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
129 endif()
130
131 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
132 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
133 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
134 option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effects)" ON)
135 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
136 option(WITH_SYSTEM_BULLET "Use the systems bullet library (currently unsupported due to missing features in upstream!)" )
137 mark_as_advanced(WITH_SYSTEM_BULLET)
138 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
139 option(WITH_PLAYER        "Build Player" OFF)
140 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ON)
141 option(WITH_COMPOSITOR    "Enable the tile based nodal compositor" ON)
142
143 # GHOST Windowing Library Options
144 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
145 mark_as_advanced(WITH_GHOST_DEBUG)
146
147 option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
148 mark_as_advanced(WITH_GHOST_SDL)
149
150 # Misc...
151 option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
152 mark_as_advanced(WITH_HEADLESS)
153
154 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
155 mark_as_advanced(WITH_AUDASPACE)
156
157 option(WITH_BOOL_COMPAT "Continue defining \"TRUE\" and \"FALSE\" until these can be replaced with \"true\" and \"false\" from stdbool.h" ON)
158 mark_as_advanced(WITH_BOOL_COMPAT)
159
160
161 # (unix defaults to OpenMP On)
162 if((UNIX AND NOT APPLE) OR (MINGW))
163         set(PLATFORM_DEFAULT ON)
164 else()
165         set(PLATFORM_DEFAULT OFF)
166 endif()
167 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ${PLATFORM_DEFAULT})
168 unset(PLATFORM_DEFAULT)
169
170
171 if(UNIX AND NOT APPLE)
172         option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support and unicode input)"   ON)
173         option(WITH_X11_XF86VMODE "Enable X11 video mode switching"     ON)
174         option(WITH_SYSTEM_GLEW "Use GLEW OpenGL wrapper library provided by the operating system" ON)
175
176         # freebsd doesn't seems to support XDND
177         if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
178                 option(WITH_GHOST_XDND   "Enable drag'n'drop support on Linux using XDND protocol" ON)
179         endif()
180 else()
181         # not an option for other OS's
182         set(WITH_SYSTEM_GLEW OFF)
183 endif()
184
185
186 # (unix defaults to System OpenJPEG On)
187 if(UNIX AND NOT APPLE)
188         set(PLATFORM_DEFAULT ON)
189 else()
190         set(PLATFORM_DEFAULT OFF)
191 endif()
192 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" ${PLATFORM_DEFAULT})
193 unset(PLATFORM_DEFAULT)
194
195
196 # Modifiers
197 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
198 option(WITH_MOD_SMOKE           "Enable Smoke Modifier (Smoke Simulation)" ON)
199 option(WITH_MOD_BOOLEAN         "Enable Boolean Modifier" ON)
200 option(WITH_MOD_REMESH          "Enable Remesh Modifier" ON)
201 # option(WITH_MOD_CLOTH_ELTOPO    "Enable Experimental cloth solver" OFF)  # this is now only available in a branch
202 # mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
203 option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
204
205 # Image format support
206 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
207 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
208 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
209 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
210 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
211 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
212 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
213 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
214
215 # Audio/Video format support
216 option(WITH_CODEC_AVI           "Enable Blenders own AVI file support (raw/jpeg)" ON)
217 option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
218
219 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
220 if(APPLE OR (WIN32 AND NOT UNIX))
221         option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" OFF)
222 endif()
223
224 # 3D format support
225 # disable opencollada on non-apple unix because opencollada has no package for debian
226 option(WITH_OPENCOLLADA         "Enable OpenCollada Support (http://www.opencollada.org)"       OFF)
227
228 # Sound output
229 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
230 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
231 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
232 if(UNIX AND NOT APPLE)
233         option(WITH_JACK_DYNLOAD  "Enable runtime dynamic Jack libraries loading" OFF)
234 endif()
235
236 # Compression
237 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
238 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
239
240 # Camera/motion tracking
241 option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
242
243 # Freestyle
244 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
245
246 # Misc
247 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON)
248 option(WITH_RAYOPTIMIZATION     "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
249 if(UNIX AND NOT APPLE)
250         option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
251         option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
252         if(WITH_STATIC_LIBS)
253                 option(WITH_BOOST_ICU "Boost uses ICU library (required for linking with static Boost built with libicu)." OFF)
254                 mark_as_advanced(WITH_BOOST_ICU)
255         endif()
256 endif()
257 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
258 option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
259 set(PYTHON_NUMPY_PATH            "" CACHE PATH "Python to python site-packages or dist-packages containing 'numpy' module")
260 mark_as_advanced(PYTHON_NUMPY_PATH)
261
262 # Cycles
263 option(WITH_CYCLES                                      "Enable cycles Render Engine" ON)
264 option(WITH_CYCLES_TEST                         "Build cycles test application" OFF)
265 option(WITH_CYCLES_OSL                          "Build Cycles with OSL support" OFF)
266 option(WITH_CYCLES_CUDA_BINARIES        "Build cycles CUDA binaries" OFF)
267 set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 CACHE STRING "CUDA architectures to build binaries for")
268 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
269 unset(PLATFORM_DEFAULT)
270
271 # LLVM
272 option(WITH_LLVM                                        "Use LLVM" OFF)
273 option(LLVM_STATIC                                      "Link with LLVM static libraries" ON)
274 mark_as_advanced(LLVM_STATIC)
275
276 # disable for now, but plan to support on all platforms eventually
277 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
278 mark_as_advanced(WITH_MEM_JEMALLOC)
279
280 # Debug
281 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
282 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
283
284 option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
285 mark_as_advanced(WITH_ASSERT_ABORT)
286
287 option(WITH_BOOST                                       "Enable features depending no boost" ON)
288
289 if(CMAKE_COMPILER_IS_GNUCC)
290         option(WITH_GCC_MUDFLAP                 "Enable mudflap" OFF)
291         mark_as_advanced(WITH_GCC_MUDFLAP)
292 endif()
293
294 if(APPLE)
295         cmake_minimum_required(VERSION 2.8.8)
296         cmake_policy(VERSION 2.8.8)
297
298         if(NOT CMAKE_OSX_ARCHITECTURES)
299                 set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
300                 "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
301                 FORCE)
302         endif()
303         
304         execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
305         if(${MAC_SYS} MATCHES 12)
306                 set(OSX_SYSTEM 10.8)
307         elseif(${MAC_SYS} MATCHES 11)
308                 set(OSX_SYSTEM 10.7)
309         elseif(${MAC_SYS} MATCHES 10)
310                 set(OSX_SYSTEM 10.6)
311         elseif(${MAC_SYS} MATCHES 9)
312                 set(OSX_SYSTEM 10.5)
313         else()
314                 set(OSX_SYSTEM unsupported)
315         endif()
316         message(STATUS "Detected system-version: " ${OSX_SYSTEM})
317
318         if(${CMAKE_GENERATOR} MATCHES "Xcode")
319         
320                 ##### cmake incompatibility with xcode  4.3 and higher #####
321                 if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
322                         message(FATAL_ERROR "Xcode 4.3 and higher must be used with cmake 2.8-8 or higher")
323                 endif()
324                 ### end cmake incompatibility with xcode 4.3 and higher ###
325                 
326                 if(${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4 AND ${XCODE_VERSION} VERSION_LESS 4.3)
327                         # Xcode 4 defaults to the Apple LLVM Compiler.
328                         # Override the default compiler selection because Blender only compiles with gcc up to xcode 4.2
329                         set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
330                         message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
331                 endif()
332         else() # unix makefile generator does not fill XCODE_VERSION var, so we get it with a command
333                 execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILD_NR)
334                 string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
335                 unset(XCODE_VERS_BUILD_NR)
336         endif()
337         
338         message(STATUS "Detected Xcode-version: " ${XCODE_VERSION})
339
340         if(${XCODE_VERSION} VERSION_LESS 4.3)
341                 set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)  # use guaranteed existing sdk
342         else()
343                 # note: i don't use xcode-select path on purpose, cause also /Applications/Xcode.app would be allowed
344                 # absolute pathes are more foolproof here !
345                 set(OSX_SYSROOT_PREFIX /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform)
346                 set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
347                 set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
348         endif()
349         
350         if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
351                         set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5" CACHE STRING "" FORCE) # 10.5 is our min. target, if you use higher sdk, weak linking happens
352         endif()
353         
354         if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
355                 # force CMAKE_OSX_DEPLOYMENT_TARGET for makefiles, will not work else ( cmake bug ? )
356                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
357                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
358                 add_definitions ("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
359         endif()
360
361         option(WITH_COCOA         "Use Cocoa framework instead of deprecated Carbon" ON)
362         option(USE_QTKIT          "Use QtKit instead of Carbon quicktime (needed for having partial quicktime for 64bit)" OFF)
363         option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
364         if(CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
365                 set(USE_QTKIT ON CACHE BOOL "ON" FORCE) # no Quicktime in 64bit
366         endif()
367 endif()
368
369
370 #-----------------------------------------------------------------------------
371 # Check for conflicting/unsupported configurations
372
373 if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_TEST)
374         message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER must be enabled, nothing to do!")
375 endif()
376
377 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
378         message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
379 endif()
380
381 if(NOT WITH_AUDASPACE)
382         if(WITH_OPENAL)
383                 message(FATAL_ERROR "WITH_OPENAL requires WITH_AUDASPACE")
384         endif()
385         if(WITH_JACK)
386                 message(FATAL_ERROR "WITH_JACK requires WITH_AUDASPACE")
387         endif()
388         if(WITH_GAMEENGINE)
389                 message(FATAL_ERROR "WITH_GAMEENGINE requires WITH_AUDASPACE")
390         endif()
391 endif()
392
393 if(NOT WITH_SDL AND WITH_GHOST_SDL)
394         message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
395 endif()
396
397 if(WITH_IMAGE_REDCODE AND ((NOT WITH_IMAGE_OPENJPEG) OR (NOT WITH_CODEC_FFMPEG)))
398         message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG and WITH_CODEC_FFMPEG")
399 endif()
400
401 # python module, needs some different options
402 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
403         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
404 endif()
405
406 if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
407         message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
408 endif()
409
410
411 # may as well build python module without a UI
412 if(WITH_PYTHON_MODULE)
413         set(WITH_HEADLESS ON)
414 endif()
415
416 # enable boost for cycles, booleans, audaspace or i18n
417 # otherwise if the user disabled
418 if(NOT WITH_BOOST)
419         # Explicitly disabled. so disable all deps.
420         macro(set_and_warn
421                 _setting _val)
422                 if(${${_setting}})
423                         message(STATUS "'WITH_BOOST' is disabled: forceing 'set(${_setting} ${_val})'")
424                 endif()
425                 set(${_setting} ${_val})
426         endmacro()
427
428         set_and_warn(WITH_CYCLES         OFF)
429         set_and_warn(WITH_MOD_BOOLEAN    OFF)
430         set_and_warn(WITH_AUDASPACE      OFF)
431         set_and_warn(WITH_INTERNATIONAL  OFF)
432
433         set_and_warn(WITH_OPENAL         OFF)  # depends on AUDASPACE
434         set_and_warn(WITH_GAMEENGINE     OFF)  # depends on AUDASPACE
435 elseif(WITH_CYCLES OR WITH_MOD_BOOLEAN OR WITH_AUDASPACE OR WITH_INTERNATIONAL)
436         # Keep enabled
437 else()
438         # Enabled but we don't need it
439         set(WITH_BOOST OFF)
440 endif()
441
442 # auto enable openimageio for cycles
443 if(WITH_CYCLES)
444         set(WITH_OPENIMAGEIO ON)
445 endif()
446
447 # auto enable openimageio linking dependencies
448 if(WITH_OPENIMAGEIO)
449         set(WITH_IMAGE_OPENEXR ON)
450         set(WITH_IMAGE_TIFF ON)
451 endif()
452
453 # auto enable llvm for cycles_osl
454 if(WITH_CYCLES_OSL)
455         set(WITH_LLVM ON CACHE BOOL "ON" FORCE)
456 endif()
457
458 # don't store paths to libs for portable distribution
459 if(WITH_INSTALL_PORTABLE)
460         set(CMAKE_SKIP_BUILD_RPATH TRUE)
461 endif()
462
463 if(WITH_GHOST_SDL OR WITH_HEADLESS)
464         set(WITH_GHOST_XDND OFF)
465         set(WITH_X11_XF86VMODE OFF)
466         set(WITH_X11_XINPUT OFF)
467 endif()
468
469 if(MINGW)
470         if(WITH_CODEC_QUICKTIME)
471                 message(FATAL_ERROR "MINGW requires WITH_CODEC_QUICKTIME to be OFF "
472                                     "because it is currently unsupported, remove this "
473                                     "line if youre a developer who wants to add support.")
474         endif()
475 endif()
476
477 TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
478
479 TEST_STDBOOL_SUPPORT()
480 if(HAVE_STDBOOL_H)
481         add_definitions(-DHAVE_STDBOOL_H)
482 endif()
483 if(WITH_BOOL_COMPAT)
484         add_definitions(-DWITH_BOOL_COMPAT)
485 endif()
486
487 #-----------------------------------------------------------------------------
488 # Check for valid directories
489 # ... svn extern paths can be missing because of svn-git.
490
491 if(WITH_INTERNATIONAL)
492         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale")
493                 message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
494                                                 "This is an 'svn external', which are known not to work with bridges to other version "
495                                                 "control systems, disabling 'WITH_INTERNATIONAL'.")
496                 set(WITH_INTERNATIONAL OFF)
497         endif()
498 endif()
499
500 if(WITH_PYTHON)
501         if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons")
502                 message(WARNING "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
503                                                 "This is an 'svn external', which are known not to work with bridges to other version "
504                                                 "control systems: * CONTINUING WITHOUT ADDONS *")
505         endif()
506 endif()
507
508 #-----------------------------------------------------------------------------
509 # Initialize un-cached vars, avoid unused warning
510
511 # linux only, not cached
512 set(WITH_BINRELOC OFF)
513
514 # MAXOSX only, set to avoid uninitialized
515 set(EXETYPE "")
516
517 # C/C++ flags
518 set(PLATFORM_CFLAGS)
519
520 # these are added to later on.
521 set(C_WARNINGS)
522 set(CXX_WARNINGS)
523
524 # for gcc -Wno-blah-blah
525 set(CC_REMOVE_STRICT_FLAGS)
526
527 # libraries to link the binary with passed to target_link_libraries()
528 # known as LLIBS to scons
529 set(PLATFORM_LINKLIBS "")
530
531 # Added to linker flags in setup_liblinks
532 # - CMAKE_EXE_LINKER_FLAGS
533 # - CMAKE_EXE_LINKER_FLAGS_DEBUG
534 set(PLATFORM_LINKFLAGS "")
535 set(PLATFORM_LINKFLAGS_DEBUG "")
536
537
538 # disabled for now, not supported
539 # option(WITH_WEBPLUGIN     "Enable Web Plugin (Unix only)" OFF)
540
541 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
542 # On Unix:
543 #   cmake ../blender \
544 #         -D PYTHON_VERSION=3.3 \
545 #         -D PYTHON_INCLUDE_DIR=/opt/py33/include/python3.3d \
546 #         -D PYTHON_LIBRARY=/opt/py33/lib/libpython3.3d.so
547 #
548 # On Macs:
549 #   cmake ../blender \
550 #         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3 \
551 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/config \
552 #         -G Xcode
553 #
554 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
555
556 #-----------------------------------------------------------------------------
557 #Platform specifics
558
559 if(UNIX AND NOT APPLE)
560         macro(find_package_wrapper)
561                 string(TOUPPER ${ARGV0} _NAME_UPPER)
562                 if(${WITH_STATIC_LIBS})
563                         set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
564                         set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
565                 endif()
566                 find_package(${ARGV})
567                 if(${WITH_STATIC_LIBS})
568                         set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
569                         unset(_cmake_find_library_suffixes_back)
570                 endif()
571         endmacro()
572
573         find_package_wrapper(JPEG REQUIRED)
574         find_package_wrapper(PNG REQUIRED)
575         find_package_wrapper(ZLIB REQUIRED)
576         find_package_wrapper(Freetype REQUIRED)
577
578         if(WITH_PYTHON)
579                 # No way to set py33. remove for now.
580                 # find_package(PythonLibs)
581
582                 # Use our own instead, since wothout py is such a rare case,
583                 # require this package
584                 # XXX Linking errors with debian static python :/
585 #               find_package_wrapper(PythonLibsUnix REQUIRED)
586                 find_package(PythonLibsUnix REQUIRED)
587         endif()
588
589         if(WITH_IMAGE_OPENEXR)
590                 find_package_wrapper(OpenEXR)  # our own module
591                 if(NOT OPENEXR_FOUND)
592                         set(WITH_IMAGE_OPENEXR OFF)
593                 endif()
594         endif()
595
596         if(WITH_IMAGE_OPENJPEG)
597                 find_package_wrapper(OpenJPEG)
598                 if(NOT OPENJPEG_FOUND)
599                         set(WITH_IMAGE_OPENJPEG OFF)
600                 endif()
601         endif()
602
603         if(WITH_IMAGE_TIFF)
604                 # XXX Linking errors with debian static tiff :/
605 #               find_package_wrapper(TIFF)
606                 find_package(TIFF)
607                 if(NOT TIFF_FOUND)
608                         set(WITH_IMAGE_TIFF OFF)
609                 endif()
610         endif()
611
612         # Audio IO
613         if(WITH_OPENAL)
614                 find_package_wrapper(OpenAL)
615                 if(NOT OPENAL_FOUND)
616                         set(WITH_OPENAL OFF)
617                 endif()
618         endif()
619
620         if(WITH_SDL)
621                 find_package_wrapper(SDL)
622                 mark_as_advanced(
623                         SDLMAIN_LIBRARY
624                         SDL_INCLUDE_DIR
625                         SDL_LIBRARY
626                         SDL_LIBRARY_TEMP
627                 )
628                 # unset(SDLMAIN_LIBRARY CACHE)
629                 if(NOT SDL_FOUND)
630                         set(WITH_SDL OFF)
631                 endif()
632         endif()
633
634         if(WITH_JACK)
635                 find_package_wrapper(Jack)
636                 if(NOT JACK_FOUND)
637                         set(WITH_JACK OFF)
638                 endif()
639         endif()
640
641         # Codecs
642         if(WITH_CODEC_SNDFILE)
643                 find_package_wrapper(SndFile)
644                 if(NOT SNDFILE_FOUND)
645                         set(WITH_CODEC_SNDFILE OFF)
646                 endif()
647         endif()
648
649         if(WITH_CODEC_FFMPEG)
650                 set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
651                 set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
652
653                 mark_as_advanced(FFMPEG)
654
655                 # lame, but until we have proper find module for ffmpeg
656                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
657                 if(EXISTS "${FFMPEG}/include/ffmpeg/")
658                         list(APPEND FFMPEG_INCLUDE_DIRS "${FFMPEG}/include/ffmpeg")
659                 endif()
660                 # end lameness
661
662                 mark_as_advanced(FFMPEG_LIBRARIES)
663                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
664                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
665         endif()
666
667         if(WITH_FFTW3)
668                 find_package_wrapper(Fftw3)
669                 if(NOT FFTW3_FOUND)
670                         set(WITH_FFTW3 OFF)
671                 endif()
672         endif()
673
674         if(WITH_OPENCOLLADA)
675                 find_package_wrapper(OpenCOLLADA)
676                 if(OPENCOLLADA_FOUND)
677                         find_package_wrapper(XML2)
678                         find_package_wrapper(PCRE)
679                 else()
680                         set(WITH_OPENCOLLADA OFF)
681                 endif()
682         endif()
683
684         if(WITH_MEM_JEMALLOC)
685                 find_package_wrapper(JeMalloc)
686                 if(NOT JEMALLOC_FOUND)
687                         set(WITH_MEM_JEMALLOC OFF)
688                 endif()
689         endif()
690
691         if(WITH_INPUT_NDOF)
692                 find_package_wrapper(Spacenav)
693                 if(NOT SPACENAV_FOUND)
694                         set(WITH_INPUT_NDOF OFF)
695                 endif()
696
697                 # use generic names within blenders buildsystem.
698                 if(SPACENAV_FOUND)
699                         set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
700                         set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
701                 endif()
702         endif()
703
704         if(WITH_BOOST)
705                 # uses in build instructions to override include and library variables
706                 if(NOT BOOST_CUSTOM)
707                         if(${WITH_STATIC_LIBS})
708                                 set(Boost_USE_STATIC_LIBS ON)
709                         endif()
710                         set(Boost_USE_MULTITHREADED ON)
711                         set(__boost_packages filesystem regex system thread date_time)
712                         if(WITH_INTERNATIONAL)
713                                 list(APPEND __boost_packages locale)
714                         endif()
715                         find_package(Boost 1.48 COMPONENTS ${__boost_packages})
716                         unset(__boost_packages)
717                         if(Boost_USE_STATIC_LIBS AND WITH_BOOST_ICU)
718                                 find_package(IcuLinux)
719                         endif()
720                         mark_as_advanced(Boost_DIR)  # why doesnt boost do this?
721                 endif()
722
723                 set(BOOST_INCLUDE_DIR ${Boost_INCLUDE_DIRS})
724                 set(BOOST_LIBRARIES ${Boost_LIBRARIES})
725                 set(BOOST_LIBPATH ${Boost_LIBRARY_DIRS})
726                 set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
727         endif()
728
729         if(WITH_OPENIMAGEIO)
730                 find_package_wrapper(OpenImageIO)
731
732                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
733                 set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
734                 set(OPENIMAGEIO_DEFINITIONS "")
735
736                 if(WITH_IMAGE_TIFF)
737                         list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}")
738                 endif()
739                 if(WITH_IMAGE_OPENEXR)
740                         list(APPEND OPENIMAGEIO_LIBRARIES "${OPENEXR_LIBRARIES}")
741                 endif()
742
743                 if(NOT OPENIMAGEIO_FOUND)
744                         set(WITH_OPENIMAGEIO OFF)
745                         message(STATUS "OpenImageIO not found, disabling WITH_CYCLES")
746                 endif()
747         endif()
748
749         if(WITH_OPENCOLORIO)
750                 find_package_wrapper(OpenColorIO)
751
752                 set(OPENCOLORIO_LIBRARIES ${OPENCOLORIO_LIBRARIES})
753                 set(OPENCOLORIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
754                 set(OPENCOLORIO_DEFINITIONS)
755
756                 if(NOT OPENCOLORIO_FOUND)
757                         set(WITH_OPENCOLORIO OFF)
758                         message(STATUS "OpenColorIO not found")
759                 endif()
760         endif()
761
762         # XXX Maybe most of this section should go into an llvm module?
763         if(WITH_LLVM)
764                 # Set llvm version if not specified
765                 if(NOT LLVM_VERSION)
766                         set(LLVM_VERSION "3.0")
767                 endif()
768
769                 if(LLVM_DIRECTORY)
770                         FIND_PROGRAM(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
771                         if(NOT LLVM_CONFIG)
772                                 FIND_PROGRAM(LLVM_CONFIG llvm-config HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
773                         endif()
774                 else()
775                         FIND_PROGRAM(LLVM_CONFIG llvm-config-${LLVM_VERSION})
776                         if(NOT LLVM_CONFIG)
777                                 FIND_PROGRAM(LLVM_CONFIG llvm-config)
778                         endif()
779                 endif()
780                 execute_process(COMMAND ${LLVM_CONFIG} --version
781                                 OUTPUT_VARIABLE LLVM_VERSION
782                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
783                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
784                                 OUTPUT_VARIABLE LLVM_DIRECTORY
785                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
786                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
787                                 OUTPUT_VARIABLE LLVM_LIB_DIR
788                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
789
790                 if(LLVM_STATIC)
791                         find_library(LLVM_LIBRARY
792                                      NAMES LLVMAnalysis # first of a whole bunch of libs to get
793                                      PATHS ${LLVM_LIB_DIR})
794                 else()
795                         find_library(LLVM_LIBRARY
796                                      NAMES LLVM-${LLVM_VERSION}
797                                      PATHS ${LLVM_LIB_DIR})
798                 endif()
799
800                 message(STATUS "LLVM version  = ${LLVM_VERSION}")
801                 message(STATUS "LLVM dir      = ${LLVM_DIRECTORY}")
802                 message(STATUS "LLVM lib dir  = ${LLVM_LIB_DIR}")
803                 set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
804                 set(LLVM_DIRECTORY ${LLVM_DIRECTORY} CACHE PATH "Path to the LLVM installation")
805
806                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIB_DIR)
807                         if(LLVM_STATIC)
808                                 # if static LLVM libraries were requested, use llvm-config to generate
809                                 # the list of what libraries we need, and substitute that in the right
810                                 # way for LLVM_LIBRARY.
811                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
812                                                 OUTPUT_VARIABLE LLVM_LIBRARY
813                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
814                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
815                         endif()
816                 else()
817                         message(FATAL_ERROR "LLVM not found.")
818                 endif()
819
820                 # Fix for conflict with Mesa llvmpipe
821                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--version-script=${CMAKE_SOURCE_DIR}/source/creator/blender.map")
822         endif()
823
824         if(WITH_CYCLES_OSL)
825                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
826         
827                 message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
828         
829                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
830                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
831                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
832                 # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
833                 # otherwise LLVM is missing the osl_allocate_closure_component function
834                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -Wl,--whole-archive ${OSL_LIB_EXEC} -Wl,--no-whole-archive ${OSL_LIB_QUERY})
835                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
836                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
837         
838                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
839                         set(OSL_FOUND TRUE)
840                         message(STATUS "OSL includes = ${OSL_INCLUDES}")
841                         message(STATUS "OSL library = ${OSL_LIBRARIES}")
842                         message(STATUS "OSL compiler = ${OSL_COMPILER}")
843                 else()
844                         message(STATUS "OSL not found")
845                 endif()
846         endif()
847
848         # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
849         set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
850
851         if((NOT WITH_HEADLESS) AND (NOT WITH_GHOST_SDL))
852                 find_package(X11 REQUIRED)
853                 find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
854                 mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
855
856                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_X11_LIB}")
857
858                 if(WITH_X11_XINPUT)
859                         if(X11_Xinput_LIB)
860                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xinput_LIB}")
861                         else()
862                                 set(WITH_X11_XINPUT OFF)
863                         endif()
864                 endif()
865
866                 if(WITH_X11_XF86VMODE)
867                         # XXX, why dont cmake make this available?
868                         FIND_LIBRARY(X11_Xxf86vmode_LIB Xxf86vm   ${X11_LIB_SEARCH_PATH})
869                         mark_as_advanced(X11_Xxf86vmode_LIB)
870                         if(X11_Xxf86vmode_LIB)
871                                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} ${X11_Xxf86vmode_LIB}")
872                         else()
873                                 set(WITH_X11_XF86VMODE OFF)
874                         endif()
875                 endif()
876         endif()
877
878         if(CMAKE_SYSTEM_NAME MATCHES "Linux")
879                 if(NOT WITH_PYTHON_MODULE)
880                         # BSD's dont use libdl.so
881                 set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -ldl")
882                         # binreloc is linux only
883                         set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
884                         set(WITH_BINRELOC ON)
885                 endif()
886         endif()
887
888         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -pthread")
889
890         # lfs on glibc, all compilers should use
891         add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
892
893         # GNU Compiler
894         if(CMAKE_COMPILER_IS_GNUCC)
895                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
896         # CLang is the same as GCC for now.
897         elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
898                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
899         # Solaris CC
900         elseif(CMAKE_CXX_COMPILER_ID MATCHES "SunPro")
901                 set(PLATFORM_CFLAGS "-pipe -features=extensions -fPIC -D__FUNCTION__=__func__")
902                 
903         # Intel C++ Compiler
904         elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
905                 # think these next two are broken
906                 find_program(XIAR xiar)
907                 if(XIAR)
908                         set(CMAKE_AR "${XIAR}")
909                 endif()
910                 mark_as_advanced(XIAR)
911
912                 find_program(XILD xild)
913                 if(XILD)
914                         set(CMAKE_LINKER "${XILD}")
915                 endif()
916                 mark_as_advanced(XILD)
917
918                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise -prec_div -parallel")
919                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -prec_div -parallel")
920
921                 # set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -diag-enable sc3")
922                 set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
923                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-intel")
924         endif()
925
926 elseif(WIN32)
927
928         # this file is included anyway when building under Windows with cl.exe
929         #  include(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
930
931         if(CMAKE_COMPILER_IS_GNUCC)
932                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
933                 include(CheckCSourceCompiles)
934                 # Setup 64bit and 64bit windows systems
935                 CHECK_C_SOURCE_COMPILES("
936                         #ifndef __MINGW64__
937                         #error
938                         #endif
939                         main(){}
940                         " 
941                         WITH_MINGW64)
942                 
943                 if(WITH_MINGW64)
944                         message("Compiling for 64 bit with MinGW-w64.")
945                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
946                 endif()
947         else()
948                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
949
950                 # Setup 64bit and 64bit windows systems
951                 if(CMAKE_CL_64)
952                         message("64 bit compiler detected.")
953                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64)
954                 endif()
955         endif()
956                 
957         add_definitions(-DWIN32)
958
959         set(JPEG "${LIBDIR}/jpeg")
960         set(JPEG_INCLUDE_DIR "${JPEG}/include")
961         set(JPEG_LIBPATH ${JPEG}/lib) # not cmake defined
962
963         set(WINTAB_INC ${LIBDIR}/wintab/include)
964
965         if(WITH_OPENAL)
966                 set(OPENAL ${LIBDIR}/openal)
967                 set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
968                 set(OPENAL_LIBRARY wrap_oal)
969                 set(OPENAL_LIBPATH ${OPENAL}/lib)
970         endif()
971
972         if(WITH_CODEC_SNDFILE)
973                 set(SNDFILE ${LIBDIR}/sndfile)
974                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
975                 set(SNDFILE_LIBRARIES libsndfile-1)
976                 set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
977         endif()
978
979         if(WITH_SDL)
980                 set(SDL ${LIBDIR}/sdl)
981                 set(SDL_INCLUDE_DIR ${SDL}/include)
982                 set(SDL_LIBRARY SDL)
983                 set(SDL_LIBPATH ${SDL}/lib)
984         endif()
985
986         if(WITH_CODEC_QUICKTIME)
987                 set(QUICKTIME ${LIBDIR}/QTDevWin)
988                 set(QUICKTIME_INCLUDE_DIRS ${QUICKTIME}/CIncludes)
989                 set(QUICKTIME_LIBRARIES qtmlClient)
990                 set(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
991         endif()
992
993         if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
994                 add_definitions(-D__SSE__ -D__MMX__)
995         endif()
996
997         if(WITH_CYCLES_OSL)
998                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
999         
1000                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1001                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1002                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1003                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
1004                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1005                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1006         
1007                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1008                         set(OSL_FOUND TRUE)
1009                 else()
1010                         message(STATUS "OSL not found")
1011                 endif()
1012         endif()
1013
1014         if(MSVC)
1015                 set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid psapi)
1016
1017                 add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB)
1018
1019                 set(CMAKE_CXX_FLAGS "/nologo /J /Gd /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE)
1020                 set(CMAKE_C_FLAGS   "/nologo /J /Gd"       CACHE STRING "MSVC MT C++ flags " FORCE)
1021
1022                 if(CMAKE_CL_64)
1023                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /Zi" CACHE STRING "MSVC MT flags " FORCE)
1024                 else()
1025                         set(CMAKE_CXX_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /ZI" CACHE STRING "MSVC MT flags " FORCE)
1026                 endif()
1027                 set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /MT" CACHE STRING "MSVC MT flags " FORCE)
1028                 set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /MT" CACHE STRING "MSVC MT flags " FORCE)
1029                 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi" CACHE STRING "MSVC MT flags " FORCE)
1030                 if(CMAKE_CL_64)
1031                         set(CMAKE_C_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /Zi" CACHE STRING "MSVC MT flags " FORCE)
1032                 else()
1033                         set(CMAKE_C_FLAGS_DEBUG "/Od /Gm /RTC1 /MTd /ZI" CACHE STRING "MSVC MT flags " FORCE)
1034                 endif()
1035                 set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT" CACHE STRING "MSVC MT flags " FORCE)
1036                 set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /MT" CACHE STRING "MSVC MT flags " FORCE)
1037                 set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi" CACHE STRING "MSVC MT flags " FORCE)
1038
1039                 # most msvc warnings are C & C++
1040                 set(_WARNINGS "/W3 /wd4018 /wd4244 /wd4305 /wd4800 /wd4181 /wd4065 /wd4267 /we4013 /wd4200")
1041                 set(C_WARNINGS "${_WARNINGS}")
1042                 set(CXX_WARNINGS "${_WARNINGS}")
1043                 unset(_WARNINGS)
1044
1045                 if(WITH_MOD_CLOTH_ELTOPO)
1046                         set(LAPACK ${LIBDIR}/lapack)
1047                         # set(LAPACK_INCLUDE_DIR ${LAPACK}/include)
1048                         set(LAPACK_LIBPATH ${LAPACK}/lib)
1049                         set(LAPACK_LIBRARIES
1050                                 ${LIBDIR}/lapack/lib/libf2c.lib
1051                                 ${LIBDIR}/lapack/lib/clapack_nowrap.lib
1052                                 ${LIBDIR}/lapack/lib/BLAS_nowrap.lib
1053                         )
1054                 endif()
1055
1056                 set(PNG_LIBRARIES libpng)
1057                 set(JPEG_LIBRARIES libjpeg)
1058                 
1059                 set(PNG "${LIBDIR}/png")
1060                 set(PNG_INCLUDE_DIR "${PNG}/include")
1061                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1062
1063                 set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
1064                 if(CMAKE_CL_64)
1065                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz.lib)
1066                 else()
1067                         set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/zlib.lib)
1068                 endif()
1069
1070                 set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
1071                 set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
1072
1073                 set(FREETYPE ${LIBDIR}/freetype)
1074                 set(FREETYPE_INCLUDE_DIRS
1075                         ${LIBDIR}/freetype/include
1076                         ${LIBDIR}/freetype/include/freetype2
1077                 )
1078                 set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
1079
1080                 if(WITH_FFTW3)
1081                         set(FFTW3 ${LIBDIR}/fftw3)
1082                         set(FFTW3_LIBRARIES libfftw)
1083                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1084                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1085                 endif()
1086
1087                 if(WITH_OPENCOLLADA)
1088                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1089
1090                         set(OPENCOLLADA_INCLUDE_DIRS
1091                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1092                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1093                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1094                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1095                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1096                         )
1097                         set_lib_path(OPENCOLLADA_LIBPATH "opencollada")
1098
1099                         set(OPENCOLLADA_LIBRARIES
1100                                 ${OPENCOLLADA_LIBPATH}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
1101                                 ${OPENCOLLADA_LIBPATH}/lib/opencollada/OpenCOLLADAFramework.lib
1102                                 ${OPENCOLLADA_LIBPATH}/lib/opencollada/OpenCOLLADABaseUtils.lib
1103                                 ${OPENCOLLADA_LIBPATH}/lib/opencollada/OpenCOLLADAStreamWriter.lib
1104                                 ${OPENCOLLADA_LIBPATH}/lib/opencollada/MathMLSolver.lib
1105                                 ${OPENCOLLADA_LIBPATH}/lib/opencollada/GeneratedSaxParser.lib
1106                                 ${OPENCOLLADA_LIBPATH}/lib/opencollada/xml.lib
1107                                 ${OPENCOLLADA_LIBPATH}/lib/opencollada/buffer.lib
1108                                 ${OPENCOLLADA_LIBPATH}/lib/opencollada/ftoa.lib
1109                                 ${OPENCOLLADA_LIBPATH}/lib/opencollada/UTF.lib
1110                         )
1111                         set(PCRE_LIBRARIES
1112                                 ${OPENCOLLADA_LIBPATH}/lib/opencollada/pcre.lib
1113                         )
1114                         
1115                         unset(OPENCOLLADA_LIBPATH)
1116                         
1117                 endif()
1118
1119                 if(WITH_CODEC_FFMPEG)
1120                         set(FFMPEG_INCLUDE_DIRS
1121                                 ${LIBDIR}/ffmpeg/include
1122                                 ${LIBDIR}/ffmpeg/include/msvc
1123                         )
1124                         set(FFMPEG_LIBRARIES
1125                                 ${LIBDIR}/ffmpeg/lib/avcodec-53.lib
1126                                 ${LIBDIR}/ffmpeg/lib/avformat-53.lib
1127                                 ${LIBDIR}/ffmpeg/lib/avdevice-53.lib
1128                                 ${LIBDIR}/ffmpeg/lib/avutil-51.lib
1129                                 ${LIBDIR}/ffmpeg/lib/swscale-2.lib
1130                         )
1131                 endif()
1132
1133                 if(WITH_IMAGE_OPENEXR)
1134                         set_lib_path(OPENEXR "openexr")
1135                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1136                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1137                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1138                         set(OPENEXR_LIBRARIES
1139                                 ${OPENEXR_LIBPATH}/Iex.lib
1140                                 ${OPENEXR_LIBPATH}/Half.lib
1141                                 ${OPENEXR_LIBPATH}/IlmImf.lib
1142                                 ${OPENEXR_LIBPATH}/Imath.lib
1143                                 ${OPENEXR_LIBPATH}/IlmThread.lib
1144                         )
1145                 endif()
1146
1147                 if(WITH_IMAGE_TIFF)
1148                         set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
1149                         set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
1150                 endif()
1151
1152                 if(WITH_JACK)
1153                         set(JACK_INCLUDE_DIRS
1154                                 ${LIBDIR}/jack/include/jack
1155                                 ${LIBDIR}/jack/include
1156                         )
1157                         set(JACK_LIBRARIES ${LIBDIR}/jack/lib/libjack.lib)
1158                 endif()
1159
1160                 if(WITH_PYTHON)
1161                         # normally cached but not since we include them with blender
1162                         if(MSVC10)
1163                                 set(PYTHON_VERSION 3.3) # CACHE STRING)
1164                         else()
1165                                 set(PYTHON_VERSION 3.3) # CACHE STRING)
1166                         endif()
1167
1168                         set_lib_path(PYTHON "python")
1169                         string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
1170                         # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
1171                         set(PYTHON_LIBRARY ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.lib)
1172                         # set(PYTHON_LIBRARY ${PYTHON}/lib/python${_PYTHON_VERSION_NO_DOTS}.lib) #CACHE FILEPATH
1173                         unset(_PYTHON_VERSION_NO_DOTS)
1174
1175                         #Shared includes for both vc2008 and vc2010
1176                         set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
1177
1178                         # uncached vars
1179                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1180                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1181                 endif()
1182
1183                 if(WITH_BOOST)
1184                         set(BOOST ${LIBDIR}/boost)
1185                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1186                         if(MSVC10)
1187                                 set(BOOST_LIBPATH ${BOOST}/vc2010/lib)
1188                                 set(BOOST_POSTFIX "vc100-mt-s-1_49.lib")
1189                                 set(BOOST_DEBUG_POSTFIX "vc100-mt-sgd-1_49.lib")
1190                         else()
1191                                 set(BOOST_LIBPATH ${BOOST}/lib)
1192                                 set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
1193                                 set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_49.lib")
1194                         endif()
1195                         set(BOOST_LIBRARIES
1196                                 optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
1197                                 optimized libboost_regex-${BOOST_POSTFIX}
1198                                 optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
1199                                 debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
1200                                 debug libboost_regex-${BOOST_DEBUG_POSTFIX}
1201                                 debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
1202                         if(WITH_CYCLES_OSL)
1203                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1204                                         optimized libboost_wave-${BOOST_POSTFIX}
1205                                         debug libboost_wave-${BOOST_DEBUG_POSTFIX})
1206                         endif()
1207                         if(WITH_INTERNATIONAL)
1208                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1209                                         optimized libboost_locale-${BOOST_POSTFIX}
1210                                         debug libboost_locale-${BOOST_DEBUG_POSTFIX})
1211                         endif()
1212                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB")
1213                 endif()
1214                         
1215                 if(WITH_OPENIMAGEIO)
1216                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1217                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1218                         set(OPENIMAGEIO_LIBRARIES optimized OpenImageIO debug OpenImageIO_d)
1219                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1220                         set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
1221                 endif()
1222
1223                 if(WITH_LLVM)
1224                         set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1225                         file(GLOB LLVM_LIBRARY ${LLVM_DIRECTORY}/lib/*.lib)
1226                 endif()
1227         
1228                 if(WITH_OPENCOLORIO)
1229                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1230                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1231                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1232                         set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
1233                         set(OPENCOLORIO_DEFINITIONS)
1234                 endif()
1235
1236
1237                 set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
1238
1239                 # MSVC only, Mingw doesnt need
1240                 if(CMAKE_CL_64)
1241                         set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
1242                 else()
1243                         set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
1244                 endif()
1245
1246                 set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
1247
1248                 # used in many places so include globally, like OpenGL
1249                 blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
1250
1251         elseif(CMAKE_COMPILER_IS_GNUCC)
1252         # keep GCC specific stuff here
1253                 set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi")
1254                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
1255
1256                 if(WITH_MINGW64)
1257                         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
1258                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -lpthread")
1259                         
1260                         add_definitions(-DFREE_WINDOWS64 -DMS_WIN64)
1261                         #Turn off OpenMP since it causes crashes on render for subsurfed/multiresolution meshes
1262                         set(WITH_OPENMP OFF)
1263                 endif()
1264
1265                 add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
1266
1267                 add_definitions(-DFREE_WINDOWS)
1268
1269                 set(PNG "${LIBDIR}/png")
1270                 set(PNG_INCLUDE_DIR "${PNG}/include")
1271                 set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
1272
1273                 if(WITH_MINGW64)
1274                         set(JPEG_LIBRARIES jpeg)
1275                 else()
1276                         set(JPEG_LIBRARIES libjpeg)
1277                 endif()
1278                 set(PNG_LIBRARIES png)
1279
1280                 set(ZLIB ${LIBDIR}/zlib)
1281                 set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
1282                 set(ZLIB_LIBPATH ${ZLIB}/lib)
1283                 set(ZLIB_LIBRARIES z)
1284
1285                 #comes with own pthread library
1286                 if(NOT WITH_MINGW64)
1287                         set(PTHREADS ${LIBDIR}/pthreads)
1288                         #set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
1289                         set(PTHREADS_LIBPATH ${PTHREADS}/lib)
1290                         set(PTHREADS_LIBRARIES pthreadGC2)
1291                 endif()
1292                 
1293                 set(FREETYPE ${LIBDIR}/freetype)
1294                 set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1295                 set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1296                 set(FREETYPE_LIBRARY freetype)
1297
1298                 if(WITH_FFTW3)
1299                         set(FFTW3 ${LIBDIR}/fftw3)
1300                         set(FFTW3_LIBRARIES fftw3)
1301                         set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1302                         set(FFTW3_LIBPATH ${FFTW3}/lib)
1303                 endif()
1304
1305                 if(WITH_OPENCOLLADA)
1306                         set(OPENCOLLADA ${LIBDIR}/opencollada)
1307                         set(OPENCOLLADA_INCLUDE_DIRS
1308                                 ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
1309                                 ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
1310                                 ${OPENCOLLADA}/include/opencollada/COLLADAFramework
1311                                 ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
1312                                 ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
1313                         )
1314                         set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib/opencollada)
1315                         set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver buffer ftoa xml)
1316                         set(PCRE_LIBRARIES pcre)
1317                 endif()
1318
1319                 if(WITH_CODEC_FFMPEG)
1320                         set(FFMPEG ${LIBDIR}/ffmpeg)
1321                         set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1322                         if(WITH_MINGW64)
1323                                 set(FFMPEG_LIBRARIES avcodec.dll avformat.dll avdevice.dll avutil.dll swscale.dll swresample.dll)
1324                         else()
1325                                 set(FFMPEG_LIBRARIES avcodec-53 avformat-53 avdevice-53 avutil-51 swscale-2)
1326                         endif()
1327                         set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1328                 endif()
1329
1330                 if(WITH_IMAGE_OPENEXR)
1331                         set(OPENEXR ${LIBDIR}/openexr)
1332                         set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1333                         set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1334                         set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
1335                         set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1336                 endif()
1337
1338                 if(WITH_IMAGE_TIFF)
1339                         set(TIFF ${LIBDIR}/tiff)
1340                         set(TIFF_LIBRARY tiff)
1341                         set(TIFF_INCLUDE_DIR ${TIFF}/include)
1342                         set(TIFF_LIBPATH ${TIFF}/lib)
1343                 endif()
1344
1345                 if(WITH_JACK)
1346                         set(JACK ${LIBDIR}/jack)
1347                         set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
1348                         set(JACK_LIBRARIES jack)
1349                         set(JACK_LIBPATH ${JACK}/lib)
1350
1351                         # TODO, gives linking errors, force off
1352                         set(WITH_JACK OFF)
1353                 endif()
1354
1355                 if(WITH_PYTHON)
1356                         # normally cached but not since we include them with blender
1357                         set(PYTHON_VERSION 3.3) #  CACHE STRING)
1358                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
1359                         set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python33mw.lib")  # CACHE FILEPATH)
1360
1361                         # uncached vars
1362                         set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1363                         set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1364                 endif()
1365
1366                 if(WITH_BOOST)
1367                         set(BOOST ${LIBDIR}/boost)
1368                         set(BOOST_INCLUDE_DIR ${BOOST}/include)
1369                         if(WITH_MINGW64)
1370                                 set(BOOST_POSTFIX "mgw47-mt-s-1_49")
1371                                 set(BOOST_DEBUG_POSTFIX "mgw47-mt-sd-1_49")
1372                         else()
1373                                 set(BOOST_POSTFIX "mgw46-mt-s-1_49")
1374                                 set(BOOST_DEBUG_POSTFIX "mgw46-mt-sd-1_49")
1375                         endif()
1376                         set(BOOST_LIBRARIES
1377                                 optimized boost_date_time-${BOOST_POSTFIX} boost_filesystem-${BOOST_POSTFIX}
1378                                 boost_regex-${BOOST_POSTFIX}
1379                                 boost_system-${BOOST_POSTFIX} boost_thread-${BOOST_POSTFIX}
1380                                 debug boost_date_time-${BOOST_DEBUG_POSTFIX} boost_filesystem-${BOOST_DEBUG_POSTFIX}
1381                                 boost_regex-${BOOST_DEBUG_POSTFIX}
1382                                 boost_system-${BOOST_DEBUG_POSTFIX} boost_thread-${BOOST_DEBUG_POSTFIX})
1383                         if(WITH_INTERNATIONAL)
1384                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1385                                         optimized boost_locale-${BOOST_POSTFIX}
1386                                         debug boost_locale-${BOOST_DEBUG_POSTFIX}) 
1387                         endif()
1388                         if(WITH_CYCLES_OSL)
1389                                 set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
1390                                         optimized boost_wave-${BOOST_POSTFIX}
1391                                         debug boost_wave-${BOOST_DEBUG_POSTFIX}) 
1392                         endif()
1393                         set(BOOST_LIBPATH ${BOOST}/lib)
1394                         set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
1395                 endif()
1396                         
1397                 if(WITH_OPENIMAGEIO)
1398                         set(OPENIMAGEIO ${LIBDIR}/openimageio)
1399                         set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1400                         set(OPENIMAGEIO_LIBRARIES OpenImageIO)
1401                         set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
1402                         set(OPENIMAGEIO_DEFINITIONS "")
1403                 endif()
1404                 
1405                 if(WITH_LLVM)
1406                         set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1407                         set(LLVM_LIB_DIR ${LLVM_DIRECTORY}/lib)
1408                         #Explicitly set llvm lib order.
1409                         #---- WARNING ON GCC ORDER OF LIBS IS IMPORTANT, DO NOT CHANGE! ---------
1410                         set(LLVM_LIBRARY LLVMSelectionDAG LLVMCodeGen LLVMScalarOpts LLVMAnalysis LLVMArchive
1411                                 LLVMAsmParser LLVMAsmPrinter
1412                                 LLVMBitReader LLVMBitWriter
1413                                 LLVMDebugInfo LLVMExecutionEngine
1414                                 LLVMInstCombine LLVMInstrumentation
1415                                 LLVMInterpreter LLVMJIT
1416                                 LLVMLinker LLVMMC
1417                                 LLVMMCDisassembler LLVMMCJIT
1418                                 LLVMMCParser LLVMObject
1419                                 LLVMRuntimeDyld 
1420                                 LLVMSupport
1421                                 LLVMTableGen LLVMTarget
1422                                 LLVMTransformUtils LLVMVectorize
1423                                 LLVMX86AsmParser LLVMX86AsmPrinter
1424                                 LLVMX86CodeGen LLVMX86Desc
1425                                 LLVMX86Disassembler LLVMX86Info
1426                                 LLVMX86Utils LLVMipa
1427                                 LLVMipo LLVMCore)
1428                         #imagehelp is needed by LLVM 3.1 on MinGW, check lib\Support\Windows\Signals.inc
1429                         set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -limagehlp")
1430                 endif()
1431                 
1432                 if(WITH_OPENCOLORIO)
1433                         set(OPENCOLORIO ${LIBDIR}/opencolorio)
1434                         set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1435                         set(OPENCOLORIO_LIBRARIES OpenColorIO)
1436                         set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1437                         set(OPENCOLORIO_DEFINITIONS)
1438                 endif()
1439
1440                 set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
1441
1442                 ## DISABLE - causes linking errors 
1443                 ## for re-distribution, so users dont need mingw installed
1444                 # set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -static-libgcc -static-libstdc++")
1445
1446         endif()
1447
1448 elseif(APPLE)
1449
1450         if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
1451                 set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/10.7
1452         endif()
1453
1454         if(WITH_LIBS10.5)
1455                 set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
1456         else()
1457                 if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1458                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
1459                 else()
1460                         set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
1461                 endif()
1462         endif()
1463
1464
1465         if(WITH_OPENAL)
1466                 find_package(OpenAL)
1467                 if(OPENAL_FOUND)
1468                         set(WITH_OPENAL ON)
1469                         set(OPENAL_INCLUDE_DIR "${LIBDIR}/openal/include")
1470                 else()
1471                         set(WITH_OPENAL OFF)
1472                 endif()
1473         endif()
1474
1475         if(WITH_JACK)
1476                 find_library(JACK_FRAMEWORK
1477                         NAMES jackmp
1478                 )
1479                 set(JACK_INCLUDE_DIRS ${JACK_FRAMEWORK}/headers)
1480                 if(NOT JACK_FRAMEWORK)
1481                         set(WITH_JACK OFF)
1482                 endif()
1483         endif()
1484
1485         if(WITH_CODEC_SNDFILE)
1486                 set(SNDFILE ${LIBDIR}/sndfile)
1487                 set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
1488                 set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
1489                 set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
1490         endif()
1491
1492         if(WITH_PYTHON)
1493                 # we use precompiled libraries for py 3.3 and up by default
1494                 set(PYTHON_VERSION 3.3)
1495                 if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
1496                         # normally cached but not since we include them with blender
1497                         set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
1498                         # set(PYTHON_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
1499                         set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
1500                         set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
1501                         # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
1502                 else()
1503                         # module must be compiled against Python framework
1504                         set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
1505                         set(PYTHON_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
1506                         #set(PYTHON_LIBRARY python${PYTHON_VERSION})
1507                         set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
1508                         #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
1509                 endif()
1510                 
1511                 # uncached vars
1512                 set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
1513                 set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
1514         endif()
1515
1516         if(WITH_FFTW3)
1517                 set(FFTW3 ${LIBDIR}/fftw3)
1518                 set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
1519                 set(FFTW3_LIBRARIES fftw3)
1520                 set(FFTW3_LIBPATH ${FFTW3}/lib)
1521         endif()
1522
1523         set(PNG_LIBRARIES png)
1524         set(JPEG_LIBRARIES jpeg)
1525
1526         set(ZLIB /usr)
1527         set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
1528         set(ZLIB_LIBRARIES z bz2)
1529
1530         set(FREETYPE ${LIBDIR}/freetype)
1531         set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
1532         set(FREETYPE_LIBPATH ${FREETYPE}/lib)
1533         set(FREETYPE_LIBRARY freetype)
1534
1535         if(WITH_IMAGE_OPENEXR)
1536                 set(OPENEXR ${LIBDIR}/openexr)
1537                 set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
1538                 set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
1539                 set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
1540                 set(OPENEXR_LIBPATH ${OPENEXR}/lib)
1541         endif()
1542
1543         if(WITH_CODEC_FFMPEG)
1544                 set(FFMPEG ${LIBDIR}/ffmpeg)
1545                 set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
1546                 set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
1547                 set(FFMPEG_LIBPATH ${FFMPEG}/lib)
1548                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
1549         endif()
1550
1551         find_library(SYSTEMSTUBS_LIBRARY
1552                 NAMES
1553                 SystemStubs
1554                 PATHS
1555         )
1556         mark_as_advanced(SYSTEMSTUBS_LIBRARY)
1557         if(SYSTEMSTUBS_LIBRARY)
1558                 set(PLATFORM_LINKLIBS stdc++ SystemStubs)
1559         else()
1560                 set(PLATFORM_LINKLIBS stdc++)
1561         endif()
1562
1563         if(WITH_COCOA)
1564                 set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
1565                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
1566                 if(USE_QTKIT)
1567                         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -DUSE_QTKIT")
1568                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
1569                         if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
1570                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1571                                 #libSDL still needs 32bit carbon quicktime
1572                         endif()
1573                 elseif(WITH_CODEC_QUICKTIME)
1574                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
1575                 endif()
1576
1577                 # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
1578                 # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
1579                 if(WITH_INPUT_NDOF)
1580                         # This thread it *should* work and check the framework - campbell
1581                         # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
1582                         find_library(3DCONNEXION_CLIENT_FRAMEWORK
1583                                 NAMES 3DconnexionClient
1584                         )
1585                         if(NOT 3DCONNEXION_CLIENT_FRAMEWORK)
1586                                 set(WITH_INPUT_NDOF OFF)
1587                         endif()
1588
1589                         if(WITH_INPUT_NDOF)
1590                                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework 3DconnexionClient")
1591                                 set(NDOF_INCLUDE_DIRS /Library/Frameworks/3DconnexionClient.framework/Headers )
1592                         endif()
1593                 endif()
1594
1595         if(WITH_JACK)
1596                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -weak_framework jackmp")
1597         endif()
1598
1599         else()
1600                 set(PLATFORM_CFLAGS "-pipe -funsigned-char")
1601                 set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Carbon -framework AGL -framework AudioUnit -framework AudioToolbox -framework CoreAudio -framework QuickTime")
1602                 set(WITH_INPUT_NDOF OFF)  # unsupported
1603         endif()
1604         
1605         if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK)
1606                 set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")# force cmake to link right framework
1607         endif()
1608         
1609         if(WITH_OPENCOLLADA)
1610                 set(OPENCOLLADA ${LIBDIR}/opencollada)
1611
1612                 set(OPENCOLLADA_INCLUDE_DIRS
1613                         ${LIBDIR}/opencollada/include/COLLADAStreamWriter
1614                         ${LIBDIR}/opencollada/include/COLLADABaseUtils
1615                         ${LIBDIR}/opencollada/include/COLLADAFramework
1616                         ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader
1617                         ${LIBDIR}/opencollada/include/GeneratedSaxParser
1618                 )
1619
1620                 set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
1621                 set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa")
1622                 #pcre is bundled with openCollada
1623                 #set(PCRE ${LIBDIR}/pcre)
1624                 #set(PCRE_LIBPATH ${PCRE}/lib)
1625                 set(PCRE_LIBRARIES pcre)
1626                 #libxml2 is used
1627                 #set(EXPAT ${LIBDIR}/expat)
1628                 #set(EXPAT_LIBPATH ${EXPAT}/lib)
1629                 set(EXPAT_LIB)
1630         endif()
1631
1632         if(WITH_SDL)
1633                 set(SDL ${LIBDIR}/sdl)
1634                 set(SDL_INCLUDE_DIR ${SDL}/include)
1635                 set(SDL_LIBRARY SDL)
1636                 set(SDL_LIBPATH ${SDL}/lib)
1637         endif()
1638
1639         set(PNG "${LIBDIR}/png")
1640         set(PNG_INCLUDE_DIR "${PNG}/include")
1641         set(PNG_LIBPATH ${PNG}/lib)
1642
1643         set(JPEG "${LIBDIR}/jpeg")
1644         set(JPEG_INCLUDE_DIR "${JPEG}/include")
1645         set(JPEG_LIBPATH ${JPEG}/lib)
1646
1647         if(WITH_IMAGE_TIFF)
1648                 set(TIFF ${LIBDIR}/tiff)
1649                 set(TIFF_INCLUDE_DIR ${TIFF}/include)
1650                 set(TIFF_LIBRARY tiff)
1651                 set(TIFF_LIBPATH ${TIFF}/lib)
1652         endif()
1653
1654         if(WITH_INPUT_NDOF)
1655                 # linker needs "-weak_framework 3DconnexionClient"
1656         endif()
1657
1658         if(WITH_BOOST)
1659                 set(BOOST ${LIBDIR}/boost)
1660                 set(BOOST_INCLUDE_DIR ${BOOST}/include)
1661                 set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt boost_wave-mt)
1662                 if(WITH_INTERNATIONAL)
1663                         list(APPEND BOOST_LIBRARIES boost_locale-mt)
1664                         set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -liconv") # boost_locale needs it !
1665                 endif()
1666                 set(BOOST_LIBPATH ${BOOST}/lib)
1667                 set(BOOST_DEFINITIONS)
1668         endif()
1669
1670         if(WITH_OPENIMAGEIO)
1671                 set(OPENIMAGEIO ${LIBDIR}/openimageio)
1672                 set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
1673                 set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO}/lib/libOpenImageIO.a ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
1674                 set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
1675                 set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
1676         endif()
1677
1678         if(WITH_OPENCOLORIO)
1679                 set(OPENCOLORIO ${LIBDIR}/opencolorio)
1680                 set(OPENCOLORIO_INCLUDE_DIRS ${OPENCOLORIO}/include)
1681                 set(OPENCOLORIO_LIBRARIES OpenColorIO tinyxml yaml-cpp)
1682                 set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
1683                 set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
1684         endif()
1685
1686         if(WITH_LLVM)
1687                 set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
1688                 set(LLVM_VERSION "3.1" CACHE STRING     "Version of LLVM to use")
1689                 if(EXISTS "${LLVM_DIRECTORY}/bin/llvm-config")
1690                         set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
1691                 else()
1692                         set(LLVM_CONFIG llvm-config)
1693                 endif()
1694                 execute_process(COMMAND ${LLVM_CONFIG} --version
1695                                 OUTPUT_VARIABLE LLVM_VERSION
1696                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1697                 execute_process(COMMAND ${LLVM_CONFIG} --prefix
1698                                 OUTPUT_VARIABLE LLVM_DIRECTORY
1699                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1700                 execute_process(COMMAND ${LLVM_CONFIG} --libdir
1701                                 OUTPUT_VARIABLE LLVM_LIB_DIR
1702                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1703                 find_library(LLVM_LIBRARY
1704                              NAMES LLVMAnalysis # first of a whole bunch of libs to get
1705                              PATHS ${LLVM_LIB_DIR})
1706
1707                 if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIB_DIR)
1708                         if(LLVM_STATIC)
1709                                 # if static LLVM libraries were requested, use llvm-config to generate
1710                                 # the list of what libraries we need, and substitute that in the right
1711                                 # way for LLVM_LIBRARY.
1712                                 execute_process(COMMAND ${LLVM_CONFIG} --libfiles
1713                                                 OUTPUT_VARIABLE LLVM_LIBRARY
1714                                                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1715                                 string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
1716                         endif()
1717                 else()
1718                         message(FATAL_ERROR "LLVM not found.")
1719                 endif()
1720         endif()
1721
1722         if(WITH_CYCLES_OSL)
1723                 set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
1724         
1725                 find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
1726                 find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
1727                 find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
1728                 # WARNING! depends on correct order of OSL libs linking
1729                 list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -force_load ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
1730                 find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
1731                 find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
1732         
1733                 if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
1734                         set(OSL_FOUND TRUE)
1735                 else()
1736                         message(STATUS "OSL not found")
1737                 endif()
1738         endif()
1739
1740         set(EXETYPE MACOSX_BUNDLE)
1741
1742         set(CMAKE_C_FLAGS_DEBUG "-fno-strict-aliasing -g")
1743         set(CMAKE_CXX_FLAGS_DEBUG "-fno-strict-aliasing -g")
1744         if(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64" OR CMAKE_OSX_ARCHITECTURES MATCHES "i386")
1745                 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -mdynamic-no-pic -msse -msse2 -msse3 -mssse3")
1746                 set(CMAKE_C_FLAGS_RELEASE "-O2 -mdynamic-no-pic  -msse -msse2 -msse3 -mssse3")
1747                 if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1748                         set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
1749                         set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize  -fvariable-expansion-in-unroller")
1750                 endif()
1751         else()
1752                 set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1753                 set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
1754         endif()
1755 endif()
1756
1757 #-----------------------------------------------------------------------------
1758 # Common.
1759
1760 if(APPLE OR WIN32)
1761         if(NOT EXISTS "${LIBDIR}/")
1762                 message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
1763         endif()
1764 endif()
1765
1766 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
1767         message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
1768 endif()
1769
1770 if(WITH_CYCLES)
1771         if(NOT WITH_OPENIMAGEIO)
1772                 message(FATAL_ERROR "Cycles reqires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
1773         endif()
1774         if(NOT WITH_BOOST)
1775                 message(FATAL_ERROR "Cycles reqires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
1776         endif()
1777
1778         if(WITH_CYCLES_OSL)
1779                 if(NOT WITH_LLVM)
1780                         message(FATAL_ERROR "Cycles OSL reqires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
1781                 endif()
1782         endif()
1783 endif()
1784
1785 if(WITH_INTERNATIONAL)
1786         if(NOT WITH_BOOST)
1787                 message(FATAL_ERROR "Internationalization reqires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_INTERNATIONAL")
1788         endif()
1789 endif()
1790
1791 # See TEST_SSE_SUPPORT() for how this is defined.
1792
1793 if(WITH_RAYOPTIMIZATION)
1794         if(SUPPORT_SSE_BUILD)
1795                 set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
1796                 add_definitions(-D__SSE__ -D__MMX__)
1797         endif()
1798         if(SUPPORT_SSE2_BUILD)
1799                 set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
1800                 add_definitions(-D__SSE2__)
1801                 if(NOT SUPPORT_SSE_BUILD) # dont double up
1802                         add_definitions(-D__MMX__)
1803                 endif()
1804         endif()
1805 endif()
1806
1807
1808 # set the endian define
1809 if(MSVC)
1810         # for some reason this fails on msvc
1811         add_definitions(-D__LITTLE_ENDIAN__)
1812         
1813 # OSX-Note: as we do crosscompiling with specific set architecture,
1814 # endianess-detection and autosetting is counterproductive
1815 # so we just set endianess according CMAKE_OSX_ARCHITECTURES
1816
1817 elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64)
1818         add_definitions(-D__LITTLE_ENDIAN__)
1819 elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64)            
1820         add_definitions(-D__BIG_ENDIAN__)
1821         
1822 else()
1823         include(TestBigEndian)
1824         test_big_endian(_SYSTEM_BIG_ENDIAN)
1825         if(_SYSTEM_BIG_ENDIAN)
1826                 add_definitions(-D__BIG_ENDIAN__)
1827         else()
1828                 add_definitions(-D__LITTLE_ENDIAN__)
1829         endif()
1830         unset(_SYSTEM_BIG_ENDIAN)
1831 endif()
1832
1833
1834 if(WITH_IMAGE_OPENJPEG)
1835         if(WITH_SYSTEM_OPENJPEG)
1836                 # dealt with above
1837         else()
1838                 set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
1839                 add_definitions(-DOPJ_STATIC)
1840         endif()
1841 endif()
1842
1843 if(WITH_IMAGE_REDCODE)
1844         set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
1845         set(REDCODE_INC ${REDCODE})
1846 endif()
1847
1848 #-----------------------------------------------------------------------------
1849 # Blender WebPlugin
1850
1851 if(WITH_WEBPLUGIN)
1852         set(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
1853         set(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
1854
1855         set(WITH_PLAYER ON)
1856 endif()
1857
1858
1859 #-----------------------------------------------------------------------------
1860 # Configure OpenGL.
1861 find_package(OpenGL)
1862 blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
1863 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake
1864 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake
1865
1866 #-----------------------------------------------------------------------------
1867 # Configure OpenMP.
1868 if(WITH_OPENMP)
1869         find_package(OpenMP)
1870         if(OPENMP_FOUND)
1871                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
1872                 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
1873
1874                 if(APPLE AND ${CMAKE_GENERATOR} MATCHES "Xcode")
1875                         set(CMAKE_XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT "YES")
1876                 endif()
1877         else()
1878                 set(WITH_OPENMP OFF)
1879         endif()
1880
1881         mark_as_advanced(
1882                 OpenMP_C_FLAGS
1883                 OpenMP_CXX_FLAGS
1884         )
1885 endif()
1886
1887 #-----------------------------------------------------------------------------
1888 # Configure GLEW
1889
1890 if(WITH_SYSTEM_GLEW)
1891         find_package(GLEW)
1892
1893         if(NOT GLEW_FOUND)
1894                 message(FATAL_ERROR "GLEW is required to build blender, install it or disable WITH_SYSTEM_GLEW")
1895         endif()
1896
1897         mark_as_advanced(
1898                 GLEW_LIBRARY
1899                 GLEW_INCLUDE_PATH
1900         )
1901 else()
1902         # set(GLEW_LIBRARY "")  # unused
1903         set(GLEW_INCLUDE_PATH "${CMAKE_SOURCE_DIR}/extern/glew/include")
1904 endif()
1905
1906
1907 #-----------------------------------------------------------------------------
1908 # Configure Bullet
1909
1910 if(WITH_BULLET AND WITH_SYSTEM_BULLET)
1911         find_package(Bullet)
1912         if(NOT BULLET_FOUND)
1913                 set(WITH_BULLET OFF)
1914         endif()
1915 else()
1916         set(BULLET_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/bullet2/src")
1917         # set(BULLET_LIBRARIES "")
1918 endif()
1919
1920 #-----------------------------------------------------------------------------
1921 # Configure Python.
1922
1923 if(WITH_PYTHON_MODULE)
1924         add_definitions(-DPy_ENABLE_SHARED)
1925 endif()
1926
1927 #-----------------------------------------------------------------------------
1928 # Extra compile flags
1929
1930 if(CMAKE_COMPILER_IS_GNUCC)
1931
1932         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
1933         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
1934         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
1935         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
1936         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
1937         # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
1938         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
1939         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
1940         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
1941         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
1942         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
1943         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
1944         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_WRITE_STRINGS -Wwrite-strings)
1945         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_LOGICAL_OP -Wlogical-op)
1946         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNDEF -Wundef)
1947         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1948         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
1949         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1950         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1951
1952         # gcc 4.2 gives annoying warnings on every file with this
1953         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1954                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
1955         endif()
1956
1957         # versions before gcc4.6 give many BLI_math warnings
1958         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
1959                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
1960                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
1961         endif()
1962
1963         # disable because it gives warnings for printf() & friends.
1964         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
1965
1966         if(NOT APPLE)
1967                 ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1968         endif()
1969
1970         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
1971         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
1972         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
1973         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_LOGICAL_OP -Wlogical-op)
1974         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
1975         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
1976         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
1977
1978         # gcc 4.2 gives annoying warnings on every file with this
1979         if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
1980                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
1981         endif()
1982
1983         # causes too many warnings
1984         if(NOT APPLE)
1985                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
1986                 ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_DECLARATIONS -Wmissing-declarations)
1987         endif()
1988
1989         # flags to undo strict flags
1990         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DEPRECATED_DECLARATIONS -Wno-deprecated-declarations)
1991         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER        -Wno-unused-parameter)
1992
1993         if(NOT APPLE)
1994                 ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_ERROR_UNUSED_BUT_SET_VARIABLE -Wno-error=unused-but-set-variable)
1995         endif()
1996
1997 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1998
1999         # strange, clang complains these are not supported, but then yses them.
2000         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2001         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
2002         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
2003         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
2004         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2005         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2006         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
2007         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
2008         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
2009         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
2010
2011         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2012         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
2013         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
2014         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
2015         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.
2016         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
2017         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
2018
2019         # gives too many unfixable warnings
2020         # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
2021         # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
2022
2023         # flags to undo strict flags
2024         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
2025         ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
2026
2027 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
2028
2029         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
2030         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_POINTER_ARITH -Wpointer-arith)
2031         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
2032
2033         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
2034         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF -Wno-invalid-offsetof)
2035         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE -Wno-sign-compare)
2036
2037         # disable numbered, false positives
2038         set(C_WARNINGS "${C_WARNINGS} -wd188,186,144,913,556")
2039         set(CXX_WARNINGS "${CXX_WARNINGS} -wd188,186,144,913,556")
2040
2041 endif()
2042
2043 # MSVC2010 fails to links C++ libs right
2044 if(MSVC10)
2045         if(WITH_OPENCOLLADA)
2046                 message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008")
2047         endif()
2048 endif()
2049
2050 # ensure python header is found since detection can fail, this could happen
2051 # with _any_ library but since we used a fixed python version this tends to
2052 # be most problematic.
2053 if(WITH_PYTHON)
2054         if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
2055                 message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
2056                                                         "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
2057                                                         "to a valid python include path. Containing "
2058                                                         "Python.h for python version \"${PYTHON_VERSION}\"")
2059         endif()
2060
2061         if(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
2062                 # set but invalid
2063                 # -- disabled until we make numpy bundled with blender - campbell
2064                 if((NOT ${PYTHON_NUMPY_PATH} STREQUAL "") AND (NOT ${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
2065 #                       if(NOT EXISTS "${PYTHON_NUMPY_PATH}/numpy")
2066 #                               message(WARNING "PYTHON_NUMPY_PATH is invalid, numpy not found in '${PYTHON_NUMPY_PATH}' "
2067 #                                               "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
2068 #                               set(WITH_PYTHON_INSTALL_NUMPY OFF)
2069 #                       endif()
2070                 # not set, so initialize
2071                 else()
2072                         string(REPLACE "." ";" _PY_VER_SPLIT "${PYTHON_VERSION}")
2073                         list(GET _PY_VER_SPLIT 0 _PY_VER_MAJOR)
2074
2075                         # re-cache
2076                         unset(PYTHON_NUMPY_PATH CACHE)
2077                         find_path(PYTHON_NUMPY_PATH
2078                           NAMES
2079                             numpy
2080                           HINTS
2081                             "${PYTHON_LIBPATH}/python${PYTHON_VERSION}/"
2082                             "${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/"
2083                           PATH_SUFFIXES
2084                             site-packages
2085                             dist-packages
2086                            NO_DEFAULT_PATH
2087                         )
2088
2089                         if(NOT EXISTS "${PYTHON_NUMPY_PATH}")
2090                                 message(WARNING "'numpy' path could not be found in:\n"
2091                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/numpy', "
2092                                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/site-packages/numpy', "
2093                                                 "'${PYTHON_LIBPATH}/python${PYTHON_VERSION}/dist-packages/numpy', "
2094                                                 "'${PYTHON_LIBPATH}/python${_PY_VER_MAJOR}/dist-packages/numpy', "
2095                                                 "WITH_PYTHON_INSTALL_NUMPY option will be ignored when installing python")
2096                                 set(WITH_PYTHON_INSTALL_NUMPY OFF)
2097                         else()
2098                                 message(STATUS "numpy found at '${PYTHON_NUMPY_PATH}'")
2099                         endif()
2100
2101                         unset(_PY_VER_SPLIT)
2102                         unset(_PY_VER_MAJOR)
2103                 endif()
2104         endif()
2105 endif()
2106
2107 if(WITH_GCC_MUDFLAP)
2108         set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -fmudflapth -funwind-tables")
2109         set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread -lmudflapth -rdynamic")
2110         ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS     C_WARN_NO_ERROR_MUDFLAP   -Wno-error=mudflap)
2111         ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_ERROR_MUDFLAP -Wno-error=mudflap)
2112 endif()
2113
2114 # Include warnings first, so its possible to disable them with user defined flags
2115 # eg: -Wno-uninitialized
2116 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
2117 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
2118
2119 #-------------------------------------------------------------------------------
2120 # Global Defines
2121
2122 # better not set includes here but this debugging option is off by default.
2123 if(WITH_CXX_GUARDEDALLOC)
2124         include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
2125         add_definitions(-DWITH_CXX_GUARDEDALLOC)
2126 endif()
2127
2128 if(WITH_ASSERT_ABORT)
2129         add_definitions(-DWITH_ASSERT_ABORT)
2130 endif()
2131
2132 # message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
2133 # message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
2134
2135 #-----------------------------------------------------------------------------
2136 # Libraries
2137
2138 add_subdirectory(source)
2139 add_subdirectory(intern)
2140 add_subdirectory(extern)
2141
2142
2143 #-----------------------------------------------------------------------------
2144 # Blender Application
2145 if(WITH_BLENDER)
2146         add_subdirectory(source/creator)
2147 endif()
2148
2149
2150 #-----------------------------------------------------------------------------
2151 # Blender Player
2152 if(WITH_PLAYER)
2153         add_subdirectory(source/blenderplayer)
2154 endif()
2155
2156 #-----------------------------------------------------------------------------
2157 # CPack for generating packages
2158 include(build_files/cmake/packaging.cmake)
2159
2160
2161 #-----------------------------------------------------------------------------
2162 # Print Final Configuration
2163
2164 if(FIRST_RUN)
2165         set(_config_msg "\n* Blender Configuration *")
2166         macro(info_cfg_option
2167                 _setting)
2168                 set(_msg "   * ${_setting}")
2169                 string(LENGTH "${_msg}" _len)
2170                 while("32" GREATER "${_len}")
2171                         set(_msg "${_msg} ")
2172                          math(EXPR _len "${_len} + 1")
2173                 endwhile()
2174
2175                 set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
2176         endmacro()
2177
2178         macro(info_cfg_text
2179                 _text)
2180                 set(_config_msg "${_config_msg}\n\n  ${_text}")
2181
2182
2183         endmacro()
2184
2185         info_cfg_text("Build Options:")
2186         info_cfg_option(WITH_GAMEENGINE)
2187         info_cfg_option(WITH_PLAYER)
2188         info_cfg_option(WITH_BULLET)
2189         info_cfg_option(WITH_IK_SOLVER)
2190         info_cfg_option(WITH_IK_ITASC)
2191         info_cfg_option(WITH_OPENCOLLADA)
2192         info_cfg_option(WITH_FFTW3)
2193         info_cfg_option(WITH_INTERNATIONAL)
2194         info_cfg_option(WITH_INPUT_NDOF)
2195         info_cfg_option(WITH_CYCLES)
2196         info_cfg_option(WITH_OPENCOLORIO)
2197
2198         info_cfg_text("Compiler Options:")
2199         info_cfg_option(WITH_BUILDINFO)
2200         info_cfg_option(WITH_OPENMP)
2201         info_cfg_option(WITH_RAYOPTIMIZATION)
2202
2203         info_cfg_text("System Options:")
2204         info_cfg_option(WITH_INSTALL_PORTABLE)
2205         info_cfg_option(WITH_X11_XF86VMODE)
2206         info_cfg_option(WITH_X11_XINPUT)
2207         info_cfg_option(WITH_MEM_JEMALLOC)
2208         info_cfg_option(WITH_SYSTEM_GLEW)
2209         info_cfg_option(WITH_SYSTEM_OPENJPEG)
2210
2211         info_cfg_text("Image Formats:")
2212         info_cfg_option(WITH_IMAGE_CINEON)
2213         info_cfg_option(WITH_IMAGE_DDS)
2214         info_cfg_option(WITH_IMAGE_HDR)
2215         info_cfg_option(WITH_IMAGE_OPENEXR)
2216         info_cfg_option(WITH_IMAGE_OPENJPEG)
2217         info_cfg_option(WITH_IMAGE_REDCODE)
2218         info_cfg_option(WITH_IMAGE_TIFF)
2219
2220         info_cfg_text("Audio:")
2221         info_cfg_option(WITH_OPENAL)
2222         info_cfg_option(WITH_SDL)
2223         info_cfg_option(WITH_JACK)
2224         info_cfg_option(WITH_JACK_DYNLOAD)
2225         info_cfg_option(WITH_CODEC_AVI)
2226         info_cfg_option(WITH_CODEC_FFMPEG)
2227         info_cfg_option(WITH_CODEC_SNDFILE)
2228
2229         info_cfg_text("Compression:")
2230         info_cfg_option(WITH_LZMA)
2231         info_cfg_option(WITH_LZO)
2232
2233         info_cfg_text("Python:")
2234         info_cfg_option(WITH_PYTHON_INSTALL)
2235         info_cfg_option(WITH_PYTHON_INSTALL_NUMPY)
2236         info_cfg_option(WITH_PYTHON_MODULE)
2237         info_cfg_option(WITH_PYTHON_SAFETY)
2238         if(APPLE)
2239                 info_cfg_option(WITH_PYTHON_FRAMEWORK)
2240         endif()
2241
2242         info_cfg_text("Modifiers:")
2243         info_cfg_option(WITH_MOD_BOOLEAN)
2244         info_cfg_option(WITH_MOD_REMESH)
2245         info_cfg_option(WITH_MOD_FLUID)
2246         info_cfg_option(WITH_MOD_OCEANSIM)
2247
2248         # debug
2249         message(STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}")
2250
2251         info_cfg_text("")
2252
2253         message("${_config_msg}")
2254 endif()