Lock-free memory allocator
[blender.git] / CMakeLists.txt
index c50caa4a34888959cc00b68a8741a9d2388e8f79..6eb8ec097b4ccc28bc6416f0dc1a72fdbc8b047d 100644 (file)
@@ -118,13 +118,14 @@ mark_as_advanced(WITH_BLENDER)
 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
 
 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
-option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default (recommend to leave off)" OFF)
+option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default" ON) 
 mark_as_advanced(WITH_PYTHON)  # dont want people disabling this unless they really know what they are doing.
 mark_as_advanced(WITH_PYTHON_SECURITY)  # some distributions see this as a security issue, rather than have them patch it, make a build option.
+set(WITH_PYTHON_SECURITY ON CACHE BOOL "ON" FORCE) # temp force on. 
 
 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)
 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)
-if (APPLE)
+if(APPLE)
        option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
 endif()
 
@@ -157,7 +158,6 @@ mark_as_advanced(WITH_AUDASPACE)
 option(WITH_BOOL_COMPAT "Continue defining \"TRUE\" and \"FALSE\" until these can be replaced with \"true\" and \"false\" from stdbool.h" ON)
 mark_as_advanced(WITH_BOOL_COMPAT)
 
-
 # (unix defaults to OpenMP On)
 if((UNIX AND NOT APPLE) OR (MINGW))
        set(PLATFORM_DEFAULT ON)
@@ -206,6 +206,7 @@ option(WITH_MOD_OCEANSIM        "Enable Ocean Modifier" OFF)
 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
 option(WITH_IMAGE_OPENJPEG      "Enable OpenJpeg Support (http://www.openjpeg.org)" ON)
 option(WITH_IMAGE_TIFF          "Enable LibTIFF Support" ON)
+option(WITH_IMAGE_PSD           "Enable Photoshop PSD Support" ON)
 option(WITH_IMAGE_DDS           "Enable DDS Image Support" ON)
 option(WITH_IMAGE_CINEON        "Enable CINEON and DPX Image Support" ON)
 option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
@@ -229,6 +230,9 @@ option(WITH_OPENCOLLADA             "Enable OpenCollada Support (http://www.opencollada.org
 option(WITH_SDL           "Enable SDL for sound and joystick support" ON)
 option(WITH_OPENAL        "Enable OpenAL Support (http://www.openal.org)" ON)
 option(WITH_JACK          "Enable Jack Support (http://www.jackaudio.org)" OFF)
+if(UNIX AND NOT APPLE)
+       option(WITH_JACK_DYNLOAD  "Enable runtime dynamic Jack libraries loading" OFF)
+endif()
 
 # Compression
 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
@@ -258,20 +262,27 @@ mark_as_advanced(PYTHON_NUMPY_PATH)
 
 # Cycles
 option(WITH_CYCLES                                     "Enable cycles Render Engine" ON)
-option(WITH_CYCLES_TEST                                "Build cycles test application" OFF)
+option(WITH_CYCLES_STANDALONE          "Build cycles standalone application" OFF)
+option(WITH_CYCLES_STANDALONE_GUI      "Build cycles standalone with GUI" OFF)
 option(WITH_CYCLES_OSL                         "Build Cycles with OSL support" OFF)
 option(WITH_CYCLES_CUDA_BINARIES       "Build cycles CUDA binaries" OFF)
-set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 CACHE STRING "CUDA architectures to build binaries for")
+set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 CACHE STRING "CUDA architectures to build binaries for")
 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
 unset(PLATFORM_DEFAULT)
 
 # LLVM
 option(WITH_LLVM                                       "Use LLVM" OFF)
+option(LLVM_STATIC                                     "Link with LLVM static libraries" ON)
+mark_as_advanced(LLVM_STATIC)
 
 # disable for now, but plan to support on all platforms eventually
 option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
 mark_as_advanced(WITH_MEM_JEMALLOC)
 
+# currently only used for BLI_mempool
+option(WITH_MEM_VALGRIND "Enable extended valgrind support for better reporting" OFF)
+mark_as_advanced(WITH_MEM_VALGRIND)
+
 # Debug
 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
@@ -281,6 +292,10 @@ mark_as_advanced(WITH_ASSERT_ABORT)
 
 option(WITH_BOOST                                      "Enable features depending no boost" ON)
 
+if(CMAKE_COMPILER_IS_GNUCC)
+       option(WITH_GCC_MUDFLAP                 "Enable mudflap" OFF)
+       mark_as_advanced(WITH_GCC_MUDFLAP)
+endif()
 
 if(APPLE)
        cmake_minimum_required(VERSION 2.8.8)
@@ -293,9 +308,11 @@ if(APPLE)
        endif()
        
        execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
-       if (${MAC_SYS} MATCHES 12)
+       if(${MAC_SYS} MATCHES 13)
+               set(OSX_SYSTEM 10.9)
+       elseif(${MAC_SYS} MATCHES 12)
                set(OSX_SYSTEM 10.8)
-       elseif (${MAC_SYS} MATCHES 11)
+       elseif(${MAC_SYS} MATCHES 11)
                set(OSX_SYSTEM 10.7)
        elseif(${MAC_SYS} MATCHES 10)
                set(OSX_SYSTEM 10.6)
@@ -305,9 +322,22 @@ if(APPLE)
                set(OSX_SYSTEM unsupported)
        endif()
        message(STATUS "Detected system-version: " ${OSX_SYSTEM})
-
+       
+       # workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not take xcode-select path into accout
+       # but would always look into /Applications/Xcode.app while dev versions are named Xcode<version>-DP<preview_number>
+       execute_process(COMMAND xcode-select --print-path  OUTPUT_VARIABLE XCODE_CHECK OUTPUT_STRIP_TRAILING_WHITESPACE)
+       string(REPLACE "/Contents/Developer" "" XCODE_BUNDLE ${XCODE_CHECK}) # truncate to bundlepath in any case
+       message(STATUS "Xcode-bundle : " ${XCODE_BUNDLE})
+       
        if(${CMAKE_GENERATOR} MATCHES "Xcode")
        
