CMake: De-duplicate checks around unordered maps and shared pointer
[blender.git] / CMakeLists.txt
index 87ee8526fc97e61bdef5b66657ec383d9dfe579a..e91f4b503a23b51d88eac6c001c41c4d4239e23f 100644 (file)
@@ -47,13 +47,10 @@ 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")
+       set(FIRST_RUN TRUE)
+else()
+       set(FIRST_RUN FALSE)
 endif()
 
 # this starts out unset
@@ -66,11 +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
@@ -129,7 +136,7 @@ macro(option_defaults_init)
                set(${_var} ON)
                list(APPEND _init_vars "${_var}")
        endforeach()
-       unset(_INC)
+       unset(_var)
 endmacro()
 
 # remove from namespace
@@ -157,25 +164,30 @@ option_defaults_init(
        _init_SDL
        _init_FFTW3
        _init_GAMEENGINE
+       _init_OPENSUBDIV
 )
 
 # customize...
-if(UNIX AND NOT APPLE)
+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_INPUT_NDOF                     OFF)
+       set(_init_JACK                           OFF)
+       set(_init_OPENSUBDIV                     OFF)
 endif()
 
 
@@ -197,10 +209,10 @@ option(WITH_PYTHON        "Enable Embedded Python API  (only disable for develop
 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)
+mark_as_advanced(WITH_PYTHON_SAFETY)
+option(WITH_PYTHON_MODULE "Enable building as a python module which runs without a user interface, like running regular blender in background mode (experimental, only enable for development), installs to PYTHON_SITE_PACKAGES (or CMAKE_INSTALL_PREFIX if WITH_INSTALL_PORTABLE is enabled)." OFF)
 if(APPLE)
        option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
 endif()
@@ -220,7 +232,15 @@ mark_as_advanced(WITH_SYSTEM_BULLET)
 option(WITH_GAMEENGINE    "Enable Game Engine" ${_init_GAMEENGINE})
 option(WITH_PLAYER        "Build Player" OFF)
 option(WITH_OPENCOLORIO   "Enable OpenColorIO color management" ${_init_OPENCOLORIO})
-option(WITH_COMPOSITOR    "Enable the tile based nodal compositor" ON)
+
+# 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" _init_OPENSUBDIV)
+option(WITH_SUBSURF_WERROR  "Treat warnings as errors in subsurf code" OFF)
+mark_as_advanced(WITH_COMPOSITOR_WERROR)
 
 # GHOST Windowing Library Options
 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
@@ -238,9 +258,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)
@@ -260,6 +290,10 @@ endif()
 # (unix defaults to System OpenJPEG On)
 option(WITH_SYSTEM_OPENJPEG "Use the operating systems OpenJPEG library" OFF)
 
+if(UNIX AND NOT APPLE)
+       option(WITH_SYSTEM_EIGEN3 "Use the systems Eigen3 library" OFF)
+endif()
+
 
 # Modifiers
 option(WITH_MOD_FLUID           "Enable Elbeem Modifier (Fluid Simulation)" ON)
@@ -308,19 +342,26 @@ endif()
 # Compression
 option(WITH_LZO           "Enable fast LZO compression (used for pointcache)" ON)
 option(WITH_LZMA          "Enable best LZMA compression, (used for pointcache)" ON)
+if(UNIX AND NOT APPLE)
+       option(WITH_SYSTEM_LZO    "Use the system LZO library" OFF)
+endif()
 
 # Camera/motion tracking
-option(WITH_LIBMV         "Enable libmv structure from motion library" ON)
+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")
 mark_as_advanced(WITH_LIBMV_SCHUR_SPECIALIZATIONS)
+mark_as_advanced(WITH_LIBMV_WERROR)
 
 # Freestyle
 option(WITH_FREESTYLE     "Enable Freestyle (advanced edges rendering)" ON)
 
 # Misc
+if(WIN32)
+       option(WITH_INPUT_IME "Enable Input Method Editor (IME) for complex Asian character input" ON)
+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)
@@ -343,18 +384,23 @@ if(UNIX AND NOT APPLE)
 endif()
 
 # 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                                     "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 CACHE STRING "CUDA architectures to build binaries for")
