Fix T48554: Absolute grid snap fails w/ cursor pivot
[blender.git] / CMakeLists.txt
index 5654eb3289a73348f64131aac020063042d1288f..b558fe1482049f9e509876a30c44deef2f240e3a 100644 (file)
@@ -47,11 +47,6 @@ endif()
 
 cmake_minimum_required(VERSION 2.8)
 
-if(NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
-       # keep until CMake-3.0 is min requirement
-       cmake_policy(SET CMP0043 OLD)
-endif()
-
 if(NOT EXECUTABLE_OUTPUT_PATH)
        set(FIRST_RUN TRUE)
 else()
@@ -68,10 +63,21 @@ set(CMAKE_BUILD_TYPE_INIT "Release")
 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
 
 # global compile definitions since add_definitions() adds for all.
-set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
-set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
-set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
-set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
+
+if(NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
+       set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
+               $<$<CONFIG:Debug>:DEBUG;_DEBUG>
+               $<$<CONFIG:Release>:NDEBUG>
+               $<$<CONFIG:MinSizeRel>:NDEBUG>
+               $<$<CONFIG:RelWithDebInfo>:NDEBUG>
+       )
+else()
+       # keep until CMake-3.0 is min requirement
+       set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG           DEBUG _DEBUG)
+       set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE         NDEBUG)
+       set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_MINSIZEREL      NDEBUG)
+       set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELWITHDEBINFO  NDEBUG)
+endif()
 
 #-----------------------------------------------------------------------------
 # Set policy
@@ -149,37 +155,34 @@ option_defaults_init(
        _init_CODEC_FFMPEG
        _init_CYCLES_OSL
        _init_IMAGE_OPENEXR
-       _init_IMAGE_REDCODE
        _init_INPUT_NDOF
        _init_JACK
-       _init_LIBMV_SCHUR_SPECIALIZATION
        _init_OPENCOLLADA
        _init_OPENCOLORIO
        _init_SDL
        _init_FFTW3
        _init_GAMEENGINE
+       _init_OPENSUBDIV
 )
 
-# NOTE: for now use same defaults on all platforms...
-# in future we may want to tweak per-platform
-
 # customize...
-if (1)
+if(UNIX AND NOT APPLE)
        # some of these libraries are problematic on Linux
        # disable less important dependencies by default
-       set(_init_BUILDINFO                      OFF)
        set(_init_CODEC_FFMPEG                   OFF)
        set(_init_CYCLES_OSL                     OFF)
        set(_init_IMAGE_OPENEXR                  OFF)
-       set(_init_IMAGE_REDCODE                  OFF)
-       set(_init_INPUT_NDOF                     OFF)
        set(_init_JACK                           OFF)
-       set(_init_LIBMV_SCHUR_SPECIALIZATION     OFF)
        set(_init_OPENCOLLADA                    OFF)
        set(_init_OPENCOLORIO                    OFF)
        set(_init_SDL                            OFF)
        set(_init_FFTW3                          OFF)
-       set(_init_GAMEENGINE                     OFF)
+       set(_init_OPENSUBDIV                     OFF)
+elseif(WIN32)
+       set(_init_JACK                           OFF)
+elseif(APPLE)
+       set(_init_JACK                           OFF)
+       set(_init_OPENSUBDIV                     OFF)
 endif()
 
 
@@ -214,6 +217,10 @@ if(${CMAKE_VERSION} VERSION_LESS 2.8.8)
        # add_library OBJECT arg unsupported
        set(WITH_BUILDINFO OFF)
 endif()
+set(BUILDINFO_OVERRIDE_DATE "" CACHE STRING "Use instead of the current date for reproducable builds (empty string disables this option)")
+set(BUILDINFO_OVERRIDE_TIME "" CACHE STRING "Use instead of the current time for reproducable builds (empty string disables this option)")
+mark_as_advanced(BUILDINFO_OVERRIDE_DATE)
+mark_as_advanced(BUILDINFO_OVERRIDE_TIME)
 
 option(WITH_IK_ITASC      "Enable ITASC IK solver (only disable for development & for incompatible C++ compilers)" ON)
 option(WITH_IK_SOLVER     "Enable Legacy IK solver (only disable for development)" ON)
@@ -227,16 +234,17 @@ option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ${_init_OPENCOLO
 
 # Compositor
 option(WITH_COMPOSITOR         "Enable the tile based nodal compositor" ON)
-option(WITH_COMPOSITOR_WERROR  "Treat warnings as errors in compositor code" OFF)
-mark_as_advanced(WITH_COMPOSITOR_WERROR)
 
-option(WITH_OPENSUBDIV    "Enable OpenSubdiv for surface subdivision" OFF)
+option(WITH_OPENSUBDIV    "Enable OpenSubdiv for surface subdivision" _init_OPENSUBDIV)
+
+option(WITH_OPENVDB       "Enable features relying on OpenVDB" OFF)
+option(WITH_OPENVDB_BLOSC "Enable blosc compression for OpenVDB, only enable if OpenVDB was built with blosc support" OFF)
 
 # GHOST Windowing Library Options
 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
 mark_as_advanced(WITH_GHOST_DEBUG)
 
-option(WITH_GHOST_SDL    "Enable building blender against SDL for windowing rather then the native APIs" OFF)
+option(WITH_GHOST_SDL    "Enable building Blender against SDL for windowing rather than the native APIs" OFF)
 mark_as_advanced(WITH_GHOST_SDL)
 
 if(WITH_X11)
@@ -248,9 +256,19 @@ option(WITH_HEADLESS      "Build without graphical support (renderfarm, server m
 mark_as_advanced(WITH_HEADLESS)
 
 option(WITH_AUDASPACE    "Build with blenders audio library (only disable if you know what you're doing!)" ON)
+option(WITH_SYSTEM_AUDASPACE "Build with external audaspace library installed on the system (only enable if you know what you're doing!)" OFF)
 mark_as_advanced(WITH_AUDASPACE)
+mark_as_advanced(WITH_SYSTEM_AUDASPACE)
+
+if(NOT WITH_AUDASPACE)
+       set(WITH_SYSTEM_AUDASPACE OFF)
+endif()
 
 option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
+if(UNIX AND NOT APPLE)
+       option(WITH_OPENMP_STATIC "Link OpenMP statically (only used by the release environment)" OFF)
+       mark_as_advanced(WITH_OPENMP_STATIC)
+endif()
 
 if(WITH_X11)
        option(WITH_X11_XINPUT    "Enable X11 Xinput (tablet support and unicode input)"  ON)
@@ -292,7 +310,6 @@ option(WITH_IMAGE_TIFF          "Enable LibTIFF 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)
-option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" ${_init_IMAGE_REDCODE})
 option(WITH_IMAGE_FRAMESERVER   "Enable image FrameServer Support for rendering" ON)
 
 # Audio/Video format support
@@ -328,10 +345,8 @@ endif()
 
 # Camera/motion tracking
 option(WITH_LIBMV         "Enable Libmv structure from motion library" ON)
-option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." ${_init_LIBMV_SCHUR_SPECIALIZATION})
-option(WITH_LIBMV_WERROR  "Treat warnings as errors in Libmv (and Blender's motion tracking) code")
+option(WITH_LIBMV_SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." OFF)
 mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
-mark_as_advanced(WITH_LIBMV_WERROR)
 
 # Freestyle
 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
@@ -342,7 +357,6 @@ if(WIN32)
 endif()
 option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ${_init_INPUT_NDOF})
 option(WITH_RAYOPTIMIZATION    "Enable use of SIMD (SSE) optimizations for the raytracer" ON)
-option(WITH_OPENNL        "Enable use of Open Numerical Library" ON)
 if(UNIX AND NOT APPLE)
        option(WITH_INSTALL_PORTABLE "Install redistributeable runtime, otherwise install into CMAKE_INSTALL_PREFIX" ON)
        option(WITH_STATIC_LIBS "Try to link with static libraries, as much as possible, to make blender more portable across distributions" OFF)
@@ -351,34 +365,41 @@ if(UNIX AND NOT APPLE)
                mark_as_advanced(WITH_BOOST_ICU)
        endif()
 endif()
+
 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
-option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
-set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
-mark_as_advanced(PYTHON_NUMPY_PATH)
-option(WITH_CPU_SSE              "Enable SIMD instruction if they're detected on the host machine" ON)
-mark_as_advanced(WITH_CPU_SSE)
+if(WITH_PYTHON_INSTALL)
+       option(WITH_PYTHON_INSTALL_NUMPY "Copy system numpy into the blender install folder"  ON)
+       set(PYTHON_NUMPY_PATH            "" CACHE PATH "Path to python site-packages or dist-packages containing 'numpy' module")
+       mark_as_advanced(PYTHON_NUMPY_PATH)
 
-if(UNIX AND NOT APPLE)
-       option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
-       set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
-       mark_as_advanced(PYTHON_REQUESTS_PATH)
+       if(UNIX AND NOT APPLE)
+               option(WITH_PYTHON_INSTALL_REQUESTS "Copy system requests into the blender install folder" ON)
+               set(PYTHON_REQUESTS_PATH "" CACHE PATH "Path to python site-packages or dist-packages containing 'requests' module")
+               mark_as_advanced(PYTHON_REQUESTS_PATH)
+       endif()
 endif()
 
+option(WITH_CPU_SSE              "Enable SIMD instruction if they're detected on the host machine" ON)
+mark_as_advanced(WITH_CPU_SSE)
+
 # Cycles
 option(WITH_CYCLES                                     "Enable Cycles Render Engine" ON)
 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" ${_init_CYCLES_OSL})
 option(WITH_CYCLES_CUDA_BINARIES       "Build Cycles CUDA binaries" OFF)
-set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_50 sm_52 CACHE STRING "CUDA architectures to build binaries for")
+set(CYCLES_CUDA_BINARIES_ARCH sm_20 sm_21 sm_30 sm_35 sm_37 sm_50 sm_52 CACHE STRING "CUDA architectures to build binaries for")
 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
 unset(PLATFORM_DEFAULT)
 option(WITH_CYCLES_LOGGING     "Build Cycles with logging support" ON)
 option(WITH_CYCLES_DEBUG       "Build Cycles with extra debug capabilities" OFF)
-option(WITH_CYCLES_WERROR      "Treat warnings as errors in Cycles code" OFF)
+option(WITH_CYCLES_NATIVE_ONLY "Build Cycles with native kernel only (which fits current CPU, use for development only)" OFF)
 mark_as_advanced(WITH_CYCLES_LOGGING)
 mark_as_advanced(WITH_CYCLES_DEBUG)
-mark_as_advanced(WITH_CYCLES_WERROR)
+mark_as_advanced(WITH_CYCLES_NATIVE_ONLY)
+
+option(WITH_CUDA_DYNLOAD "Dynamically load CUDA libraries at runtime" ON)
+mark_as_advanced(WITH_CUDA_DYNLOAD)
 
 # LLVM
 option(WITH_LLVM                                       "Use LLVM" OFF)
@@ -450,14 +471,26 @@ if(WITH_GLEW_ES AND WITH_SYSTEM_GLEW)
        set(WITH_SYSTEM_GLEW OFF)
 endif()
 
-if(MSVC)
+if(WIN32)
        getDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
        set(CPACK_INSTALL_PREFIX ${CMAKE_GENERIC_PROGRAM_FILES}/${})
 endif()
 
-# Experimental support of C++11
-option(WITH_CPP11 "Build with C++11 standard enabled, for development use only!" OFF)
-mark_as_advanced(WITH_CPP11)
+# Experimental support of C11 and C++11
+#
+# We default options to whatever default standard in the current compiler.
+if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0") AND (NOT WITH_CXX11))
+       set(_c11_init ON)
+       set(_cxx11_init ON)
+else()
+       set(_c11_init OFF)
+       set(_cxx11_init OFF)
+endif()
+
+option(WITH_C11 "Build with C11 standard enabled, for development use only!" ${_c11_init})
+mark_as_advanced(WITH_C11)
+option(WITH_CXX11 "Build with C++11 standard enabled, for development use only!" ${_cxx11_init})
+mark_as_advanced(WITH_CXX11)
 
 # Dependency graph
 option(WITH_LEGACY_DEPSGRAPH "Build Blender with legacy dependency graph" ON)
@@ -473,7 +506,7 @@ option_defaults_clear()
 # By default we want to install to the directory we are compiling our executables
 # unless specified otherwise, which we currently do not allow
 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
-       if(MSVC)
+       if(WIN32)
                set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
        elseif(APPLE)
                set(CMAKE_INSTALL_PREFIX ${EXECUTABLE_OUTPUT_PATH}/\${BUILD_TYPE} CACHE PATH "default install path" FORCE)
@@ -489,47 +522,37 @@ endif()
 # Apple
 
 if(APPLE)
-       if(${CMAKE_VERSION} VERSION_LESS 3.0) # else breaks setting CMP0043 policy
-               cmake_minimum_required(VERSION 2.8.8)
-               cmake_policy(VERSION 2.8.8)
-       endif()
+       # require newer cmake on osx because of version handling,
+       # older cmake cannot handle 2 digit subversion!
+       cmake_minimum_required(VERSION 3.0.0)
 
        if(NOT CMAKE_OSX_ARCHITECTURES)
                set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
-               "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
-               FORCE)
+                       "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
+                       FORCE)
        endif()