+               if(${XCODE_VERSION} VERSION_GREATER 4.2) # earlier xcode has no bundled developer dir, no sense in getting xcode path from
+                       string(SUBSTRING "${XCODE_CHECK}" 14 6 DP_NAME) # reduce to XCode name without dp extension
+                       if(${DP_NAME} MATCHES Xcode5)
+                               set(XCODE_VERSION 5)
+                       endif()
+               endif()
+
                ##### cmake incompatibility with xcode  4.3 and higher #####
                if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
                        message(FATAL_ERROR "Xcode 4.3 and higher must be used with cmake 2.8-8 or higher")
@@ -331,22 +361,23 @@ if(APPLE)
        if(${XCODE_VERSION} VERSION_LESS 4.3)
                set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)  # use guaranteed existing sdk
        else()
-               # note: i don't use xcode-select path on purpose, cause also /Applications/Xcode.app would be allowed
-               # absolute pathes are more foolproof here !
-               set(OSX_SYSROOT_PREFIX /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform)
+               # note: xcode-select path could be ambigous, cause /Applications/Xcode.app/Contents/Developer or /Applications/Xcode.app would be allowed
+               # so i use a selfcomposed bundlepath here  
+               set(OSX_SYSROOT_PREFIX ${XCODE_BUNDLE}/Contents/Developer/Platforms/MacOSX.platform)
+               message(STATUS "OSX_SYSROOT_PREFIX: " ${OSX_SYSROOT_PREFIX})
                set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
                set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
        endif()
        
        if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
-                       set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5" CACHE STRING "" FORCE) # 10.5 is our min. target, if you use higher sdk, weak linking happens
+               set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5" CACHE STRING "" FORCE) # 10.5 is our min. target, if you use higher sdk, weak linking happens
        endif()
        
        if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
                # force CMAKE_OSX_DEPLOYMENT_TARGET for makefiles, will not work else ( cmake bug ? )
                set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
                set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
-               add_definitions ("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
+               add_definitions("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
        endif()
 
        option(WITH_COCOA         "Use Cocoa framework instead of deprecated Carbon" ON)
@@ -361,7 +392,7 @@ endif()
 #-----------------------------------------------------------------------------
 # Check for conflicting/unsupported configurations
 
-if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_TEST)
+if(NOT WITH_BLENDER AND NOT WITH_PLAYER AND NOT WITH_CYCLES_STANDALONE)
        message(FATAL_ERROR "At least one of WITH_BLENDER or WITH_PLAYER must be enabled, nothing to do!")
 endif()
 
@@ -404,8 +435,12 @@ if(WITH_PYTHON_MODULE)
        set(WITH_HEADLESS ON)
 endif()
 
-# auto enable openimageio for cycles
-if(WITH_CYCLES)
+if(NOT WITH_PYTHON)
+       set(WITH_CYCLES OFF)
+endif()
+
+# auto enable openimageio for photoshop psd
+if(WITH_IMAGE_PSD)
        set(WITH_OPENIMAGEIO ON)
 endif()
 
@@ -413,20 +448,39 @@ endif()
 # otherwise if the user disabled
 if(NOT WITH_BOOST)
        # Explicitly disabled. so disable all deps.
-       set(WITH_CYCLES         OFF)
-       set(WITH_MOD_BOOLEAN    OFF)
-       set(WITH_AUDASPACE      OFF)
-       set(WITH_INTERNATIONAL  OFF)
-
-       set(WITH_OPENAL         OFF)  # depends on AUDASPACE
-       set(WITH_GAMEENGINE     OFF)  # depends on AUDASPACE
-elseif(WITH_CYCLES OR WITH_MOD_BOOLEAN OR WITH_AUDASPACE OR WITH_INTERNATIONAL)
+       macro(set_and_warn
+               _setting _val)
+               if(${${_setting}})
+                       message(STATUS "'WITH_BOOST' is disabled: forceing 'set(${_setting} ${_val})'")
+               endif()
+               set(${_setting} ${_val})
+       endmacro()
+
+       set_and_warn(WITH_CYCLES         OFF)
+       set_and_warn(WITH_MOD_BOOLEAN    OFF)
+       set_and_warn(WITH_AUDASPACE      OFF)
+       set_and_warn(WITH_INTERNATIONAL  OFF)
+
+       set_and_warn(WITH_OPENAL         OFF)  # depends on AUDASPACE
+       set_and_warn(WITH_GAMEENGINE     OFF)  # depends on AUDASPACE
+elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_MOD_BOOLEAN OR WITH_AUDASPACE OR WITH_INTERNATIONAL)
        # Keep enabled
 else()
        # Enabled but we don't need it
        set(WITH_BOOST OFF)
 endif()
 
+# auto enable openimageio for cycles
+if(WITH_CYCLES)
+       set(WITH_OPENIMAGEIO ON)
+endif()
+
+# auto enable openimageio linking dependencies
+if(WITH_OPENIMAGEIO)
+       set(WITH_IMAGE_OPENEXR ON)
+       set(WITH_IMAGE_TIFF ON)
+endif()
+
 # auto enable llvm for cycles_osl
 if(WITH_CYCLES_OSL)
        set(WITH_LLVM ON CACHE BOOL "ON" FORCE)
@@ -512,9 +566,6 @@ set(PLATFORM_LINKFLAGS "")
 set(PLATFORM_LINKFLAGS_DEBUG "")
 
 
-# disabled for now, not supported
-# option(WITH_WEBPLUGIN     "Enable Web Plugin (Unix only)" OFF)
-
 # For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
 # On Unix:
 #   cmake ../blender \