+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")
 mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH)
 unset(PLATFORM_DEFAULT)
-option(WITH_CYCLES_LOGGING     "Build cycles with logging support" OFF)
-option(WITH_CYCLES_DEBUG       "Build cycles with extra debug capabilities" OFF)
+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)
 mark_as_advanced(WITH_CYCLES_LOGGING)
 mark_as_advanced(WITH_CYCLES_DEBUG)
+mark_as_advanced(WITH_CYCLES_WERROR)
+
+option(WITH_CUDA_DYNLOAD "Dynamically load CUDA libraries at runtime" ON)
+mark_as_advanced(WITH_CUDA_DYNLOAD)
 
 # LLVM
 option(WITH_LLVM                                       "Use LLVM" OFF)
@@ -366,7 +412,7 @@ endif()
 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)
+option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" ON)
 mark_as_advanced(WITH_MEM_JEMALLOC)
 
 # currently only used for BLI_mempool
@@ -426,11 +472,19 @@ 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)
+
+# Dependency graph
+option(WITH_LEGACY_DEPSGRAPH "Build Blender with legacy dependency graph" ON)
+mark_as_advanced(WITH_LEGACY_DEPSGRAPH)
+
 # avoid using again
 option_defaults_clear()
 
@@ -441,7 +495,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)
@@ -469,7 +523,11 @@ if(APPLE)
        endif()
        
        execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version
-       if(${MAC_SYS} MATCHES 14)
+       if(${MAC_SYS} MATCHES 15)
+               set(OSX_SYSTEM 10.11)
+               # throw an error here, older cmake cannot handle 2 digit subversion!
+               cmake_minimum_required(VERSION 3.0.0)
+       elseif(${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)
@@ -486,13 +544,11 @@ if(APPLE)
        else()
                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")
        
@@ -520,8 +576,8 @@ 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
@@ -634,6 +690,13 @@ endif()
 # auto enable openimageio for cycles
 if(WITH_CYCLES)
        set(WITH_OPENIMAGEIO ON)
+
+       # auto enable llvm for cycles_osl
+       if(WITH_CYCLES_OSL)
+               set(WITH_LLVM ON CACHE BOOL "" FORCE)
+       endif()
+else()
+       set(WITH_CYCLES_OSL OFF)
 endif()
 
 # auto enable openimageio linking dependencies
@@ -642,11 +705,6 @@ if(WITH_OPENIMAGEIO)
        set(WITH_IMAGE_TIFF ON)
 endif()
 
-# auto enable llvm for cycles_osl
-if(WITH_CYCLES_OSL)
-       set(WITH_LLVM ON CACHE BOOL "" FORCE)
-endif()
-
 # don't store paths to libs for portable distribution
 if(WITH_INSTALL_PORTABLE)
        set(CMAKE_SKIP_BUILD_RPATH TRUE)
@@ -657,6 +715,7 @@ if(WITH_GHOST_SDL OR WITH_HEADLESS)
        set(WITH_X11_XINPUT    OFF)
        set(WITH_X11_XF86VMODE OFF)
        set(WITH_GHOST_XDND    OFF)
+       set(WITH_INPUT_IME     OFF)
 endif()
 
 if(WITH_CPU_SSE)
@@ -672,6 +731,37 @@ if(HAVE_STDBOOL_H)
        add_definitions(-DHAVE_STDBOOL_H)
 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()
+
 #-----------------------------------------------------------------------------
 # Check for valid directories
 # ... a partial checkout may cause this.
@@ -729,14 +819,14 @@ 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
+#         -D PYTHON_VERSION=3.5 \
+#         -D PYTHON_INCLUDE_DIR=/opt/py35/include/python3.5d \
+#         -D PYTHON_LIBRARY=/opt/py35/lib/libpython3.5d.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 \
+#         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5 \
+#         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/config \
 #         -G Xcode
 #
 # When changing any of this remember to update the notes in doc/build_systems/cmake.txt
@@ -773,16 +863,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()
 
@@ -791,11 +885,26 @@ if(UNIX AND NOT APPLE)
        find_package_wrapper(ZLIB REQUIRED)
        find_package_wrapper(Freetype REQUIRED)
 
+       if(WITH_LZO AND WITH_SYSTEM_LZO)
+               find_package_wrapper(LZO)
+               if(NOT LZO_FOUND)
+                       message(FATAL_ERROR "Failed finding system LZO version!")
+               endif()
+       endif()
+
+       if(WITH_SYSTEM_EIGEN3)
+               find_package_wrapper(Eigen3)
+               if(NOT EIGEN3_FOUND)
+                       message(FATAL_ERROR "Failed finding system Eigen3 version!")
+               endif()
+       endif()
+       # 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)
@@ -826,6 +935,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)
@@ -835,17 +951,21 @@ if(UNIX AND NOT APPLE)
 
        if(WITH_SDL)
                if(WITH_SDL_DYNLOAD)