-       
-       execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
-       if(${MAC_SYS} MATCHES 14)
-               set(OSX_SYSTEM 10.10)
-               # throw an error here, older cmake cannot handle 2 digit subversion!
-               cmake_minimum_required(VERSION 3.0.0)
-       elseif(${MAC_SYS} MATCHES 13)
-               set(OSX_SYSTEM 10.9)
-       elseif(${MAC_SYS} MATCHES 12)
-               set(OSX_SYSTEM 10.8)
-       elseif(${MAC_SYS} MATCHES 11)
-               set(OSX_SYSTEM 10.7)
-       elseif(${MAC_SYS} MATCHES 10)
-               set(OSX_SYSTEM 10.6)
-       elseif(${MAC_SYS} MATCHES 9)
-               set(OSX_SYSTEM 10.5)
-       else()
-               set(OSX_SYSTEM unsupported)
+
+       if(NOT DEFINED OSX_SYSTEM)
+               execute_process(
+                       COMMAND xcodebuild -version -sdk macosx SDKVersion
+                       OUTPUT_VARIABLE OSX_SYSTEM
+                       OUTPUT_STRIP_TRAILING_WHITESPACE)
        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)
+
+       # workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not
+       # take xcode-select path into account 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
+               # earlier xcode has no bundled developer dir, no sense in getting xcode path from
+               if(${XCODE_VERSION} VERSION_GREATER 4.2) 
+                       # reduce to XCode name without dp extension
+                       string(SUBSTRING "${XCODE_CHECK}" 14 6 DP_NAME) 
                        if(${DP_NAME} MATCHES Xcode5)
                                set(XCODE_VERSION 5)
                        endif()
@@ -552,29 +575,34 @@ if(APPLE)
                string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
                unset(XCODE_VERS_BUILD_NR)
        endif()
-       
-       message(STATUS "Detected Xcode-version: " ${XCODE_VERSION})
+
+       message(STATUS "Detected OS X ${OSX_SYSTEM} and Xcode ${XCODE_VERSION} at ${XCODE_BUNDLE}")
 
        if(${XCODE_VERSION} VERSION_LESS 4.3)
-               set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)  # use guaranteed existing sdk
+               # use guaranteed existing sdk
+               set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)
        else()
-               # note: xcode-select path could be ambigous, cause /Applications/Xcode.app/Contents/Developer or /Applications/Xcode.app would be allowed
+               # 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)
                if(${CMAKE_GENERATOR} MATCHES "Xcode")
-                       set(CMAKE_XCODE_ATTRIBUTE_SDKROOT macosx${OSX_SYSTEM}) # to silence sdk not found warning, just overrides CMAKE_OSX_SYSROOT
+                       # to silence sdk not found warning, just overrides CMAKE_OSX_SYSROOT
+                       set(CMAKE_XCODE_ATTRIBUTE_SDKROOT macosx${OSX_SYSTEM})
                endif()
        endif()
 
        if(OSX_SYSTEM MATCHES 10.9)
-               set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT}) # make sure syslibs and headers are looked up in sdk ( expecially for 10.9 openGL atm. )
+               # make sure syslibs and headers are looked up in sdk ( expecially for 10.9 openGL atm. )
+               set(CMAKE_FIND_ROOT_PATH ${CMAKE_OSX_SYSROOT})
        endif()
 
        if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
-               set(CMAKE_OSX_DEPLOYMENT_TARGET "10.6" CACHE STRING "" FORCE) # 10.6 is our min. target, if you use higher sdk, weak linking happens
+               # 10.6 is our min. target, if you use higher sdk, weak linking happens
+               set(CMAKE_OSX_DEPLOYMENT_TARGET "10.6" CACHE STRING "" FORCE)
        endif()
        
        if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
