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