-                       set(SDLMAIN_LIBRARY)
                        set(SDL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/extern/sdlew/include/SDL2")
                        set(SDL_LIBRARY)
-                       set(SDL_LIBRARY_TEMP)
                else()
-                       find_package_wrapper(SDL)
+                       find_package_wrapper(SDL2)
+                       if(SDL2_FOUND)
+                               # Use same names for both versions of SDL until we move to 2.x.
+                               set(SDL_INCLUDE_DIR "${SDL2_INCLUDE_DIR}")
+                               set(SDL_LIBRARY "${SDL2_LIBRARY}")
+                               set(SDL_FOUND "${SDL2_FOUND}")
+                       else()
+                               find_package_wrapper(SDL)
+                       endif()
                        mark_as_advanced(
-                               SDLMAIN_LIBRARY
                                SDL_INCLUDE_DIR
                                SDL_LIBRARY
-                               SDL_LIBRARY_TEMP
                        )
                        # unset(SDLMAIN_LIBRARY CACHE)
                        if(NOT SDL_FOUND)
@@ -923,6 +1043,24 @@ if(UNIX AND NOT APPLE)
                endif()
        endif()
 
+       if(WITH_CYCLES_OSL)
+               set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
+               if(NOT OSL_ROOT)
+                       set(OSL_ROOT ${CYCLES_OSL})
+               endif()
+               find_package_wrapper(OpenShadingLanguage)
+               if(OSL_FOUND)
+                       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})
+                       endif()
+               else()
+                       message(STATUS "OSL not found, disabling it from Cycles")
+                       set(WITH_CYCLES_OSL OFF)
+               endif()
+       endif()
+
        if(WITH_BOOST)
                # uses in build instructions to override include and library variables
                if(NOT BOOST_CUSTOM)
@@ -931,6 +1069,12 @@ if(UNIX AND NOT APPLE)
                        endif()
                        set(Boost_USE_MULTITHREADED ON)
                        set(__boost_packages filesystem regex system thread date_time)
+                       if(WITH_CYCLES_OSL)
+                               if(NOT (${OSL_LIBRARY_VERSION_MAJOR} EQUAL "1" AND ${OSL_LIBRARY_VERSION_MINOR} LESS "6"))
+                                       list(APPEND __boost_packages wave)
+                               else()
+                               endif()
+                       endif()
                        if(WITH_INTERNATIONAL)
                                list(APPEND __boost_packages locale)
                        endif()
@@ -960,6 +1104,12 @@ if(UNIX AND NOT APPLE)
 
        if(WITH_OPENIMAGEIO)
                find_package_wrapper(OpenImageIO)
+               if(NOT OPENIMAGEIO_PUGIXML_FOUND AND WITH_CYCLES_STANDALONE)
+                       find_package_wrapper(PugiXML)
+               else()
+                       set(PUGIXML_INCLUDE_DIR "${OPENIMAGEIO_INCLUDE_DIR/OpenImageIO}")
+                       set(PUGIXML_LIBRARIES "")
+               endif()
 
                set(OPENIMAGEIO_LIBRARIES ${OPENIMAGEIO_LIBRARIES} ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${ZLIB_LIBRARIES} ${BOOST_LIBRARIES})
                set(OPENIMAGEIO_LIBPATH)  # TODO, remove and reference the absolute path everywhere