@@ -535,13 +586,13 @@ set(PLATFORM_LINKFLAGS_DEBUG "")
 
 if(UNIX AND NOT APPLE)
        macro(find_package_wrapper)
-               STRING(TOUPPER ${ARGV0} _NAME_UPPER)
-               if(${WITH_STATIC_LIBS})
+               string(TOUPPER ${ARGV0} _NAME_UPPER)
+               if(WITH_STATIC_LIBS)
                        set(_cmake_find_library_suffixes_back ${CMAKE_FIND_LIBRARY_SUFFIXES})
                        set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
                endif()
                find_package(${ARGV})
-               if(${WITH_STATIC_LIBS})
+               if(WITH_STATIC_LIBS)
                        set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
                        unset(_cmake_find_library_suffixes_back)
                endif()
@@ -665,7 +716,7 @@ if(UNIX AND NOT APPLE)
                endif()
        endif()
 
-       if (WITH_INPUT_NDOF)
+       if(WITH_INPUT_NDOF)
                find_package_wrapper(Spacenav)
                if(NOT SPACENAV_FOUND)
                        set(WITH_INPUT_NDOF OFF)
@@ -681,15 +732,16 @@ if(UNIX AND NOT APPLE)
        if(WITH_BOOST)
                # uses in build instructions to override include and library variables
                if(NOT BOOST_CUSTOM)
-                       if(${WITH_STATIC_LIBS})
+                       if(WITH_STATIC_LIBS)
                                set(Boost_USE_STATIC_LIBS ON)
                        endif()
                        set(Boost_USE_MULTITHREADED ON)
                        set(__boost_packages filesystem regex system thread date_time)
-                       if (WITH_INTERNATIONAL)
+                       if(WITH_INTERNATIONAL)
                                list(APPEND __boost_packages locale)
                        endif()
                        find_package(Boost 1.48 COMPONENTS ${__boost_packages})
+                       unset(__boost_packages)
                        if(Boost_USE_STATIC_LIBS AND WITH_BOOST_ICU)
                                find_package(IcuLinux)
                        endif()
@@ -707,7 +759,7 @@ if(UNIX AND NOT APPLE)
 
                set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
                set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
-               set(OPENIMAGEIO_DEFINITIONS)
+               set(OPENIMAGEIO_DEFINITIONS "")
 
                if(WITH_IMAGE_TIFF)
                        list(APPEND OPENIMAGEIO_LIBRARIES "${TIFF_LIBRARY}")
@@ -741,37 +793,50 @@ if(UNIX AND NOT APPLE)
                if(NOT LLVM_VERSION)
                        set(LLVM_VERSION "3.0")
                endif()
-               set(LLVM_STATIC YES)
+
                if(LLVM_DIRECTORY)
-                       FIND_PROGRAM(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
+                       find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
                        if(NOT LLVM_CONFIG)
-                               FIND_PROGRAM(LLVM_CONFIG llvm-config HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
+                               find_program(LLVM_CONFIG llvm-config HINTS ${LLVM_DIRECTORY}/bin NO_CMAKE_PATH)
                        endif()
                else()
-                       FIND_PROGRAM(LLVM_CONFIG llvm-config-${LLVM_VERSION})
+                       find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION})
                        if(NOT LLVM_CONFIG)
-                               FIND_PROGRAM(LLVM_CONFIG llvm-config)
+                               find_program(LLVM_CONFIG llvm-config)
                        endif()
                endif()
-               execute_process(COMMAND ${LLVM_CONFIG} --version
-                               OUTPUT_VARIABLE LLVM_VERSION
-                               OUTPUT_STRIP_TRAILING_WHITESPACE)
-               execute_process(COMMAND ${LLVM_CONFIG} --prefix
-                               OUTPUT_VARIABLE LLVM_DIRECTORY
-                               OUTPUT_STRIP_TRAILING_WHITESPACE)
-               execute_process(COMMAND ${LLVM_CONFIG} --libdir
-                               OUTPUT_VARIABLE LLVM_LIB_DIR
-                               OUTPUT_STRIP_TRAILING_WHITESPACE)
-               find_library(LLVM_LIBRARY
-                            NAMES LLVMAnalysis # first of a whole bunch of libs to get
-                            PATHS ${LLVM_LIB_DIR})
-               message(STATUS "LLVM version  = ${LLVM_VERSION}")
-               message(STATUS "LLVM dir      = ${LLVM_DIRECTORY}")
-               message(STATUS "LLVM lib dir  = ${LLVM_LIB_DIR}")
-               set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
-               set(LLVM_DIRECTORY ${LLVM_DIRECTORY} CACHE PATH "Path to the LLVM installation")
-
-               if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIB_DIR)
+
+               if(NOT DEFINED LLVM_VERSION)
+                       execute_process(COMMAND ${LLVM_CONFIG} --version
+                                                       OUTPUT_VARIABLE LLVM_VERSION
+                                                       OUTPUT_STRIP_TRAILING_WHITESPACE)
+                       set(LLVM_VERSION ${LLVM_VERSION} CACHE STRING "Version of LLVM to use")
+               endif()
+               if(NOT DEFINED LLVM_DIRECTORY)
+                       execute_process(COMMAND ${LLVM_CONFIG} --prefix
+                                                       OUTPUT_VARIABLE LLVM_DIRECTORY
+                                                       OUTPUT_STRIP_TRAILING_WHITESPACE)
+                       set(LLVM_DIRECTORY ${LLVM_DIRECTORY} CACHE PATH "Path to the LLVM installation")
+               endif()
+               if(NOT DEFINED LLVM_LIBPATH)
+                       execute_process(COMMAND ${LLVM_CONFIG} --libdir
+                                                       OUTPUT_VARIABLE LLVM_LIBPATH
+                                                       OUTPUT_STRIP_TRAILING_WHITESPACE)
+                       set(LLVM_LIBPATH ${LLVM_LIBPATH} CACHE PATH "Path to the LLVM library path")
+               endif()
+
+               if(LLVM_STATIC)
+                       find_library(LLVM_LIBRARY
+                                    NAMES LLVMAnalysis # first of a whole bunch of libs to get
+                                    PATHS ${LLVM_LIBPATH})
+               else()
+                       find_library(LLVM_LIBRARY
+                                    NAMES LLVM-${LLVM_VERSION}
+                                    PATHS ${LLVM_LIBPATH})
+               endif()
+
+
+               if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIBPATH)
                        if(LLVM_STATIC)
                                # if static LLVM libraries were requested, use llvm-config to generate
                                # the list of what libraries we need, and substitute that in the right