@@ -583,8 +611,6 @@ if(APPLE)
                set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
                add_definitions("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
        endif()
-
-       option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
 endif()
 
 
@@ -592,7 +618,10 @@ endif()
 # Check for conflicting/unsupported configurations
 
 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 or WITH_CYCLES_STANDALONE must be enabled, nothing to do!")
+       message(FATAL_ERROR
+               "At least one of WITH_BLENDER or WITH_PLAYER or "
+               "WITH_CYCLES_STANDALONE must be enabled, nothing to do!"
+       )
 endif()
 
 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
@@ -615,10 +644,6 @@ if(NOT WITH_SDL AND WITH_GHOST_SDL)
        message(FATAL_ERROR "WITH_GHOST_SDL requires WITH_SDL")
 endif()
 
-if(WITH_IMAGE_REDCODE AND ((NOT WITH_IMAGE_OPENJPEG) OR (NOT WITH_CODEC_FFMPEG)))
-       message(FATAL_ERROR "WITH_IMAGE_REDCODE requires WITH_IMAGE_OPENJPEG and WITH_CODEC_FFMPEG")
-endif()
-
 # python module, needs some different options
 if(WITH_PYTHON_MODULE AND WITH_PLAYER)
        message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PLAYER to be OFF")
@@ -653,14 +678,22 @@ if(NOT WITH_BOOST)
        set_and_warn(WITH_CYCLES         OFF)
        set_and_warn(WITH_AUDASPACE      OFF)
        set_and_warn(WITH_INTERNATIONAL  OFF)
+       set_and_warn(WITH_OPENVDB        OFF)
+       set_and_warn(WITH_OPENCOLORIO    OFF)
+       set_and_warn(WITH_MOD_BOOLEAN    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_AUDASPACE OR WITH_INTERNATIONAL)
+       set_and_warn(WITH_PLAYER         OFF)  # depends on GAMEENGINE
+elseif(WITH_CYCLES OR WITH_OPENIMAGEIO OR WITH_AUDASPACE OR WITH_INTERNATIONAL OR
+       WITH_OPENVDB OR WITH_OPENCOLORIO OR WITH_MOD_BOOLEAN)
        # Keep enabled
 else()
-       # Enabled but we don't need it
-       set(WITH_BOOST OFF)
+       # New dependency graph needs either Boost or C++11 for function bindings.
+       if(NOT USE_CXX11)
+               # Enabled but we don't need it
+               set(WITH_BOOST OFF)
+       endif()
 endif()
 
 # auto enable openimageio for cycles
@@ -702,9 +735,43 @@ else()
        set(COMPILER_SSE2_FLAG)
 endif()
 
-TEST_STDBOOL_SUPPORT()
-if(HAVE_STDBOOL_H)
-       add_definitions(-DHAVE_STDBOOL_H)
+if(WITH_BUILDINFO)
+       find_package(Git)
+       if(NOT GIT_FOUND)
+               message(WARNING "Git was not found, disabling WITH_BUILDINFO")
+               set(WITH_BUILDINFO OFF)
+       endif()
+endif()
+
+TEST_SHARED_PTR_SUPPORT()
+TEST_UNORDERED_MAP_SUPPORT()
+
+if(WITH_AUDASPACE)
+       if(WITH_SYSTEM_AUDASPACE)
+               set(AUDASPACE_DEFINITIONS
+                       -DWITH_AUDASPACE
+                       -DWITH_SYSTEM_AUDASPACE
+                       "-DAUD_DEVICE_H=<AUD_Device.h>"
+                       "-DAUD_SPECIAL_H=<AUD_Special.h>"
+                       "-DAUD_SOUND_H=<AUD_Sound.h>"
+                       "-DAUD_HANDLE_H=<AUD_Handle.h>"
+                       "-DAUD_SEQUENCE_H=<AUD_Sequence.h>"
+                       "-DAUD_TYPES_H=<AUD_Types.h>"
+                       "-DAUD_PYTHON_H=<python/PyAPI.h>"
+               )
+       else()
+               set(AUDASPACE_C_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/intern/audaspace/intern")
+               set(AUDASPACE_PY_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/intern/audaspace/intern")
+               set(AUDASPACE_DEFINITIONS
+                       -DWITH_AUDASPACE
+                       "-DAUD_DEVICE_H=<AUD_C-API.h>"
+                       "-DAUD_SPECIAL_H=<AUD_C-API.h>"
+                       "-DAUD_SOUND_H=<AUD_C-API.h>"
+                       "-DAUD_HANDLE_H=<AUD_C-API.h>"
+                       "-DAUD_SEQUENCE_H=<AUD_C-API.h>"
+                       "-DAUD_TYPES_H=<AUD_Space.h>"
+               )
+       endif()
 endif()
 
 #-----------------------------------------------------------------------------
@@ -716,18 +783,22 @@ endif()
 
 if(WITH_INTERNATIONAL)
        if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/datafiles/locale/languages")
-               message(WARNING "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
-                                               "This is a 'git submodule', which are known not to work with bridges to other version "
-                                               "control systems, disabling 'WITH_INTERNATIONAL'.")
+               message(WARNING
+                       "Translation path '${CMAKE_SOURCE_DIR}/release/datafiles/locale' is missing, "
+                       "This is a 'git submodule', which are known not to work with bridges to other version "
+                       "control systems, disabling 'WITH_INTERNATIONAL'."
+               )
                set(WITH_INTERNATIONAL OFF)
        endif()
 endif()
 
 if(WITH_PYTHON)
        if(NOT EXISTS "${CMAKE_SOURCE_DIR}/release/scripts/addons/modules")
-               message(WARNING "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
-                                               "This is a 'git submodule', which are known not to work with bridges to other version "
-                                               "control systems: * CONTINUING WITHOUT ADDONS *")
+               message(WARNING
+                       "Addons path '${CMAKE_SOURCE_DIR}/release/scripts/addons' is missing, "
+                       "This is a 'git submodule', which are known not to work with bridges to other version "
+                       "control systems: * CONTINUING WITHOUT ADDONS *"
+               )
        endif()
 endif()
 
@@ -761,21 +832,6 @@ set(PLATFORM_LINKFLAGS "")
 set(PLATFORM_LINKFLAGS_DEBUG "")
 
 
-# For alternate Python locations the commandline can be used to override detected/default cache settings, e.g:
-# On Unix:
-#   cmake ../blender \
-#         -D PYTHON_VERSION=3.4 \
-#         -D PYTHON_INCLUDE_DIR=/opt/py34/include/python3.4d \
-#         -D PYTHON_LIBRARY=/opt/py34/lib/libpython3.4d.so
-#
-# On Macs:
-#   cmake ../blender \
-#         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4 \
-#         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/config \
-#         -G Xcode
-#
-# When changing any of this remember to update the notes in doc/build_systems/cmake.txt
-
 #-----------------------------------------------------------------------------
 #Platform specifics
 
@@ -808,16 +864,20 @@ if(WITH_X11)
 
 endif()
 
+
+# ----------------------------------------------------------------------------
+# Main Platform Checks
+#
+# - UNIX
+# - WIN32
+# - APPLE
+
 if(UNIX AND NOT APPLE)
        macro(find_package_wrapper)
                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)
-                       set(CMAKE_FIND_LIBRARY_SUFFIXES ${_cmake_find_library_suffixes_back})
-                       unset(_cmake_find_library_suffixes_back)
+                       find_package_static(${ARGV})
+               else()
+                       find_package(${ARGV})
                endif()
        endmacro()
 
@@ -842,10 +902,10 @@ if(UNIX AND NOT APPLE)
        # else values are set below for all platforms
 
        if(WITH_PYTHON)
-               # No way to set py34. remove for now.
+               # No way to set py35, remove for now.
                # find_package(PythonLibs)
 
-               # Use our own instead, since wothout py is such a rare case,
+               # Use our own instead, since without py is such a rare case,
                # require this package
                # XXX Linking errors with debian static python :/
 #              find_package_wrapper(PythonLibsUnix REQUIRED)
@@ -876,6 +936,13 @@ if(UNIX AND NOT APPLE)
        endif()
 
        # Audio IO
+       if(WITH_SYSTEM_AUDASPACE)
+               find_package_wrapper(Audaspace)
+               if(NOT AUDASPACE_FOUND OR NOT AUDASPACE_C_FOUND)
+                       message(FATAL_ERROR "Audaspace external library not found!")
+               endif()
+       endif()
+
        if(WITH_OPENAL)
                find_package_wrapper(OpenAL)
                if(NOT OPENAL_FOUND)
@@ -966,14 +1033,12 @@ if(UNIX AND NOT APPLE)
 
        if(WITH_INPUT_NDOF)
                find_package_wrapper(Spacenav)
-               if(NOT SPACENAV_FOUND)
-                       set(WITH_INPUT_NDOF OFF)
-               endif()
-
-               # use generic names within blenders buildsystem.
                if(SPACENAV_FOUND)
+                       # use generic names within blenders buildsystem.
                        set(NDOF_INCLUDE_DIRS ${SPACENAV_INCLUDE_DIRS})
                        set(NDOF_LIBRARIES ${SPACENAV_LIBRARIES})
+               else()
+                       set(WITH_INPUT_NDOF OFF)
                endif()
        endif()
 
@@ -987,7 +1052,11 @@ if(UNIX AND NOT APPLE)
                        if(${OSL_LIBRARY_VERSION_MAJOR} EQUAL "1" AND ${OSL_LIBRARY_VERSION_MINOR} LESS "6")
                                # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
                                # otherwise LLVM is missing the osl_allocate_closure_component function
-                               set(OSL_LIBRARIES ${OSL_OSLCOMP_LIBRARY} -Wl,--whole-archive ${OSL_OSLEXEC_LIBRARY} -Wl,--no-whole-archive ${OSL_OSLQUERY_LIBRARY})
+                               set(OSL_LIBRARIES
+                                       ${OSL_OSLCOMP_LIBRARY}
+                                       -Wl,--whole-archive ${OSL_OSLEXEC_LIBRARY}
+                                       -Wl,--no-whole-archive ${OSL_OSLQUERY_LIBRARY}
+                               )
                        endif()
                else()
                        message(STATUS "OSL not found, disabling it from Cycles")
@@ -995,6 +1064,16 @@ if(UNIX AND NOT APPLE)
                endif()
        endif()
 
+       if(WITH_OPENVDB)
+               find_package_wrapper(OpenVDB)
+               find_package_wrapper(TBB)
+               if(NOT OPENVDB_FOUND OR NOT TBB_FOUND)
+                       set(WITH_OPENVDB OFF)
+                       set(WITH_OPENVDB_BLOSC OFF)
+                       message(STATUS "OpenVDB not found, disabling it")
+               endif()
+       endif()
+
        if(WITH_BOOST)
                # uses in build instructions to override include and library variables
                if(NOT BOOST_CUSTOM)
@@ -1015,6 +1094,9 @@ if(UNIX AND NOT APPLE)
                        if(WITH_CYCLES_NETWORK)
                                list(APPEND __boost_packages serialization)
                        endif()
+                       if(WITH_OPENVDB)
+                               list(APPEND __boost_packages iostreams)
+                       endif()
                        find_package(Boost 1.48 COMPONENTS ${__boost_packages})
                        if(NOT Boost_FOUND)
                                # try to find non-multithreaded if -mt not found, this flag
@@ -1045,7 +1127,13 @@ if(UNIX AND NOT APPLE)
                        set(PUGIXML_LIBRARIES "")
                endif()
 
-               set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
+               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 "")
 
@@ -1086,7 +1174,9 @@ if(UNIX AND NOT APPLE)
 
        if(WITH_LLVM OR WITH_SDL_DYNLOAD)
                # Fix for conflict with Mesa llvmpipe
-               set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Wl,--version-script='${CMAKE_SOURCE_DIR}/source/creator/blender.map'")
+               set(PLATFORM_LINKFLAGS
+                       "${PLATFORM_LINKFLAGS} -Wl,--version-script='${CMAKE_SOURCE_DIR}/source/creator/blender.map'"
+               )
        endif()
 
        if(WITH_OPENSUBDIV)
@@ -1097,7 +1187,7 @@ if(UNIX AND NOT APPLE)
 
                if(NOT OPENSUBDIV_FOUND)
                        set(WITH_OPENSUBDIV OFF)
-                       message(STATUS "OpenSundiv not found")
+                       message(STATUS "OpenSubdiv not found")
                endif()
        endif()
 
@@ -1128,12 +1218,6 @@ if(UNIX AND NOT APPLE)
        if(CMAKE_COMPILER_IS_GNUCC)
                set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
 
-               if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "5.0")
-                       # GCC5 uses gnu11, until we update, force c89
-                       # though some c11 features can still be used.
-                       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu89")
-               endif()
-
                # use ld.gold linker if available, could make optional
                execute_process(
                        COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version
@@ -1181,13 +1265,24 @@ elseif(WIN32)
        add_definitions(-DWIN32)
 
        if(MSVC)
+               # Minimum MSVC Version
+               set(_min_ver "18.0.31101")
+               if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${_min_ver})
+                       message(FATAL_ERROR
+                               "Visual Studio 2013 (Update 4, ${_min_ver}) required, "
+                               "found (${CMAKE_CXX_COMPILER_VERSION})")
+               endif()
+               unset(_min_ver)
 
                # needed for some MSVC installations
                set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
                set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
                set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO")
 