@@ -991,96 +1141,29 @@ if(UNIX AND NOT APPLE)
                endif()
        endif()
 
-       # XXX Maybe most of this section should go into an llvm module?
        if(WITH_LLVM)
-               # Set llvm version if not specified
-               if(NOT LLVM_VERSION)
-                       set(LLVM_VERSION "3.0")
-               endif()
-
-               if(LLVM_DIRECTORY)
-                       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)
-                       endif()
-               else()
-                       find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION})
-                       if(NOT LLVM_CONFIG)
-                               find_program(LLVM_CONFIG llvm-config)
-                       endif()
-               endif()
-
-               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")
-                       mark_as_advanced(LLVM_LIBPATH)
-               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()
+               find_package_wrapper(LLVM)
 
-
-               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
-                               # way for LLVM_LIBRARY.
-                               execute_process(COMMAND ${LLVM_CONFIG} --libfiles
-                                               OUTPUT_VARIABLE LLVM_LIBRARY
-                                               OUTPUT_STRIP_TRAILING_WHITESPACE)
-                               string(REPLACE " " ";" LLVM_LIBRARY "${LLVM_LIBRARY}")
-                       endif()
-               else()
-                       message(FATAL_ERROR "LLVM not found.")
+               if(NOT LLVM_FOUND)
+                       set(WITH_LLVM OFF)
+                       message(STATUS "LLVM not found")
                endif()
-
        endif()
 
        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_CYCLES_OSL)
-               set(CYCLES_OSL ${LIBDIR}/osl CACHE PATH "Path to OpenShadingLanguage installation")
-       
-               message(STATUS "CYCLES_OSL = ${CYCLES_OSL}")
-       
-               find_library(OSL_LIB_EXEC NAMES oslexec PATHS ${CYCLES_OSL}/lib)
-               find_library(OSL_LIB_COMP NAMES oslcomp PATHS ${CYCLES_OSL}/lib)
-               find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
-               # Note: --whole-archive is needed to force loading of all symbols in liboslexec,
-               # otherwise LLVM is missing the osl_allocate_closure_component function
-               list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -Wl,--whole-archive ${OSL_LIB_EXEC} -Wl,--no-whole-archive ${OSL_LIB_QUERY})
-               find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
-               find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
-       
-               if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
-                       set(OSL_FOUND TRUE)
-               else()
-                       message(STATUS "OSL not found")
-                       set(WITH_CYCLES_OSL OFF)
+       if(WITH_OPENSUBDIV)
+               find_package_wrapper(OpenSubdiv)
+
+               set(OPENSUBDIV_LIBRARIES ${OPENSUBDIV_LIBRARIES})
+               set(OPENSUBDIV_LIBPATH)  # TODO, remove and reference the absolute path everywhere
+
+               if(NOT OPENSUBDIV_FOUND)
+                       set(WITH_OPENSUBDIV OFF)
+                       message(STATUS "OpenSubdiv not found")
                endif()
        endif()
 
@@ -1089,6 +1172,8 @@ if(UNIX AND NOT APPLE)
 
        find_package(Threads REQUIRED)
        list(APPEND PLATFORM_LINKLIBS ${CMAKE_THREAD_LIBS_INIT})