@@ -779,7 +844,7 @@ if(UNIX AND NOT APPLE)
                                execute_process(COMMAND ${LLVM_CONFIG} --libfiles
                                                OUTPUT_VARIABLE LLVM_LIBRARY
                                                OUTPUT_STRIP_TRAILING_WHITESPACE)
-                               string(REPLACE " " ";" LLVM_LIBRARY ${LLVM_LIBRARY})
+                               string(REPLACE " " ";" LLVM_LIBRARY "${LLVM_LIBRARY}")
                        endif()
                else()
                        message(FATAL_ERROR "LLVM not found.")
@@ -845,8 +910,6 @@ if(UNIX AND NOT APPLE)
 
        if(CMAKE_SYSTEM_NAME MATCHES "Linux")
                if(NOT WITH_PYTHON_MODULE)
-                       # BSD's dont use libdl.so
-               set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -ldl")
                        # binreloc is linux only
                        set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
                        set(WITH_BINRELOC ON)
@@ -897,28 +960,45 @@ elseif(WIN32)
        #  include(${CMAKE_ROOT}/Modules/Platform/Windows-cl.cmake)
 
        if(CMAKE_COMPILER_IS_GNUCC)
-               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
-               INCLUDE (CheckCSourceCompiles) 
+               include(CheckCSourceCompiles)
                # Setup 64bit and 64bit windows systems
                CHECK_C_SOURCE_COMPILES("
                        #ifndef __MINGW64__
                        #error
                        #endif
-                       main(){}
+                       int main(void) { return 0; }
                        " 
                        WITH_MINGW64)
                
                if(WITH_MINGW64)
-                       message("Compiling for 64 bit with MinGW-w64.")
+                       message(STATUS "Compiling for 64 bit with MinGW-w64.")
                        set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
+               else()
+                       message(STATUS "Compiling for 32 bit with MinGW-w32.")
+                       set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
+                       
+                       if(WITH_RAYOPTIMIZATION)
+                               message(WARNING "MinGW-w32 is known to be unstable with 'WITH_RAYOPTIMIZATION' option enabled.")
+                       endif()
                endif()
        else()
-               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
-
                # Setup 64bit and 64bit windows systems
                if(CMAKE_CL_64)
-                       message("64 bit compiler detected.")
-                       set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64)
+                       message(STATUS "64 bit compiler detected.")
+                       if(MSVC11)
+                               message(STATUS "Visual C++ 2012 detected.")
+                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64_vc11)
+                       else()
+                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64)
+                       endif()
+               else()
+               # Setup 32bit windows systems
+                       if(MSVC11)
+                               message(STATUS "Visual C++ 2012 detected.")
+                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows_vc11)
+                       else()
+                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows)
+                       endif()
                endif()
        endif()
                
@@ -933,7 +1013,11 @@ elseif(WIN32)
        if(WITH_OPENAL)
                set(OPENAL ${LIBDIR}/openal)
                set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
-               set(OPENAL_LIBRARY wrap_oal)
+               if(MSVC11)
+                       set(OPENAL_LIBRARY openal32)
+               else()
+                       set(OPENAL_LIBRARY wrap_oal)
+               endif()
                set(OPENAL_LIBPATH ${OPENAL}/lib)
        endif()
 
@@ -982,8 +1066,18 @@ elseif(WIN32)
        if(MSVC)
                set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid psapi)
 
+               # MSVC11 SDL is not hard linked to dxguid.lib
+               if(MSVC11 AND WITH_SDL)
+                       set(PLATFORM_LINKLIBS ${PLATFORM_LINKLIBS} dxguid)
+               endif()
+
                add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB)
 
+               # MSVC11 needs _ALLOW_KEYWORD_MACROS to build
+               if(MSVC11)
+                       add_definitions(/D_ALLOW_KEYWORD_MACROS)
+               endif()
+
                set(CMAKE_CXX_FLAGS "/nologo /J /Gd /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE)
                set(CMAKE_C_FLAGS   "/nologo /J /Gd"       CACHE STRING "MSVC MT C++ flags " FORCE)
 
@@ -1029,11 +1123,7 @@ elseif(WIN32)
                set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
 
                set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
-               if(CMAKE_CL_64)
-                       set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz.lib)
-               else()
-                       set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/zlib.lib)
-               endif()
+               set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz_st.lib)
 
                set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
                set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
@@ -1056,32 +1146,28 @@ elseif(WIN32)
                        set(OPENCOLLADA ${LIBDIR}/opencollada)
 
                        set(OPENCOLLADA_INCLUDE_DIRS
-                               ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
-                               ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
-                               ${LIBDIR}/opencollada/include/COLLADAFramework/include
-                               ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
-                               ${LIBDIR}/opencollada/include/GeneratedSaxParser/include
+                               ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
+                               ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
+                               ${OPENCOLLADA}/include/opencollada/COLLADAFramework
+                               ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
+                               ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
                        )