-               list(APPEND PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid psapi Dbghelp)
+               list(APPEND PLATFORM_LINKLIBS
+                       ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32
+                       advapi32 shfolder shell32 ole32 oleaut32 uuid psapi Dbghelp
+               )
 
                if(WITH_INPUT_IME)
                        list(APPEND PLATFORM_LINKLIBS imm32)
@@ -1213,28 +1308,24 @@ elseif(WIN32)
                set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
                include(InstallRequiredSystemLibraries)
 
-               set(CMAKE_CXX_FLAGS "/nologo /J /Gd /EHsc /MP" CACHE STRING "MSVC MT C++ flags " FORCE)
-               set(CMAKE_C_FLAGS   "/nologo /J /Gd /MP"       CACHE STRING "MSVC MT C++ flags " FORCE)
+               set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /nologo /J /Gd /MP /EHsc")
+               set(CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} /nologo /J /Gd /MP")
 
-               if(CMAKE_CL_64)
-                       set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
-               else()
-                       set(CMAKE_CXX_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
-               endif()
-               set(CMAKE_CXX_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
-               set(CMAKE_CXX_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
-               set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
-               if(CMAKE_CL_64)
-                       set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
-               else()
-                       set(CMAKE_C_FLAGS_DEBUG "/Od /RTC1 /MTd /ZI /MP" CACHE STRING "MSVC MT flags " FORCE)
-               endif()
-               set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
-               set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Ob1 /MT /MP" CACHE STRING "MSVC MT flags " FORCE)
-               set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Ob1 /MT /Zi /MP" CACHE STRING "MSVC MT flags " FORCE)
+               set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
+               set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
+               set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
+               set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
+               set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
+               set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /MT")
+               set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MT")
+               set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /MT")
 
+               set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO ")
+               set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib ")
 
-               set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
+               # Ignore meaningless for us linker warnings.
+               set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /ignore:4049 /ignore:4217 /ignore:4221")
+               set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
 
                # MSVC only, Mingw doesnt need
                if(CMAKE_CL_64)
@@ -1245,25 +1336,48 @@ elseif(WIN32)
 
                set(PLATFORM_LINKFLAGS_DEBUG "/IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
 
+               # Use dynamic loading for OpenMP
+               if(WITH_OPENMP)
+                       if(MSVC_VERSION EQUAL 1800)
+                               set(OPENMP_DLL_NAME "vcomp120")
+                       else()
+                               set(OPENMP_DLL_NAME "vcomp140")
+                       endif()
+                       set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /DELAYLOAD:${OPENMP_DLL_NAME}.dll delayimp.lib")
+                       set(PLATFORM_LINKFLAGS_DEBUG "${PLATFORM_LINKFLAGS_DEBUG} /DELAYLOAD:${OPENMP_DLL_NAME}d.dll delayimp.lib")
+               endif()
+
                if(NOT DEFINED LIBDIR)
+
                        # Setup 64bit and 64bit windows systems
                        if(CMAKE_CL_64)
                                message(STATUS "64 bit compiler detected.")
-                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/win64_vc12)
+                               set(LIBDIR_BASE "win64")
                        else()
                                message(STATUS "32 bit compiler detected.")
-                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/windows_vc12)
+                               set(LIBDIR_BASE "windows")
+                       endif()
+
+                       if(MSVC_VERSION EQUAL 1900)
+                               message(STATUS "Visual Studio 2015 detected.")
+                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc14)
+                       else()
+                               message(STATUS "Visual Studio 2013 detected.")
+                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc12)
                        endif()
                else()