+       # used by other platforms
+       set(PTHREADS_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
 
        if(CMAKE_DL_LIBS)
                list(APPEND PLATFORM_LINKLIBS ${CMAKE_DL_LIBS})
@@ -1108,6 +1193,19 @@ if(UNIX AND NOT APPLE)
        # GNU Compiler
        if(CMAKE_COMPILER_IS_GNUCC)
                set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
+
+               # use ld.gold linker if available, could make optional
+               execute_process(
+                       COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version
+                       ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
+               if("${LD_VERSION}" MATCHES "GNU gold")
+                       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-ld=gold")
+                       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold")
+               else()
+                       message(STATUS "GNU gold linker isn't available, using the default system linker.")
+               endif()
+               unset(LD_VERSION)
+
        # CLang is the same as GCC for now.
        elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
                set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
@@ -1149,7 +1247,11 @@ elseif(WIN32)
                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)
+               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)
+               endif()
 
                add_definitions(
                        -D_CRT_NONSTDC_NO_DEPRECATE
@@ -1171,26 +1273,17 @@ 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)
-
-               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 "${CMAKE_CXX_FLAGS} /nologo /J /Gd /MP /EHsc")
+               set(CMAKE_C_FLAGS     "${CMAKE_C_FLAGS} /nologo /J /Gd /MP")
 
+               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 /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
 
@@ -1204,13 +1297,22 @@ elseif(WIN32)
                set(PLATFORM_LINKFLAGS_DEBUG "/IGNORE:4099 /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
 
                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})
@@ -1234,17 +1336,15 @@ elseif(WIN32)
 
                find_package(png)
                if(NOT PNG_FOUND)
-                       set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
                        message(WARNING "Using HARDCODED libpng locations")
+                       set(PNG_PNG_INCLUDE_DIR ${LIBDIR}/png/include)
                        set(PNG_LIBRARIES libpng)
                        set(PNG "${LIBDIR}/png")
                        set(PNG_INCLUDE_DIRS "${PNG}/include")
                        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)
@@ -1322,19 +1422,19 @@ elseif(WIN32)
                        set(OPENEXR_VERSION "2.1")
                        find_package(OPENEXR REQUIRED)
                        if(NOT OPENEXR_FOUND)
-                       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_LIBPATH ${OPENEXR}/lib)
-                       set(OPENEXR_LIBRARIES
-                               ${OPENEXR_LIBPATH}/Iex-2_1.lib
-                               ${OPENEXR_LIBPATH}/Half.lib
-                               ${OPENEXR_LIBPATH}/IlmImf-2_1.lib
-                               ${OPENEXR_LIBPATH}/Imath-2_1.lib
-                               ${OPENEXR_LIBPATH}/IlmThread-2_1.lib
-                       )
-                       endif(NOT OPENEXR_FOUND)
+                               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_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
+                               )
+                       endif()
                endif()
 
                if(WITH_IMAGE_TIFF)
@@ -1356,7 +1456,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
@@ -1374,10 +1474,10 @@ elseif(WIN32)
                if(WITH_BOOST)
                        if(WITH_CYCLES_OSL)
                                set(boost_extra_libs wave)
-                       endif(WITH_CYCLES_OSL)
+                       endif()
                        if(WITH_INTERNATIONAL)
                                list(APPEND boost_extra_libs locale)
-                       endif(WITH_INTERNATIONAL)
+                       endif()
                        set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
                        set(Boost_USE_MULTITHREADED ON) # suffix -mt
                        set(Boost_USE_STATIC_LIBS ON) # suffix -s