-                       set_lib_path(OPENCOLLADA_LIBPATH "opencollada")
 
                        set(OPENCOLLADA_LIBRARIES
-                               ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADASaxFrameworkLoader.lib
-                               ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADAFramework.lib
-                               ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADABaseUtils.lib
-                               ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADAStreamWriter.lib
-                               ${OPENCOLLADA_LIBPATH}/lib/MathMLSolver.lib
-                               ${OPENCOLLADA_LIBPATH}/lib/GeneratedSaxParser.lib
-                               ${OPENCOLLADA_LIBPATH}/lib/xml2.lib
-                               ${OPENCOLLADA_LIBPATH}/lib/buffer.lib
-                               ${OPENCOLLADA_LIBPATH}/lib/ftoa.lib
-                               ${OPENCOLLADA_LIBPATH}/lib/UTF.lib
+                               ${OPENCOLLADA}/lib/opencollada/OpenCOLLADASaxFrameworkLoader.lib
+                               ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAFramework.lib
+                               ${OPENCOLLADA}/lib/opencollada/OpenCOLLADABaseUtils.lib
+                               ${OPENCOLLADA}/lib/opencollada/OpenCOLLADAStreamWriter.lib
+                               ${OPENCOLLADA}/lib/opencollada/MathMLSolver.lib
+                               ${OPENCOLLADA}/lib/opencollada/GeneratedSaxParser.lib
+                               ${OPENCOLLADA}/lib/opencollada/xml.lib
+                               ${OPENCOLLADA}/lib/opencollada/buffer.lib
+                               ${OPENCOLLADA}/lib/opencollada/ftoa.lib
+                               ${OPENCOLLADA}/lib/opencollada/UTF.lib
                        )
                        set(PCRE_LIBRARIES
-                               ${OPENCOLLADA_LIBPATH}/lib/pcre.lib
+                               ${OPENCOLLADA}/lib/opencollada/pcre.lib
                        )
-                       
-                       unset(OPENCOLLADA_LIBPATH)
-                       
                endif()
 
                if(WITH_CODEC_FFMPEG)
@@ -1089,17 +1175,28 @@ elseif(WIN32)
                                ${LIBDIR}/ffmpeg/include
                                ${LIBDIR}/ffmpeg/include/msvc
                        )
-                       set(FFMPEG_LIBRARIES
-                               ${LIBDIR}/ffmpeg/lib/avcodec-53.lib
-                               ${LIBDIR}/ffmpeg/lib/avformat-53.lib
-                               ${LIBDIR}/ffmpeg/lib/avdevice-53.lib
-                               ${LIBDIR}/ffmpeg/lib/avutil-51.lib
-                               ${LIBDIR}/ffmpeg/lib/swscale-2.lib
-                       )
+                       # MSVC11 FFMPEG libs are newer
+                       if(MSVC11)
+                               set(FFMPEG_LIBRARIES
+                                       ${LIBDIR}/ffmpeg/lib/avcodec-54.lib
+                                       ${LIBDIR}/ffmpeg/lib/avformat-54.lib
+                                       ${LIBDIR}/ffmpeg/lib/avdevice-54.lib
+                                       ${LIBDIR}/ffmpeg/lib/avutil-52.lib
+                                       ${LIBDIR}/ffmpeg/lib/swscale-2.lib
+                               )
+                       else()
+                               set(FFMPEG_LIBRARIES
+                                       ${LIBDIR}/ffmpeg/lib/avcodec-53.lib
+                                       ${LIBDIR}/ffmpeg/lib/avformat-53.lib
+                                       ${LIBDIR}/ffmpeg/lib/avdevice-53.lib
+                                       ${LIBDIR}/ffmpeg/lib/avutil-51.lib
+                                       ${LIBDIR}/ffmpeg/lib/swscale-2.lib
+                               )
+                       endif()
                endif()
 
                if(WITH_IMAGE_OPENEXR)
-                       set_lib_path(OPENEXR "openexr")
+                       set(OPENEXR ${LIBDIR}/openexr)
                        set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
                        set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
                        set(OPENEXR_LIBPATH ${OPENEXR}/lib)
@@ -1126,21 +1223,14 @@ elseif(WIN32)
                endif()
 
                if(WITH_PYTHON)
-                       # normally cached but not since we include them with blender
-                       if(MSVC10)
-                               set(PYTHON_VERSION 3.3) # CACHE STRING)
-                       else()
-                               set(PYTHON_VERSION 3.3) # CACHE STRING)
-                       endif()
+                       set(PYTHON_VERSION 3.3) # CACHE STRING)
 