-                       message(STATUS using LIBDIR  ${LIBDIR})
+                       message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
+               endif()
+               if(NOT EXISTS "${LIBDIR}/")
+                       message(FATAL_ERROR "Windows requires pre-compiled libs at: '${LIBDIR}'")
                endif()
 
                # Add each of our libraries to our cmake_prefix_path so find_package() could work
                file(GLOB children RELATIVE ${LIBDIR} ${LIBDIR}/*)
                foreach(child ${children})
-               if(IS_DIRECTORY ${LIBDIR}/${child})
-                       list(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
-               endif()
+                       if(IS_DIRECTORY ${LIBDIR}/${child})
+                               list(APPEND CMAKE_PREFIX_PATH  ${LIBDIR}/${child})
+                       endif()
                endforeach()
 
                set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
@@ -1284,9 +1398,7 @@ elseif(WIN32)
                        set(PNG_LIBPATH ${PNG}/lib) # not cmake defined
                endif()
 
-               if(MSVC)
-                       set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
-               endif()
+               set(JPEG_NAMES ${JPEG_NAMES} libjpeg)
                find_package(jpeg REQUIRED)
 
                set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
@@ -1367,26 +1479,31 @@ elseif(WIN32)
                                message(WARNING "Using HARDCODED OpenEXR locations")
                                set(OPENEXR ${LIBDIR}/openexr)
                                set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
-                               set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
+                               set(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR}/include/OpenEXR)
                                set(OPENEXR_LIBPATH ${OPENEXR}/lib)
                                set(OPENEXR_LIBRARIES
-                                       ${OPENEXR_LIBPATH}/Iex-2_2.lib
-                                       ${OPENEXR_LIBPATH}/Half.lib
-                                       ${OPENEXR_LIBPATH}/IlmImf-2_2.lib
-                                       ${OPENEXR_LIBPATH}/Imath-2_2.lib
-                                       ${OPENEXR_LIBPATH}/IlmThread-2_2.lib
+                                       optimized ${OPENEXR_LIBPATH}/Iex-2_2.lib
+                                       optimized ${OPENEXR_LIBPATH}/Half.lib
+                                       optimized ${OPENEXR_LIBPATH}/IlmImf-2_2.lib
+                                       optimized ${OPENEXR_LIBPATH}/Imath-2_2.lib
+                                       optimized ${OPENEXR_LIBPATH}/IlmThread-2_2.lib
+                                       debug ${OPENEXR_LIBPATH}/Iex-2_2_d.lib
+                                       debug ${OPENEXR_LIBPATH}/Half_d.lib
+                                       debug ${OPENEXR_LIBPATH}/IlmImf-2_2_d.lib
+                                       debug ${OPENEXR_LIBPATH}/Imath-2_2_d.lib
+                                       debug ${OPENEXR_LIBPATH}/IlmThread-2_2_d.lib
                                )
                        endif()
                endif()
 
                if(WITH_IMAGE_TIFF)
-               # Try to find tiff first then complain and set static and maybe wrong paths
-               find_package(TIFF)
-               if(NOT TIFF_FOUND)
-                       message(WARNING "Using HARDCODED libtiff locations")
-                       set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
-                       set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
-               endif()
+                       # Try to find tiff first then complain and set static and maybe wrong paths
+                       find_package(TIFF)
+                       if(NOT TIFF_FOUND)
+                               message(WARNING "Using HARDCODED libtiff locations")
+                               set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
+                               set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
+                       endif()
                endif()
 
                if(WITH_JACK)
@@ -1398,7 +1515,7 @@ elseif(WIN32)
                endif()
 
                if(WITH_PYTHON)
-                       set(PYTHON_VERSION 3.4) # CACHE STRING)
+                       set(PYTHON_VERSION 3.5) # CACHE STRING)
 
                        string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
                        # Use shared libs for vc2008 and vc2010 until we actually have vc2010 libs
@@ -1420,6 +1537,9 @@ elseif(WIN32)
                        if(WITH_INTERNATIONAL)
                                list(APPEND boost_extra_libs locale)
                        endif()
+                       if(WITH_OPENVDB)
+                               list(APPEND boost_extra_libs iostreams)
+                       endif()
                        set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
                        set(Boost_USE_MULTITHREADED ON) # suffix -mt
                        set(Boost_USE_STATIC_LIBS ON) # suffix -s
@@ -1430,20 +1550,25 @@ elseif(WIN32)
                                set(BOOST_INCLUDE_DIR ${BOOST}/include)
                                if(MSVC12)
                                        set(BOOST_LIBPATH ${BOOST}/lib)
-                                       set(BOOST_POSTFIX "vc120-mt-s-1_55.lib")
-                                       set(BOOST_DEBUG_POSTFIX "vc120-mt-sgd-1_55.lib")
+                                       set(BOOST_POSTFIX "vc120-mt-s-1_60.lib")
+                                       set(BOOST_DEBUG_POSTFIX "vc120-mt-sgd-1_60.lib")
                                else()
                                        set(BOOST_LIBPATH ${BOOST}/lib)
-                                       set(BOOST_POSTFIX "vc90-mt-s-1_49.lib")
-                                       set(BOOST_DEBUG_POSTFIX "vc90-mt-sgd-1_49.lib")
+                                       set(BOOST_POSTFIX "vc140-mt-s-1_60.lib")
+                                       set(BOOST_DEBUG_POSTFIX "vc140-mt-sgd-1_60.lib")
                                endif()
                                set(BOOST_LIBRARIES
-                                       optimized libboost_date_time-${BOOST_POSTFIX} optimized libboost_filesystem-${BOOST_POSTFIX}
+                                       optimized libboost_date_time-${BOOST_POSTFIX}
+                                       optimized libboost_filesystem-${BOOST_POSTFIX}
                                        optimized libboost_regex-${BOOST_POSTFIX}
-                                       optimized libboost_system-${BOOST_POSTFIX} optimized libboost_thread-${BOOST_POSTFIX}
-                                       debug libboost_date_time-${BOOST_DEBUG_POSTFIX} debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
+                                       optimized libboost_system-${BOOST_POSTFIX}
+                                       optimized libboost_thread-${BOOST_POSTFIX}
+                                       debug libboost_date_time-${BOOST_DEBUG_POSTFIX}
+                                       debug libboost_filesystem-${BOOST_DEBUG_POSTFIX}
                                        debug libboost_regex-${BOOST_DEBUG_POSTFIX}
-                                       debug libboost_system-${BOOST_DEBUG_POSTFIX} debug libboost_thread-${BOOST_DEBUG_POSTFIX})
+                                       debug libboost_system-${BOOST_DEBUG_POSTFIX}
+                                       debug libboost_thread-${BOOST_DEBUG_POSTFIX}
+                               )
                                if(WITH_CYCLES_OSL)
                                        set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
                                                optimized libboost_wave-${BOOST_POSTFIX}
@@ -1508,7 +1633,16 @@ elseif(WIN32)
                        set(OPENCOLORIO_LIBPATH ${LIBDIR}/opencolorio/lib)
                        set(OPENCOLORIO_DEFINITIONS)
                endif()
-               
+
+               if(WITH_OPENVDB)
+                       set(BLOSC_LIBRARIES optimized ${LIBDIR}/blosc/lib/libblosc.lib debug ${LIBDIR}/blosc/lib/libblosc_d.lib)
+                       set(TBB_LIBRARIES optimized ${LIBDIR}/tbb/lib/tbb.lib debug ${LIBDIR}/tbb/lib/tbb_debug.lib)
+                       set(TBB_INCLUDE_DIR ${LIBDIR}/tbb/include)
+                       set(OPENVDB ${LIBDIR}/openvdb)
+                       set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include ${TBB_INCLUDE_DIR})
+                       set(OPENVDB_LIBRARIES optimized openvdb debug openvdb_d ${TBB_LIBRARIES} ${BLOSC_LIBRARIES})
+                       set(OPENVDB_LIBPATH ${LIBDIR}/openvdb/lib)
+               endif()
 
                if(WITH_MOD_CLOTH_ELTOPO)
                        set(LAPACK ${LIBDIR}/lapack)
@@ -1531,8 +1665,23 @@ elseif(WIN32)
                if(WITH_SDL)
                        set(SDL ${LIBDIR}/sdl)
                        set(SDL_INCLUDE_DIR ${SDL}/include)
-                       set(SDL_LIBRARY SDL2)
                        set(SDL_LIBPATH ${SDL}/lib)
+                       # MinGW TODO: Update MinGW to SDL2
+                       if(NOT CMAKE_COMPILER_IS_GNUCC)
+                               set(SDL_LIBRARY SDL2)
+                       else()
+                               set(SDL_LIBRARY SDL)
+                       endif()
+               endif()
+
+               # Audio IO
+               if(WITH_SYSTEM_AUDASPACE)
+                       set(AUDASPACE_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
+                       set(AUDASPACE_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace.lib)
+                       set(AUDASPACE_C_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
+                       set(AUDASPACE_C_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-c.lib)
+                       set(AUDASPACE_PY_INCLUDE_DIRS ${LIBDIR}/audaspace/include/audaspace)
+                       set(AUDASPACE_PY_LIBRARIES ${LIBDIR}/audaspace/lib/audaspace-py.lib)
                endif()
 
                # used in many places so include globally, like OpenGL
@@ -1548,26 +1697,32 @@ elseif(WIN32)
                        #endif
                        int main(void) { return 0; }
                        " 
-                       WITH_MINGW64)
+                       WITH_MINGW64
+               )
                
-               if(WITH_MINGW64)
-                       message(STATUS "Compiling for 64 bit with MinGW-w64.")
-                       execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
-                       if(GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
-                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64_gcc49)
-                       else()
+               if(NOT DEFINED LIBDIR)
+                       if(WITH_MINGW64)
+                               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()
-                       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()
+                       message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
                endif()
-               
-               list(APPEND PLATFORM_LINKLIBS -lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi -ldbghelp)
+               if(NOT EXISTS "${LIBDIR}/")
+                       message(FATAL_ERROR "Windows requires pre-compiled libs at: '${LIBDIR}'")
+               endif()
+
+               list(APPEND PLATFORM_LINKLIBS
+                       -lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32
+                       -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi -ldbghelp
+               )
 
                if(WITH_INPUT_IME)
                        list(APPEND PLATFORM_LINKLIBS -limm32)
@@ -1636,7 +1791,14 @@ elseif(WIN32)
                                ${OPENCOLLADA}/include/opencollada/GeneratedSaxParser
                        )
                        set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib/opencollada)
-                       set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver buffer ftoa xml)
+                       set(OPENCOLLADA_LIBRARIES
+                               OpenCOLLADAStreamWriter
+                               OpenCOLLADASaxFrameworkLoader
+                               OpenCOLLADAFramework
+                               OpenCOLLADABaseUtils
+                               GeneratedSaxParser
+                               UTF MathMLSolver buffer ftoa xml
+                       )
                        set(PCRE_LIBRARIES pcre)
                endif()
 
@@ -1678,7 +1840,7 @@ elseif(WIN32)
 
                if(WITH_PYTHON)
                        # normally cached but not since we include them with blender
-                       set(PYTHON_VERSION 3.4) #  CACHE STRING)
+                       set(PYTHON_VERSION 3.5) #  CACHE STRING)
                        string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
                        set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")  # CACHE PATH)
                        set(PYTHON_LIBRARY "${LIBDIR}/python/lib/python${_PYTHON_VERSION_NO_DOTS}mw.lib")  # CACHE FILEPATH)
@@ -1709,12 +1871,14 @@ elseif(WIN32)
                        if(WITH_INTERNATIONAL)
                                set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
                                        optimized boost_locale-${BOOST_POSTFIX}
-                                       debug boost_locale-${BOOST_DEBUG_POSTFIX}) 
+                                       debug boost_locale-${BOOST_DEBUG_POSTFIX}
+                               )
                        endif()
                        if(WITH_CYCLES_OSL)
                                set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
                                        optimized boost_wave-${BOOST_POSTFIX}
-                                       debug boost_wave-${BOOST_DEBUG_POSTFIX}) 
+                                       debug boost_wave-${BOOST_DEBUG_POSTFIX}
+                               )
                        endif()
                        set(BOOST_LIBPATH ${BOOST}/lib)
                        set(BOOST_DEFINITIONS "-DBOOST_ALL_NO_LIB -DBOOST_THREAD_USE_LIB ")
@@ -1771,6 +1935,14 @@ elseif(WIN32)
                        set(SDL_LIBPATH ${SDL}/lib)
                endif()
 
+               if(WITH_OPENVDB)
+                       set(OPENVDB ${LIBDIR}/openvdb)
+                       set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include)
+                       set(OPENVDB_LIBRARIES openvdb ${TBB_LIBRARIES})
+                       set(OPENVDB_LIBPATH ${LIBDIR}/openvdb/lib)
+                       set(OPENVDB_DEFINITIONS)
+               endif()
+
                set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
 
                ## DISABLE - causes linking errors 
@@ -1787,7 +1959,7 @@ elseif(WIN32)
                set(OPENAL ${LIBDIR}/openal)
                set(OPENALDIR ${LIBDIR}/openal)
                set(OPENAL_INCLUDE_DIR ${OPENAL}/include)
-               if(MSVC12)
+               if(MSVC)
                        set(OPENAL_LIBRARY openal32)
                else()
                        set(OPENAL_LIBRARY wrap_oal)
@@ -1815,7 +1987,14 @@ elseif(WIN32)
                find_library(OSL_LIB_EXEC_DEBUG NAMES oslexec_d PATHS ${CYCLES_OSL}/lib)
                find_library(OSL_LIB_COMP_DEBUG NAMES oslcomp_d PATHS ${CYCLES_OSL}/lib)
                find_library(OSL_LIB_QUERY_DEBUG NAMES oslquery_d PATHS ${CYCLES_OSL}/lib)
-               list(APPEND OSL_LIBRARIES optimized ${OSL_LIB_COMP} optimized ${OSL_LIB_EXEC} optimized ${OSL_LIB_QUERY} debug ${OSL_LIB_EXEC_DEBUG} debug ${OSL_LIB_COMP_DEBUG} debug ${OSL_LIB_QUERY_DEBUG})
+               list(APPEND OSL_LIBRARIES
+                       optimized ${OSL_LIB_COMP}
+                       optimized ${OSL_LIB_EXEC}
+                       optimized ${OSL_LIB_QUERY}
+                       debug ${OSL_LIB_EXEC_DEBUG}
+                       debug ${OSL_LIB_COMP_DEBUG}
+                       debug ${OSL_LIB_QUERY_DEBUG}
+               )
                find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
                find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
        
@@ -1829,20 +2008,14 @@ elseif(WIN32)
 
 elseif(APPLE)
 
-       if(${CMAKE_OSX_DEPLOYMENT_TARGET} STREQUAL "10.5" OR ${CMAKE_OSX_DEPLOYMENT_TARGET} STRGREATER "10.5")
-               set(WITH_LIBS10.5 ON CACHE BOOL "Use 10.5 libs" FORCE) # valid also for 10.6/7/8/9
-       endif()
-
-       if(WITH_LIBS10.5)
+       if(NOT DEFINED LIBDIR)
                set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-9.x.universal)
        else()
-               if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
-                       set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.x.i386)
-               else()
-                       set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/darwin-8.0.0-powerpc)
-               endif()
+               message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
+       endif()
+       if(NOT EXISTS "${LIBDIR}/")
+               message(FATAL_ERROR "Mac OSX requires pre-compiled libs at: '${LIBDIR}'")
        endif()
-
 
        if(WITH_OPENAL)
                find_package(OpenAL)
@@ -1883,27 +2056,35 @@ elseif(APPLE)
        endif()
 
        if(WITH_PYTHON)
-               # we use precompiled libraries for py 3.4 and up by default
-               set(PYTHON_VERSION 3.4)
+               # we use precompiled libraries for py 3.5 and up by default
+               set(PYTHON_VERSION 3.5)
                if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
                        # normally cached but not since we include them with blender
                        set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}m")
-                       # set(PYTHON_EXECUTABLE "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
+                       set(PYTHON_EXECUTABLE "${LIBDIR}/python/bin/python${PYTHON_VERSION}m")
                        set(PYTHON_LIBRARY python${PYTHON_VERSION}m)
                        set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
                        # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
                else()
                        # module must be compiled against Python framework
-                       set(PYTHON_INCLUDE_DIR "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/include/python${PYTHON_VERSION}m")
-                       set(PYTHON_EXECUTABLE "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
+                       set(_py_framework "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}")
+
+                       set(PYTHON_INCLUDE_DIR "${_py_framework}/include/python${PYTHON_VERSION}m")
+                       set(PYTHON_EXECUTABLE "${_py_framework}/bin/python${PYTHON_VERSION}m")
+                       set(PYTHON_LIBPATH "${_py_framework}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
                        #set(PYTHON_LIBRARY python${PYTHON_VERSION})
-                       set(PYTHON_LIBPATH "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config-${PYTHON_VERSION}m")
                        #set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework Python")  # won't  build with this enabled
+
+                       unset(_py_framework)
                endif()
                
                # uncached vars
                set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
                set(PYTHON_LIBRARIES  "${PYTHON_LIBRARY}")
+
+               if(NOT EXISTS "${PYTHON_EXECUTABLE}")
+                       message(FATAL_ERROR "Python executable missing: ${PYTHON_EXECUTABLE}")
+               endif()
        endif()
 
        if(WITH_FFTW3)
@@ -1928,7 +2109,7 @@ elseif(APPLE)
        if(WITH_IMAGE_OPENEXR)
                set(OPENEXR ${LIBDIR}/openexr)
                set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
-               set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
+               set(OPENEXR_INCLUDE_DIRS ${OPENEXR_INCLUDE_DIR} ${OPENEXR}/include/OpenEXR)
                set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
                set(OPENEXR_LIBPATH ${OPENEXR}/lib)
        endif()
@@ -1936,7 +2117,10 @@ elseif(APPLE)
        if(WITH_CODEC_FFMPEG)
                set(FFMPEG ${LIBDIR}/ffmpeg)
                set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
-               set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
+               set(FFMPEG_LIBRARIES
+                       avcodec avdevice avformat avutil
+                       mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg
+               )
                set(FFMPEG_LIBPATH ${FFMPEG}/lib)
        endif()
 
@@ -1947,13 +2131,13 @@ elseif(APPLE)
        )
        mark_as_advanced(SYSTEMSTUBS_LIBRARY)
        if(SYSTEMSTUBS_LIBRARY)
-               list(APPEND PLATFORM_LINKLIBS stdc++ SystemStubs)
-       else()
-               list(APPEND PLATFORM_LINKLIBS stdc++)
+               list(APPEND PLATFORM_LINKLIBS SystemStubs)
        endif()
 
        set(PLATFORM_CFLAGS "-pipe -funsigned-char")
-       set(PLATFORM_LINKFLAGS "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio")
+       set(PLATFORM_LINKFLAGS
+               "-fexceptions -framework CoreServices -framework Foundation -framework IOKit -framework AppKit -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -framework CoreAudio"
+       )
        if(WITH_CODEC_QUICKTIME)
                set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -framework QTKit")
                if(CMAKE_OSX_ARCHITECTURES MATCHES i386)
@@ -1962,22 +2146,10 @@ elseif(APPLE)
                endif()
        endif()
 
-       # XXX - SOME MAC DEV PLEASE TEST WITH THE SDK INSTALLED!
-       # ALSO SHOULD BE MOVED INTO OWN MODULE WHEN FUNCTIONAL
-       if(WITH_INPUT_NDOF)
-               # This thread it *should* work and check the framework - campbell
-               # http://www.cmake.org/pipermail/cmake/2005-December/007740.html
-               find_library(3DCONNEXION_CLIENT_FRAMEWORK
-                       NAMES 3DconnexionClient
-               )
-               if(NOT 3DCONNEXION_CLIENT_FRAMEWORK)
-                       set(WITH_INPUT_NDOF OFF)
-               endif()
-
-               if(WITH_INPUT_NDOF)
-                       set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -F/Library/Frameworks -weak_framework 3DconnexionClient")
-                       set(NDOF_INCLUDE_DIRS /Library/Frameworks/3DconnexionClient.framework/Headers )
-               endif()
+       if(WITH_CXX11)
+               list(APPEND PLATFORM_LINKLIBS c++)
+       else()
+               list(APPEND PLATFORM_LINKLIBS stdc++)
        endif()
 
        if(WITH_JACK)
@@ -1985,7 +2157,8 @@ elseif(APPLE)
        endif()
        
        if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK)
-               set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")# force cmake to link right framework
+               # force cmake to link right framework
+               set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")
        endif()
        
        if(WITH_OPENCOLLADA)
@@ -2000,10 +2173,18 @@ elseif(APPLE)
                )
 
                set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
-               set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lxml2 -lbuffer -lftoa")
+               set(OPENCOLLADA_LIBRARIES
+                       OpenCOLLADASaxFrameworkLoader
+                       -lOpenCOLLADAFramework
+                       -lOpenCOLLADABaseUtils
+                       -lOpenCOLLADAStreamWriter
+                       -lMathMLSolver
+                       -lGeneratedSaxParser
+                       -lxml2 -lbuffer -lftoa
+               )
                # Use UTF functions from collada if LLVM is not enabled
                if(NOT WITH_LLVM)
-                       set(OPENCOLLADA_LIBRARIES "${OPENCOLLADA_LIBRARIES} -lUTF")
+                       list(APPEND OPENCOLLADA_LIBRARIES -lUTF)
                endif()
                # pcre is bundled with openCollada
                #set(PCRE ${LIBDIR}/pcre)
@@ -2038,20 +2219,26 @@ elseif(APPLE)
                set(TIFF_LIBPATH ${TIFF}/lib)
        endif()
 
-       if(WITH_INPUT_NDOF)
-               # linker needs "-weak_framework 3DconnexionClient"
-       endif()
-
        if(WITH_BOOST)
                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)
+               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)
                        list(APPEND BOOST_LIBRARIES boost_locale-mt)
                endif()
                if(WITH_CYCLES_NETWORK)
                        list(APPEND BOOST_LIBRARIES boost_serialization-mt)
                endif()
+               if(WITH_OPENVDB)
+                       list(APPEND BOOST_LIBRARIES boost_iostreams-mt)
+               endif()
                set(BOOST_LIBPATH ${BOOST}/lib)
                set(BOOST_DEFINITIONS)
        endif()
@@ -2063,8 +2250,22 @@ elseif(APPLE)
        if(WITH_OPENIMAGEIO)
                set(OPENIMAGEIO ${LIBDIR}/openimageio)
                set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include)
-               set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO}/lib/libOpenImageIO.a ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${TIFF_LIBRARY} ${OPENEXR_LIBRARIES} ${ZLIB_LIBRARIES})
-               set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib ${JPEG_LIBPATH} ${PNG_LIBPATH} ${TIFF_LIBPATH} ${OPENEXR_LIBPATH} ${ZLIB_LIBPATH})
+               set(OPENIMAGEIO_LIBRARIES
+                       ${OPENIMAGEIO}/lib/libOpenImageIO.a
+                       ${PNG_LIBRARIES}
+                       ${JPEG_LIBRARIES}
+                       ${TIFF_LIBRARY}
+                       ${OPENEXR_LIBRARIES}
+                       ${ZLIB_LIBRARIES}
+               )
+               set(OPENIMAGEIO_LIBPATH
+                       ${OPENIMAGEIO}/lib
+                       ${JPEG_LIBPATH}
+                       ${PNG_LIBPATH}
+                       ${TIFF_LIBPATH}
+                       ${OPENEXR_LIBPATH}
+                       ${ZLIB_LIBPATH}
+               )
                set(OPENIMAGEIO_DEFINITIONS "-DOIIO_STATIC_BUILD")
                set(OPENIMAGEIO_IDIFF "${LIBDIR}/openimageio/bin/idiff")
        endif()
@@ -2076,6 +2277,16 @@ elseif(APPLE)
                set(OPENCOLORIO_LIBPATH ${OPENCOLORIO}/lib)
        endif()
 
+       if(WITH_OPENVDB)
+               set(OPENVDB ${LIBDIR}/openvdb)
+               set(OPENVDB_INCLUDE_DIRS ${OPENVDB}/include)
+               set(TBB_INCLUDE_DIRS ${LIBDIR}/tbb/include)
+               set(TBB_LIBRARIES ${LIBDIR}/tbb/lib/libtbb.a)
+               set(OPENVDB_LIBRARIES openvdb blosc ${TBB_LIBRARIES})
+               set(OPENVDB_LIBPATH ${LIBDIR}/openvdb/lib)
+               set(OPENVDB_DEFINITIONS)
+       endif()
+
        if(WITH_LLVM)
                set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
                set(LLVM_VERSION "3.4" CACHE STRING     "Version of LLVM to use")
@@ -2147,8 +2358,14 @@ elseif(APPLE)
                                include_directories(${LIBDIR}/openmp/include)
                                link_directories(${LIBDIR}/openmp/lib)
                                # This is a workaround for our helperbinaries ( datatoc, masgfmt, ... ),
-                               # They are linked also to omp lib, so we need it in builddir for runtime exexcution, TODO: remove all unneeded dependencies from these
-                               execute_process(COMMAND ditto -arch ${CMAKE_OSX_ARCHITECTURES} ${LIBDIR}/openmp/lib/libiomp5.dylib ${CMAKE_BINARY_DIR}/Resources/lib/libiomp5.dylib) # for intermediate binaries, in respect to lib ID
+                               # They are linked also to omp lib, so we need it in builddir for runtime exexcution,
+                               # TODO: remove all unneeded dependencies from these
+
+                               # for intermediate binaries, in respect to lib ID
+                               execute_process(
+                                       COMMAND ditto -arch ${CMAKE_OSX_ARCHITECTURES}
+                                       ${LIBDIR}/openmp/lib/libiomp5.dylib
+                                       ${CMAKE_BINARY_DIR}/Resources/lib/libiomp5.dylib)
                        endif()
                endif()
        endif()
@@ -2174,56 +2391,75 @@ elseif(APPLE)
                set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth=1024")
        endif()
        # Get rid of eventually clashes, we export some symbols explicite as local
-       set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Xlinker -unexported_symbols_list -Xlinker ${CMAKE_SOURCE_DIR}/source/creator/osx_locals.map")
+       set(PLATFORM_LINKFLAGS
+               "${PLATFORM_LINKFLAGS} -Xlinker -unexported_symbols_list -Xlinker ${CMAKE_SOURCE_DIR}/source/creator/osx_locals.map"
+       )
+
+       if(WITH_CXX11)
+               set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
+               set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -stdlib=libc++")
+       endif()
+
+       # Suppress ranlib "has no symbols" warnings (workaround for T48250)
+       set(CMAKE_C_ARCHIVE_CREATE   "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
+       set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
+       set(CMAKE_C_ARCHIVE_FINISH   "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
+       set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
 endif()
 
 #-----------------------------------------------------------------------------
 # Common.
 
-if(APPLE OR WIN32)
-       if(NOT EXISTS "${LIBDIR}/")
-               message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
-       endif()
-endif()
-
 if(NOT WITH_FFTW3 AND WITH_MOD_OCEANSIM)
        message(FATAL_ERROR "WITH_MOD_OCEANSIM requires WITH_FFTW3 to be ON")
 endif()
 
 if(WITH_CYCLES)
        if(NOT WITH_OPENIMAGEIO)
-               message(FATAL_ERROR "Cycles requires 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 requires 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 requires 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 requires 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()
 
 # See TEST_SSE_SUPPORT() for how this is defined.
 
-if(WITH_RAYOPTIMIZATION)
-       if(SUPPORT_SSE_BUILD)
-               set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
-               add_definitions(-D__SSE__ -D__MMX__)
-       endif()
-       if(SUPPORT_SSE2_BUILD)
-               set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
-               add_definitions(-D__SSE2__)
-               if(NOT SUPPORT_SSE_BUILD) # dont double up
-                       add_definitions(-D__MMX__)
-               endif()
+# Do it globally, SSE2 is required for quite some time now.
+# Doing it now allows to use SSE/SSE2 in inline headers.
+if(SUPPORT_SSE_BUILD)
+       set(PLATFORM_CFLAGS " ${COMPILER_SSE_FLAG} ${PLATFORM_CFLAGS}")
+       add_definitions(-D__SSE__ -D__MMX__)
+endif()
+if(SUPPORT_SSE2_BUILD)
+       set(PLATFORM_CFLAGS " ${COMPILER_SSE2_FLAG} ${PLATFORM_CFLAGS}")
+       add_definitions(-D__SSE2__)
+       if(NOT SUPPORT_SSE_BUILD) # dont double up
+               add_definitions(-D__MMX__)
        endif()
 endif()
 
@@ -2257,15 +2493,15 @@ endif()
 if(WITH_IMAGE_OPENJPEG)
        if(WITH_SYSTEM_OPENJPEG)
                # dealt with above
+               set(OPENJPEG_DEFINES "")
        else()
                set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
-               add_definitions(-DOPJ_STATIC)
+               set(OPENJPEG_DEFINES "-DOPJ_STATIC")
+       endif()
+       # Special handling of Windows platform where openjpeg is always static.
+       if(WIN32)
+               set(OPENJPEG_DEFINES "-DOPJ_STATIC")
        endif()
-endif()
-
-if(WITH_IMAGE_REDCODE)
-       set(REDCODE ${CMAKE_SOURCE_DIR}/extern)
-       set(REDCODE_INC ${REDCODE})
 endif()
 
 if(NOT WITH_SYSTEM_EIGEN3)
@@ -2293,7 +2529,10 @@ if(WITH_GL_PROFILE_COMPAT OR WITH_GL_PROFILE_CORE)
 elseif(WITH_GL_PROFILE_ES20)
        if(WITH_SYSTEM_GLES)
                if(NOT OPENGLES_LIBRARY)
-                       message(FATAL_ERROR "Unable to find OpenGL ES libraries.  Install them or disable WITH_SYSTEM_GLES.")
+                       message(FATAL_ERROR
+                               "Unable to find OpenGL ES libraries. "
+                               "Install them or disable WITH_SYSTEM_GLES."
+                       )
                endif()
 
                list(APPEND BLENDER_GL_LIBRARIES OPENGLES_LIBRARY)
@@ -2305,7 +2544,10 @@ elseif(WITH_GL_PROFILE_ES20)
                list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}")
 
                if(NOT OPENGLES_LIBRARY)
-                       message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_LIBRARY to the file path of an OpenGL ES 2.0 library.")
+                       message(FATAL_ERROR
+                               "To compile WITH_GL_EGL you need to set OPENGLES_LIBRARY "
+                               "to the file path of an OpenGL ES 2.0 library."
+                       )
                endif()
 
        endif()
@@ -2317,7 +2559,10 @@ elseif(WITH_GL_PROFILE_ES20)
                mark_as_advanced(OPENGLES_DLL)
 
                if(NOT OPENGLES_DLL)
-                       message(FATAL_ERROR "To compile WITH_GL_PROFILE_ES20 you need to set OPENGLES_DLL to the file path of an OpenGL ES 2.0 runtime dynamic link library (DLL).")
+                       message(FATAL_ERROR
+                               "To compile WITH_GL_PROFILE_ES20 you need to set OPENGLES_DLL to the file "
+                               "path of an OpenGL ES 2.0 runtime dynamic link library (DLL)."
+                       )
                endif()
 
                if(WITH_GL_ANGLE)
@@ -2331,7 +2576,10 @@ elseif(WITH_GL_PROFILE_ES20)
                        mark_as_advanced(D3DCOMPILER_DLL)
 
                        if(D3DCOMPILER_DLL STREQUAL "")
-                               message(FATAL_ERROR "To compile WITH_GL_ANGLE you need to set D3DCOMPILER_DLL to the file path of a copy of the DirectX redistributable DLL file: D3DCompiler_46.dll")
+                               message(FATAL_ERROR
+                                       "To compile WITH_GL_ANGLE you need to set D3DCOMPILER_DLL to the file "
+                                       "path of a copy of the DirectX redistributable DLL file: D3DCompiler_46.dll"
+                               )
                        endif()
 
                endif()
@@ -2345,7 +2593,10 @@ if(WITH_GL_EGL)
 
        if(WITH_SYSTEM_GLES)
                if(NOT OPENGLES_EGL_LIBRARY)
-                       message(FATAL_ERROR "Unable to find OpenGL ES libraries.  Install them or disable WITH_SYSTEM_GLES.")
+                       message(FATAL_ERROR
+                               "Unable to find OpenGL ES libraries. "
+                               "Install them or disable WITH_SYSTEM_GLES."
+                       )
                endif()
 
                list(APPEND BLENDER_GL_LIBRARIES OPENGLES_EGL_LIBRARY)
@@ -2357,7 +2608,10 @@ if(WITH_GL_EGL)
                list(APPEND BLENDER_GL_LIBRARIES "${OPENGLES_LIBRARY}" "${OPENGLES_EGL_LIBRARY}")
 
                if(NOT OPENGLES_EGL_LIBRARY)
-                       message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY to the file path of an EGL library.")
+                       message(FATAL_ERROR
+                               "To compile WITH_GL_EGL you need to set OPENGLES_EGL_LIBRARY "
+                               "to the file path of an EGL library."
+                       )
                endif()
 
        endif()
@@ -2369,7 +2623,10 @@ if(WITH_GL_EGL)
                mark_as_advanced(OPENGLES_EGL_DLL)
 
                if(NOT OPENGLES_EGL_DLL)
-                       message(FATAL_ERROR "To compile WITH_GL_EGL you need to set OPENGLES_EGL_DLL to the file path of an EGL runtime dynamic link library (DLL).")
+                       message(FATAL_ERROR
+                               "To compile WITH_GL_EGL you need to set OPENGLES_EGL_DLL "
+                               "to the file path of an EGL runtime dynamic link library (DLL)."
+                       )
                endif()
 
        endif()
@@ -2397,8 +2654,18 @@ endif()
 if(WITH_OPENMP)
        find_package(OpenMP)
        if(OPENMP_FOUND)
-               set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
-               set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
+               if(NOT WITH_OPENMP_STATIC)
+                       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
+                       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
+               else()
+                       # Typically avoid adding flags as defines but we can't
+                       # pass OpenMP flags to the linker for static builds, meaning
+                       # we can't add any OpenMP related flags to CFLAGS variables
+                       # since they're passed to the linker as well.
+                       add_definitions("${OpenMP_C_FLAGS}")
+
+                       find_library_static(OpenMP_LIBRARIES gomp ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})
+               endif()
        else()
                set(WITH_OPENMP OFF)
        endif()
@@ -2503,6 +2770,63 @@ if(WITH_PYTHON_MODULE)
        add_definitions(-DPy_ENABLE_SHARED)
 endif()
 
+#-----------------------------------------------------------------------------
+# Configure GLog/GFlags
+
+if(WITH_LIBMV OR WITH_GTESTS OR (WITH_CYCLES AND WITH_CYCLES_LOGGING))
+       set(GLOG_DEFINES
+               -DGOOGLE_GLOG_DLL_DECL=
+       )
+
+       set(GFLAGS_DEFINES
+               -DGFLAGS_DLL_DEFINE_FLAG=
+               -DGFLAGS_DLL_DECLARE_FLAG=
+               -DGFLAGS_DLL_DECL=
+       )
+endif()
+
+#-----------------------------------------------------------------------------
+# Configure Ceres
+
+if(WITH_LIBMV)
+       set(CERES_DEFINES)
+
+       if(WITH_CXX11)
+               # nothing to be done
+       elseif(SHARED_PTR_FOUND)
+               if(SHARED_PTR_TR1_MEMORY_HEADER)
+                       list(APPEND CERES_DEFINES -DCERES_TR1_MEMORY_HEADER)
+               endif()
+               if(SHARED_PTR_TR1_NAMESPACE)
+                       list(APPEND CERES_DEFINES -DCERES_TR1_SHARED_PTR)
+               endif()
+       else()
+               message(FATAL_ERROR "Ceres: Unable to find shared_ptr.")
+       endif()
+
+       if(WITH_CXX11)
+               list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP)
+       elseif(HAVE_STD_UNORDERED_MAP_HEADER)
+               if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
+                       list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP)
+               else()
+                       if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
+                               list(APPEND CERES_DEFINES -DCERES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
+                       else()
+                               list(APPEND CERES_DEFINES -DCERES_NO_UNORDERED_MAP)
+                               message(STATUS "Ceres: Replacing unordered_map/set with map/set (warning: slower!)")
+                       endif()
+               endif()
+       else()
+               if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
+                       list(APPEND CERES_DEFINES -DCERES_TR1_UNORDERED_MAP)
+               else()
+                       list(APPEND CERES_DEFINES -DCERES_NO_UNORDERED_MAP)
+                       message(STATUS "Ceres: Replacing unordered_map/set with map/set (warning: slower!)")
+               endif()
+       endif()
+endif()
+
 #-----------------------------------------------------------------------------
 # Extra compile flags
 
@@ -2510,9 +2834,9 @@ if(CMAKE_COMPILER_IS_GNUCC)
 
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
-       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_ERROR_VLA -Werror=vla)
        # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
        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)
@@ -2541,6 +2865,11 @@ if(CMAKE_COMPILER_IS_GNUCC)
                ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_REDUNDANT_DECLS -Wredundant-decls)
        endif()
 
+       # versions before gcc4.8 include global name-space.
+       if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.8")
+               ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_SHADOW -Wshadow)
+       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)
 
@@ -2557,7 +2886,6 @@ if(CMAKE_COMPILER_IS_GNUCC)
        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)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
-       ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
        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_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
@@ -2594,7 +2922,6 @@ elseif(CMAKE_C_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)
@@ -2656,6 +2983,7 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
                "/w34062"  # switch statement contains 'default' but no 'case' labels
                # disable:
                "/wd4018"  # signed/unsigned mismatch
+               "/wd4146"  # unary minus operator applied to unsigned type, result still unsigned
                "/wd4065"  # switch statement contains 'default' but no 'case' labels
                "/wd4127"  # conditional expression is constant
                "/wd4181"  # qualifier applied to reference type; ignored
@@ -2680,13 +3008,15 @@ endif()
 # be most problematic.
 if(WITH_PYTHON)
        if(NOT EXISTS "${PYTHON_INCLUDE_DIR}/Python.h")
-               message(FATAL_ERROR "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
-                                                       "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
-                                                       "to a valid python include path. Containing "
-                                                       "Python.h for python version \"${PYTHON_VERSION}\"")
+               message(FATAL_ERROR
+                       "Missing: \"${PYTHON_INCLUDE_DIR}/Python.h\",\n"
+                       "Set the cache entry 'PYTHON_INCLUDE_DIR' to point "
+                       "to a valid python include path. Containing "
+                       "Python.h for python version \"${PYTHON_VERSION}\""
+               )
        endif()
 
-       if(WIN32)
+       if(WIN32 OR APPLE)
                # pass, we have this in an archive to extract
        elseif(WITH_PYTHON_INSTALL AND WITH_PYTHON_INSTALL_NUMPY)
                find_python_package(numpy)
@@ -2699,14 +3029,34 @@ if(WITH_PYTHON)
        endif()
 endif()
 
-if(WITH_CPP11)
+if(WITH_CXX11)
        if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+               # TODO(sergey): Do we want c++11 or gnu-c++11 here?
                set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
        elseif(MSVC12)
                # Nothing special is needed, C++11 features are available by default.
        else()
                message(FATAL_ERROR "Compiler ${CMAKE_C_COMPILER_ID} is not supported for C++11 build yet")
        endif()
+else()
+       # GCC-6 switched to C++11 by default, which would break linking with existing libraries
+       # by default. So we explicitly disable C++11 for a new GCC so no linking issues happens.
+       if(CMAKE_COMPILER_IS_GNUCC AND (NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "6.0"))
+               set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++98")
+               # We also disable any of C++11 ABI from usage, so we wouldn't even try to
+               # link to stuff from std::__cxx11 namespace.
+               add_definitions("-D_GLIBCXX_USE_CXX11_ABI=0")
+       endif()
+endif()
+
+# Visual Studio has all standards it supports available by default
+if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "Intel")
+       # Use C99 + GNU extensions, works with GCC, Clang, ICC
+       if(WITH_C11)
+               set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
+       else()
+               set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
+       endif()
 endif()
 
 # Include warnings first, so its possible to disable them with user defined flags
@@ -2764,7 +3114,9 @@ if(WITH_BLENDER OR WITH_PLAYER)
 elseif(WITH_CYCLES_STANDALONE)
        add_subdirectory(intern/cycles)
        add_subdirectory(extern/clew)
-       add_subdirectory(extern/cuew)
+       if(WITH_CUDA_DYNLOAD)
+               add_subdirectory(extern/cuew)
+       endif()
        if(NOT WITH_SYSTEM_GLEW)
                add_subdirectory(extern/glew)
        endif()
@@ -2809,7 +3161,7 @@ if(FIRST_RUN)
                string(LENGTH "${_msg}" _len)
                while("32" GREATER "${_len}")
                        set(_msg "${_msg} ")
-                        math(EXPR _len "${_len} + 1")
+                       math(EXPR _len "${_len} + 1")
                endwhile()
 
                set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
@@ -2838,6 +3190,7 @@ if(FIRST_RUN)
        info_cfg_option(WITH_CYCLES)
        info_cfg_option(WITH_FREESTYLE)
        info_cfg_option(WITH_OPENCOLORIO)
+       info_cfg_option(WITH_OPENVDB)
 
        info_cfg_text("Compiler Options:")
        info_cfg_option(WITH_BUILDINFO)
@@ -2860,7 +3213,6 @@ if(FIRST_RUN)
        info_cfg_option(WITH_IMAGE_HDR)
        info_cfg_option(WITH_IMAGE_OPENEXR)
        info_cfg_option(WITH_IMAGE_OPENJPEG)
-       info_cfg_option(WITH_IMAGE_REDCODE)
        info_cfg_option(WITH_IMAGE_TIFF)
 
        info_cfg_text("Audio:")
@@ -2903,12 +3255,6 @@ if(FIRST_RUN)
                info_cfg_option(WITH_GL_ANGLE)
        endif()
 
-       info_cfg_text("Other:")
-       info_cfg_option(WITH_OPENNL)
-
-       # debug
-       message(STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}")
-
        info_cfg_text("")
 
        message("${_config_msg}")