@@ -1392,8 +1492,8 @@ elseif(WIN32)
                                        set(BOOST_DEBUG_POSTFIX "vc120-mt-sgd-1_55.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}
@@ -1430,20 +1530,21 @@ elseif(WIN32)
                        set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
                        set(OPENIMAGEIO_DEFINITIONS "-DUSE_TBB=0")
                        set(OPENCOLORIO_DEFINITIONS "-DOCIO_STATIC_BUILD")
+                       set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe")
                        add_definitions(-DOIIO_STATIC_BUILD)
                endif()
 
                if(WITH_LLVM)
-                       set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
-                       file(GLOB LLVM_LIBRARY_OPTIMIZED ${LLVM_DIRECTORY}/lib/*.lib)
+                       set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
+                       file(GLOB LLVM_LIBRARY_OPTIMIZED ${LLVM_ROOT_DIR}/lib/*.lib)
 
-                       if(EXISTS ${LLVM_DIRECTORY}/debug/lib)
+                       if(EXISTS ${LLVM_ROOT_DIR}/debug/lib)
                                foreach(LLVM_OPTIMIZED_LIB ${LLVM_LIBRARY_OPTIMIZED})
                                        get_filename_component(LIBNAME ${LLVM_OPTIMIZED_LIB} ABSOLUTE)
                                        list(APPEND LLVM_LIBS optimized ${LIBNAME})
                                endforeach(LLVM_OPTIMIZED_LIB)
                        
-                               file(GLOB LLVM_LIBRARY_DEBUG ${LLVM_DIRECTORY}/debug/lib/*.lib)
+                               file(GLOB LLVM_LIBRARY_DEBUG ${LLVM_ROOT_DIR}/debug/lib/*.lib)
 
                                foreach(LLVM_DEBUG_LIB ${LLVM_LIBRARY_DEBUG})
                                        get_filename_component(LIBNAME ${LLVM_DEBUG_LIB} ABSOLUTE)
@@ -1478,6 +1579,35 @@ elseif(WIN32)
                        )
                endif()
 
+               if(WITH_OPENSUBDIV)
+                       set(OPENSUBDIV_INCLUDE_DIR ${LIBDIR}/opensubdiv/include)
+                       set(OPENSUBDIV_LIBPATH ${LIBDIR}/opensubdiv/lib)
+                       set(OPENSUBDIV_LIBRARIES ${OPENSUBDIV_LIBPATH}/osdCPU.lib ${OPENSUBDIV_LIBPATH}/osdGPU.lib)
+                       find_package(OpenSubdiv)
+               endif()
+
+               if(WITH_SDL)
+                       set(SDL ${LIBDIR}/sdl)
+                       set(SDL_INCLUDE_DIR ${SDL}/include)
+                       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
                blender_include_dirs_sys("${PTHREADS_INCLUDE_DIRS}")
 
@@ -1505,7 +1635,12 @@ elseif(WIN32)
                        endif()
                endif()
                
-               list(APPEND PLATFORM_LINKLIBS -lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32 -lpsapi)
+               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)
+               endif()
+
                set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
 
                if(WITH_MINGW64)
@@ -1611,7 +1746,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)
@@ -1659,11 +1794,12 @@ elseif(WIN32)
                        set(OPENIMAGEIO_LIBRARIES OpenImageIO)
                        set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib)
                        set(OPENIMAGEIO_DEFINITIONS "")
+                       set(OPENIMAGEIO_IDIFF "${OPENIMAGEIO}/bin/idiff.exe")
                endif()
                
                if(WITH_LLVM)
-                       set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
-                       set(LLVM_LIBPATH ${LLVM_DIRECTORY}/lib)
+                       set(LLVM_ROOT_DIR ${LIBDIR}/llvm CACHE PATH     "Path to the LLVM installation")
+                       set(LLVM_LIBPATH ${LLVM_ROOT_DIR}/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
@@ -1696,6 +1832,13 @@ elseif(WIN32)
                        set(OPENCOLORIO_DEFINITIONS)
                endif()
 
+               if(WITH_SDL)
+                       set(SDL ${LIBDIR}/sdl)
+                       set(SDL_INCLUDE_DIR ${SDL}/include)
+                       set(SDL_LIBRARY SDL)
+                       set(SDL_LIBPATH ${SDL}/lib)
+               endif()
+
                set(PLATFORM_LINKFLAGS "-Xlinker --stack=2097152")
 
                ## DISABLE - causes linking errors 
@@ -1727,13 +1870,6 @@ elseif(WIN32)
                set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
        endif()
 
-       if(WITH_SDL)
-               set(SDL ${LIBDIR}/sdl)
-               set(SDL_INCLUDE_DIR ${SDL}/include)
-               set(SDL_LIBRARY SDL2)
-               set(SDL_LIBPATH ${SDL}/lib)
-       endif()
-
        if(WITH_RAYOPTIMIZATION AND SUPPORT_SSE_BUILD)
                add_definitions(-D__SSE__ -D__MMX__)
        endif()
@@ -1748,10 +1884,10 @@ elseif(WIN32)
                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})
-               find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
+               find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
                find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
        
-               if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
+               if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
                        set(OSL_FOUND TRUE)
                else()
                        message(STATUS "OSL not found")
@@ -1786,6 +1922,17 @@ elseif(APPLE)
                endif()
        endif()
 
+       if(WITH_OPENSUBDIV)
+               set(OPENSUBDIV ${LIBDIR}/opensubdiv)
+               set(OPENSUBDIV_LIBPATH ${OPENSUBDIV}/lib)
+               find_library(OSL_LIB_UTIL NAMES osdutil PATHS ${OPENSUBDIV_LIBPATH})
+               find_library(OSL_LIB_CPU NAMES osdCPU PATHS ${OPENSUBDIV_LIBPATH})
+               find_library(OSL_LIB_GPU NAMES osdGPU PATHS ${OPENSUBDIV_LIBPATH})
+               set(OPENSUBDIV_INCLUDE_DIR ${OPENSUBDIV}/include)
+               set(OPENSUBDIV_INCLUDE_DIRS ${OPENSUBDIV_INCLUDE_DIR})
+               list(APPEND OPENSUBDIV_LIBRARIES ${OSL_LIB_UTIL} ${OSL_LIB_CPU} ${OSL_LIB_GPU})
+       endif()
+
        if(WITH_JACK)
                find_library(JACK_FRAMEWORK
                        NAMES jackmp
@@ -1804,19 +1951,19 @@ 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_BINARY "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
+                       # set(PYTHON_EXECUTABLE "${LIBDIR}/python/bin/python${PYTHON_VERSION}") # not used yet
                        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_BINARY "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
+                       set(PYTHON_EXECUTABLE "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/bin/python${PYTHON_VERSION}")
                        #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
@@ -1987,6 +2134,7 @@ elseif(APPLE)
                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()
 
        if(WITH_OPENCOLORIO)
@@ -1997,10 +2145,10 @@ elseif(APPLE)
        endif()
 
        if(WITH_LLVM)
-               set(LLVM_DIRECTORY ${LIBDIR}/llvm CACHE PATH    "Path to the LLVM installation")
+               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")
-               if(EXISTS "${LLVM_DIRECTORY}/bin/llvm-config")
-                       set(LLVM_CONFIG "${LLVM_DIRECTORY}/bin/llvm-config")
+               if(EXISTS "${LLVM_ROOT_DIR}/bin/llvm-config")
+                       set(LLVM_CONFIG "${LLVM_ROOT_DIR}/bin/llvm-config")
                else()
                        set(LLVM_CONFIG llvm-config)
                endif()
@@ -2008,7 +2156,7 @@ elseif(APPLE)
                                OUTPUT_VARIABLE LLVM_VERSION
                                OUTPUT_STRIP_TRAILING_WHITESPACE)
                execute_process(COMMAND ${LLVM_CONFIG} --prefix
-                               OUTPUT_VARIABLE LLVM_DIRECTORY
+                               OUTPUT_VARIABLE LLVM_ROOT_DIR
                                OUTPUT_STRIP_TRAILING_WHITESPACE)
                execute_process(COMMAND ${LLVM_CONFIG} --libdir
                                OUTPUT_VARIABLE LLVM_LIBPATH
@@ -2017,7 +2165,7 @@ elseif(APPLE)
                             NAMES LLVMAnalysis # first of a whole bunch of libs to get
                             PATHS ${LLVM_LIBPATH})
 
-               if(LLVM_LIBRARY AND LLVM_DIRECTORY AND LLVM_LIBPATH)
+               if(LLVM_LIBRARY AND LLVM_ROOT_DIR 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
@@ -2042,10 +2190,10 @@ elseif(APPLE)
                find_library(OSL_LIB_QUERY NAMES oslquery PATHS ${CYCLES_OSL}/lib)
                # WARNING! depends on correct order of OSL libs linking
                list(APPEND OSL_LIBRARIES ${OSL_LIB_COMP} -force_load ${OSL_LIB_EXEC} ${OSL_LIB_QUERY})
-               find_path(OSL_INCLUDES OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
+               find_path(OSL_INCLUDE_DIR OSL/oslclosure.h PATHS ${CYCLES_OSL}/include)
                find_program(OSL_COMPILER NAMES oslc PATHS ${CYCLES_OSL}/bin)
        
-               if(OSL_INCLUDES AND OSL_LIBRARIES AND OSL_COMPILER)
+               if(OSL_INCLUDE_DIR AND OSL_LIBRARIES AND OSL_COMPILER)
                        set(OSL_FOUND TRUE)
                else()
                        message(STATUS "OSL not found")
@@ -2177,9 +2325,14 @@ 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()
 
@@ -2188,6 +2341,9 @@ if(WITH_IMAGE_REDCODE)
        set(REDCODE_INC ${REDCODE})
 endif()
 
+if(NOT WITH_SYSTEM_EIGEN3)
+       set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3)
+endif()
 
 #-----------------------------------------------------------------------------
 # Configure OpenGL.
@@ -2314,8 +2470,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()
@@ -2420,6 +2586,59 @@ 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(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(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
 
@@ -2427,9 +2646,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)
@@ -2445,6 +2664,7 @@ if(CMAKE_COMPILER_IS_GNUCC)
        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)
+       ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_FORMAT_SIGN -Wformat-signedness)
 
        # gcc 4.2 gives annoying warnings on every file with this
        if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
@@ -2457,6 +2677,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)
 
@@ -2472,6 +2697,15 @@ if(CMAKE_COMPILER_IS_GNUCC)
        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)
+       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_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)
+       ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_POINTER_ARITH -Wpointer-arith)
+       ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNUSED_PARAMETER -Wunused-parameter)
+       ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_WRITE_STRINGS -Wwrite-strings)
+       ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_UNDEF -Wundef)
+       ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_FORMAT_SIGN -Wformat-signedness)
 
        # gcc 4.2 gives annoying warnings on every file with this
        if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "4.3")
@@ -2500,7 +2734,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)
@@ -2562,6 +2795,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
@@ -2605,6 +2839,22 @@ if(WITH_PYTHON)
        endif()
 endif()
 
+if(WITH_CPP11)
+       if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+               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()
+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
+       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
+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}")
@@ -2617,12 +2867,12 @@ mark_as_advanced(
        OSL_COMPILER
        OSL_LIB_COMP
        OSL_LIB_QUERY
-       OSL_INCLUDES
+       OSL_INCLUDE_DIR
 )
 
 mark_as_advanced(
        LLVM_CONFIG
-       LLVM_DIRECTORY
+       LLVM_ROOT_DIR
        LLVM_LIBRARY
        LLVM_VERSION
 )
@@ -2660,7 +2910,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()
@@ -2694,25 +2946,29 @@ include(build_files/cmake/packaging.cmake)
 # Print Final Configuration
 
 if(FIRST_RUN)
-       set(_config_msg "\n* Blender Configuration *")
-       macro(info_cfg_option
-               _setting)
-               set(_msg "   * ${_setting}")
+
+       set(_config_msg "\nBlender Configuration\n=====================")
+
+       function(info_cfg_option
+               _setting
+               )
+
+               set(_msg "  - ${_setting}")
                string(LENGTH "${_msg}" _len)
                while("32" GREATER "${_len}")
                        set(_msg "${_msg} ")
                         math(EXPR _len "${_len} + 1")
                endwhile()
 
-               set(_config_msg "${_config_msg}\n${_msg}${${_setting}}")
-       endmacro()
-
-       macro(info_cfg_text
-               _text)
-               set(_config_msg "${_config_msg}\n\n  ${_text}")
+               set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
+       endfunction()
 
+       function(info_cfg_text
+               _text
+               )
 
-       endmacro()
+               set(_config_msg "${_config_msg}\n\n  ${_text}" PARENT_SCOPE)
+       endfunction()
 
        message(STATUS "C Compiler:   \"${CMAKE_C_COMPILER_ID}\"")
        message(STATUS "C++ Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
@@ -2795,9 +3051,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}")