-                       set_lib_path(PYTHON "python")
-                       STRING(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
+                       string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
                        # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
                        set(PYTHON_LIBRARY ${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}.lib)
-                       # set(PYTHON_LIBRARY ${PYTHON}/lib/python${_PYTHON_VERSION_NO_DOTS}.lib) #CACHE FILEPATH
                        unset(_PYTHON_VERSION_NO_DOTS)
 
-                       #Shared includes for both vc2008 and vc2010
+                       # Shared includes for both vc2008 and vc2010
                        set(PYTHON_INCLUDE_DIR ${LIBDIR}/python/include/python${PYTHON_VERSION})
 
                        # uncached vars
@@ -1151,10 +1241,10 @@ elseif(WIN32)
                if(WITH_BOOST)
                        set(BOOST ${LIBDIR}/boost)
                        set(BOOST_INCLUDE_DIR ${BOOST}/include)
-                       if(MSVC10)
-                               set(BOOST_LIBPATH ${BOOST}/vc2010/lib)
-                               set(BOOST_POSTFIX "vc100-mt-s-1_49.lib")
-                               set(BOOST_DEBUG_POSTFIX "vc100-mt-sgd-1_49.lib")
+                       if(MSVC11)
+                               set(BOOST_LIBPATH ${BOOST}/lib)
+                               set(BOOST_POSTFIX "vc110-mt-s-1_53.lib")
+                               set(BOOST_DEBUG_POSTFIX "vc110-mt-sgd-1_53.lib")
                        else()
                                set(BOOST_LIBPATH ${BOOST}/lib)
                                set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
@@ -1191,7 +1281,6 @@ elseif(WIN32)
                if(WITH_LLVM)
                        set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
                        file(GLOB LLVM_LIBRARY ${LLVM_DIRECTORY}/lib/*.lib)
-                       set(LLVM_STATIC YES)
                endif()
        
                if(WITH_OPENCOLORIO)
@@ -1202,7 +1291,6 @@ elseif(WIN32)
                        set(OPENCOLORIO_DEFINITIONS)
                endif()
 
-
                set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
 
                # MSVC only, Mingw doesnt need
@@ -1223,15 +1311,11 @@ elseif(WIN32)
                set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
 
                if(WITH_MINGW64)
-                       #We need to take care though not to have these on debug builds because they may play funky with gdb
-                       if(CMAKE_BUILD_TYPE MATCHES "Release")
-                               set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -mmmx -ftree-vectorize")
-                       endif()
                        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
                        set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -lpthread")
                        
                        add_definitions(-DFREE_WINDOWS64 -DMS_WIN64)
-                       #Turn off OpenMP since it causes crashes on render for subsurfed/multiresolution meshes
+                       # Turn off OpenMP since it causes crashes on render for subsurfed/multiresolution meshes
                        set(WITH_OPENMP OFF)
                endif()
 
@@ -1255,7 +1339,7 @@ elseif(WIN32)
                set(ZLIB_LIBPATH ${ZLIB}/lib)
                set(ZLIB_LIBRARIES z)
 
-               #comes with own pthread library
+               # comes with own pthread library
                if(NOT WITH_MINGW64)
                        set(PTHREADS ${LIBDIR}/pthreads)
                        #set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
@@ -1278,18 +1362,14 @@ elseif(WIN32)
                if(WITH_OPENCOLLADA)
                        set(OPENCOLLADA ${LIBDIR}/opencollada)
                        set(OPENCOLLADA_INCLUDE_DIRS
-                               ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include
-                               ${LIBDIR}/opencollada/include/COLLADABaseUtils/include
-                               ${LIBDIR}/opencollada/include/COLLADAFramework/include
-                               ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include
-                               ${LIBDIR}/opencollada/include/GeneratedSaxParser/include
+                               ${OPENCOLLADA}/include/opencollada/COLLADAStreamWriter
+                               ${OPENCOLLADA}/include/opencollada/COLLADABaseUtils
+                               ${OPENCOLLADA}/include/opencollada/COLLADAFramework
+                               ${OPENCOLLADA}/include/opencollada/COLLADASaxFrameworkLoader
+                               ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
                        )
-                       set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
-                       if(WITH_MINGW64)
-                               set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre buffer ftoa xml)
-                       else()
-                               set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
-                       endif()
+                       set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib/opencollada)
+                       set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver buffer ftoa xml)
                        set(PCRE_LIBRARIES pcre)
                endif()
 
@@ -1376,13 +1456,13 @@ elseif(WIN32)
                        set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
                        set(OPENIMAGEIO_LIBRARIES OpenImageIO)
                        set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
-                       set(OPENIMAGEIO_DEFINITIONS)
+                       set(OPENIMAGEIO_DEFINITIONS "")
                endif()
                
                if(WITH_LLVM)
                        set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
-                       set(LLVM_LIB_DIR ${LLVM_DIRECTORY}/lib)
-                       #Explicitly set llvm lib order.
+                       set(LLVM_LIBPATH ${LLVM_DIRECTORY}/lib)
+                       # Explicitly set llvm lib order.
                        #---- WARNING ON GCC ORDER OF LIBS IS IMPORTANT, DO NOT CHANGE! ---------
                        set(LLVM_LIBRARY LLVMSelectionDAG LLVMCodeGen LLVMScalarOpts LLVMAnalysis LLVMArchive
                                LLVMAsmParser LLVMAsmPrinter
@@ -1402,9 +1482,8 @@ elseif(WIN32)
                                LLVMX86Disassembler LLVMX86Info
                                LLVMX86Utils LLVMipa
                                LLVMipo LLVMCore)
-                               #imagehelp is needed by LLVM 3.1 on MinGW, check lib\Support\Windows\Signals.inc
-                               set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -limagehlp")
-                       set(LLVM_STATIC YES)
+                       # imagehelp is needed by LLVM 3.1 on MinGW, check lib\Support\Windows\Signals.inc
+                       set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -limagehlp")
                endif()
                
                if(WITH_OPENCOLORIO)
@@ -1546,7 +1625,7 @@ elseif(APPLE)
                        set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
                        if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
                                set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
-                               #libSDL still needs 32bit carbon quicktime
+                               # libSDL still needs 32bit carbon quicktime
                        endif()
                elseif(WITH_CODEC_QUICKTIME)
                        set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QuickTime")
@@ -1571,7 +1650,7 @@ elseif(APPLE)
                endif()
 
        if(WITH_JACK)
-               set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -weak_framework jackmp")
+               set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework jackmp")
        endif()
 
        else()
@@ -1597,7 +1676,7 @@ elseif(APPLE)
 
                set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
                set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa")
-               #pcre is bundled with openCollada
+               # pcre is bundled with openCollada
                #set(PCRE ${LIBDIR}/pcre)
                #set(PCRE_LIBPATH ${PCRE}/lib)
                set(PCRE_LIBRARIES pcre)
@@ -1629,7 +1708,7 @@ elseif(APPLE)
                set(TIFF_LIBPATH ${TIFF}/lib)
        endif()
 
-       if (WITH_INPUT_NDOF)
+       if(WITH_INPUT_NDOF)
                # linker needs "-weak_framework 3DconnexionClient"
        endif()
 
@@ -1637,7 +1716,7 @@ elseif(APPLE)
                set(BOOST ${LIBDIR}/boost)
                set(BOOST_INCLUDE_DIR ${BOOST}/include)
                set(BOOST_LIBRARIES boost_date_time-mt boost_filesystem-mt boost_regex-mt boost_system-mt boost_thread-mt boost_wave-mt)
-               if (WITH_INTERNATIONAL)
+               if(WITH_INTERNATIONAL)
                        list(APPEND BOOST_LIBRARIES boost_locale-mt)
                        set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -liconv") # boost_locale needs it !
                endif()
@@ -1664,7 +1743,6 @@ elseif(APPLE)
        if(WITH_LLVM)
                set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
                set(LLVM_VERSION "3.1" CACHE STRING     "Version of LLVM to use")
-               set(LLVM_STATIC YES)
                if(EXISTS "${LLVM_DIRECTORY}/bin/llvm-config")
                        set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
                else()
@@ -1677,13 +1755,13 @@ elseif(APPLE)
                                OUTPUT_VARIABLE LLVM_DIRECTORY
                                OUTPUT_STRIP_TRAILING_WHITESPACE)
                execute_process(COMMAND ${LLVM_CONFIG} --libdir
-                               OUTPUT_VARIABLE LLVM_LIB_DIR
+                               OUTPUT_VARIABLE LLVM_LIBPATH
                                OUTPUT_STRIP_TRAILING_WHITESPACE)
                find_library(LLVM_LIBRARY
                             NAMES LLVMAnalysis # first of a whole bunch of libs to get
-                            PATHS ${LLVM_LIB_DIR})
+                            PATHS ${LLVM_LIBPATH})
 
-               if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIB_DIR)
+               if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIBPATH)
                        if(LLVM_STATIC)
                                # if static LLVM libraries were requested, use llvm-config to generate
                                # the list of what libraries we need, and substitute that in the right
@@ -1731,6 +1809,15 @@ elseif(APPLE)
                set(CMAKE_C_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
                set(CMAKE_CXX_FLAGS_RELEASE "-mdynamic-no-pic -fno-strict-aliasing")
        endif()
+
+       if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+               if(${CMAKE_GENERATOR} MATCHES "Xcode")
+                       if(${XCODE_VERSION} VERSION_EQUAL 5 OR ${XCODE_VERSION} VERSION_GREATER 5)
+                               # Xcode 5 has too low template depth of 128 for libmv
+                               set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
+                       endif()
+               endif()
+       endif()
 endif()
 
 #-----------------------------------------------------------------------------
@@ -1748,22 +1835,22 @@ endif()
 
 if(WITH_CYCLES)
        if(NOT WITH_OPENIMAGEIO)
-               message(FATAL_ERROR "Cycles reqires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
+               message(FATAL_ERROR "Cycles requires WITH_OPENIMAGEIO, the library may not have been found. Configure OIIO or disable WITH_CYCLES")
        endif()
        if(NOT WITH_BOOST)
-               message(FATAL_ERROR "Cycles reqires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
+               message(FATAL_ERROR "Cycles requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_CYCLES")
        endif()
 
        if(WITH_CYCLES_OSL)
                if(NOT WITH_LLVM)
-                       message(FATAL_ERROR "Cycles OSL reqires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
+                       message(FATAL_ERROR "Cycles OSL requires WITH_LLVM, the library may not have been found. Configure LLVM or disable WITH_CYCLES_OSL")
                endif()
        endif()
 endif()
 
 if(WITH_INTERNATIONAL)
        if(NOT WITH_BOOST)
-               message(FATAL_ERROR "Internationalization reqires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_INTERNATIONAL")
+               message(FATAL_ERROR "Internationalization requires WITH_BOOST, the library may not have been found. Configure BOOST or disable WITH_INTERNATIONAL")
        endif()
 endif()
 
@@ -1824,16 +1911,6 @@ if(WITH_IMAGE_REDCODE)
        set(REDCODE_INC ${REDCODE})
 endif()
 
-#-----------------------------------------------------------------------------
-# Blender WebPlugin
-
-if(WITH_WEBPLUGIN)
-       set(GECKO_DIR "${CMAKE_SOURCE_DIR}/../gecko-sdk/" CACHE PATH "Gecko SDK path")
-       set(WEBPLUGIN_SANDBOX_MODE "apparmor" CACHE STRING "WEB Plugin sandbox mode, can be apparmor, privsep, none")
-
-       set(WITH_PLAYER ON)
-endif()
-
 
 #-----------------------------------------------------------------------------
 # Configure OpenGL.
@@ -1927,12 +2004,19 @@ if(CMAKE_COMPILER_IS_GNUCC)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_NULL -Wnonnull)  # C only
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
+       ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_TYPE_LIMITS -Wtype-limits)
 
        # gcc 4.2 gives annoying warnings on every file with this
-       if (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
+       if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
                ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNINITIALIZED -Wuninitialized)
        endif()
 
+       # versions before gcc4.6 give many BLI_math warnings
+       if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.6")
+               ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_REDUNDANT_DECLS       -Wredundant-decls)
+               ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
+       endif()
+
        # disable because it gives warnings for printf() & friends.
        # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_DOUBLE_PROMOTION -Wdouble-promotion -Wno-error=double-promotion)
 
@@ -1947,9 +2031,10 @@ if(CMAKE_COMPILER_IS_GNUCC)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_INIT_SELF -Winit-self)  # needs -Wuninitialized
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_MISSING_INCLUDE_DIRS -Wmissing-include-dirs)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
+       ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
 
        # gcc 4.2 gives annoying warnings on every file with this
-       if (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
+       if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
                ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNINITIALIZED -Wuninitialized)
        endif()
 
@@ -1971,20 +2056,45 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
 
        # strange, clang complains these are not supported, but then yses them.
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
+       ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
+       ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
+       ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
-       ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
+       ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_PARAMETER -Wunused-parameter)
 
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ALL -Wall)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS     -Wno-unknown-pragmas)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS     -Wno-char-subscripts)
        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.
+       ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_SIGN_COMPARE        -Wno-sign-compare)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_INVALID_OFFSETOF    -Wno-invalid-offsetof)
-       ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
+
+       # gives too many unfixable warnings
+       # ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_UNUSED_MACROS      -Wunused-macros)
+       # ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_MACROS          -Wunused-macros)
+
+       # flags to undo strict flags
+       ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_PARAMETER -Wno-unused-parameter)
+       ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_MACROS    -Wno-unused-macros)
+
+       ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_VARIABLE_DECLARATIONS -Wno-missing-variable-declarations)
+       ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNUSED_FUNCTION -Wno-unused-function)
+       ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_INT_TO_VOID_POINTER_CAST -Wno-int-to-void-pointer-cast)
+       ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_PROTOTYPES -Wno-missing-prototypes)
+       ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_DUPLICATE_ENUM -Wno-duplicate-enum)
+       ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_UNDEF -Wno-undef)
+       ADD_CHECK_C_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS C_WARN_NO_MISSING_NORETURN -Wno-missing-noreturn)
+
+       ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_PRIVATE_FIELD -Wno-unused-private-field)
+       ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_CXX11_NARROWING -Wno-c++11-narrowing)
+       ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_NON_VIRTUAL_DTOR -Wno-non-virtual-dtor)
+       ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_UNUSED_MACROS -Wno-unused-macros)
+       ADD_CHECK_CXX_COMPILER_FLAG(CC_REMOVE_STRICT_FLAGS CXX_WARN_NO_REORDER -Wno-reorder)
 
 elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
 
@@ -2002,13 +2112,6 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
 
 endif()
 
-# MSVC2010 fails to links C++ libs right
-if(MSVC10)
-       if(WITH_OPENCOLLADA)
-               message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008")
-       endif()
-endif()
-
 # ensure python header is found since detection can fail, this could happen
 # with _any_ library but since we used a fixed python version this tends to
 # be most problematic.
@@ -2022,7 +2125,7 @@ if(WITH_PYTHON)
 
        if(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
                # set but invalid
-        # -- disabled until we make numpy bundled with blender - campbell
+               # -- disabled until we make numpy bundled with blender - campbell
                if((NOT ${PYTHON_NUMPY_PATH} STREQUAL "") AND (NOT ${PYTHON_NUMPY_PATH} MATCHES NOTFOUND))
 #                      if(NOT EXISTS "${PYTHON_NUMPY_PATH}/numpy")
 #                              message(WARNING "PYTHON_NUMPY_PATH is invalid, numpy not found in '${PYTHON_NUMPY_PATH}' "
@@ -2066,11 +2169,35 @@ if(WITH_PYTHON)
        endif()
 endif()
 
+if(WITH_GCC_MUDFLAP)
+       set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -fmudflapth -funwind-tables")
+       set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread -lmudflapth -rdynamic")
+       ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS     C_WARN_NO_ERROR_MUDFLAP   -Wno-error=mudflap)
+       ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_ERROR_MUDFLAP -Wno-error=mudflap)
+endif()
+
 # Include warnings first, so its possible to disable them with user defined flags
 # eg: -Wno-uninitialized
 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
 set(CMAKE_CXX_FLAGS "${CXX_WARNINGS} ${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS}")
 
+# defined above, platform spesific but shared names
+mark_as_advanced(
+       CYCLES_OSL
+       OSL_LIB_EXEC
+       OSL_COMPILER
+       OSL_LIB_COMP
+       OSL_LIB_QUERY
+       OSL_INCLUDES
+)
+
+mark_as_advanced(
+       LLVM_CONFIG
+       LLVM_DIRECTORY
+       LLVM_LIBRARY
+       LLVM_VERSION
+)
+
 #-------------------------------------------------------------------------------
 # Global Defines
 
@@ -2148,6 +2275,7 @@ if(FIRST_RUN)
        info_cfg_option(WITH_INTERNATIONAL)
        info_cfg_option(WITH_INPUT_NDOF)
        info_cfg_option(WITH_CYCLES)
+       info_cfg_option(WITH_FREESTYLE)
        info_cfg_option(WITH_OPENCOLORIO)
 
        info_cfg_text("Compiler Options:")
@@ -2160,6 +2288,7 @@ if(FIRST_RUN)
        info_cfg_option(WITH_X11_XF86VMODE)
        info_cfg_option(WITH_X11_XINPUT)
        info_cfg_option(WITH_MEM_JEMALLOC)
+       info_cfg_option(WITH_MEM_VALGRIND)
        info_cfg_option(WITH_SYSTEM_GLEW)
        info_cfg_option(WITH_SYSTEM_OPENJPEG)
 
@@ -2171,11 +2300,13 @@ if(FIRST_RUN)
        info_cfg_option(WITH_IMAGE_OPENJPEG)
        info_cfg_option(WITH_IMAGE_REDCODE)
        info_cfg_option(WITH_IMAGE_TIFF)
+       info_cfg_option(WITH_IMAGE_PSD)
 
        info_cfg_text("Audio:")
        info_cfg_option(WITH_OPENAL)
        info_cfg_option(WITH_SDL)
        info_cfg_option(WITH_JACK)
+       info_cfg_option(WITH_JACK_DYNLOAD)
        info_cfg_option(WITH_CODEC_AVI)
        info_cfg_option(WITH_CODEC_FFMPEG)
        info_cfg_option(WITH_CODEC_SNDFILE)