CMake: De-duplicate checks around unordered maps and shared pointer
[blender.git] / CMakeLists.txt
index 8e54ddc92745687bca6712d361d8daf2355da5c6..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,11 +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)
 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)" 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), 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()
@@ -221,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)
@@ -239,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)
@@ -261,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)
@@ -314,9 +347,11 @@ if(UNIX AND NOT APPLE)
 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)
@@ -327,7 +362,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)
@@ -350,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" ON)
-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)
@@ -407,7 +446,6 @@ option(WITH_GL_EGL              "Use the EGL OpenGL system library instead of th
 option(WITH_GL_PROFILE_COMPAT   "Support using the OpenGL 'compatibility' profile. (deprecated)"                                                    ON )
 option(WITH_GL_PROFILE_CORE     "Support using the OpenGL 3.2+ 'core' profile."                                                                     OFF)
 option(WITH_GL_PROFILE_ES20     "Support using OpenGL ES 2.0. (thru either EGL or the AGL/WGL/XGL 'es20' profile)"                                  OFF)
-option(WITH_GPU_DEBUG           "Create a debug OpenGL context (allows inserting custom messages and getting notifications for bad GL use)"         OFF)
 
 mark_as_advanced(
        WITH_GLEW_MX
@@ -416,7 +454,6 @@ mark_as_advanced(
        WITH_GL_PROFILE_COMPAT
        WITH_GL_PROFILE_CORE
        WITH_GL_PROFILE_ES20
-       WITH_GPU_DEBUG
 )
 
 if(WITH_GL_PROFILE_COMPAT)
@@ -435,7 +472,7 @@ 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()
@@ -444,6 +481,10 @@ endif()
 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()
 
@@ -454,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)
@@ -482,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)
@@ -499,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")
        
@@ -533,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
@@ -647,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
@@ -655,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)
@@ -670,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)
@@ -685,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.
@@ -742,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
@@ -786,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()
 
@@ -811,11 +892,19 @@ if(UNIX AND NOT APPLE)
                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)
@@ -846,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)
@@ -1045,75 +1141,30 @@ if(UNIX AND NOT APPLE)
                endif()
        endif()
 
-       # XXX Maybe most of this section should go into an llvm module?
        if(WITH_LLVM)
+               find_package_wrapper(LLVM)
 
-               if(LLVM_ROOT_DIR)
-                       if(NOT DEFINED LLVM_VERSION)
-                               find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION} HINTS ${LLVM_ROOT_DIR}/bin NO_CMAKE_PATH)
-                       endif()
-                       if(NOT LLVM_CONFIG)
-                               find_program(LLVM_CONFIG llvm-config HINTS ${LLVM_ROOT_DIR}/bin NO_CMAKE_PATH)
-                       endif()
-               else()
-                       if(NOT DEFINED LLVM_VERSION)
-                               find_program(LLVM_CONFIG llvm-config-${LLVM_VERSION})
-                       endif()
-                       if(NOT LLVM_CONFIG)
-                               find_program(LLVM_CONFIG llvm-config)
-                       endif()
+               if(NOT LLVM_FOUND)
+                       set(WITH_LLVM OFF)
+                       message(STATUS "LLVM not found")
                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_ROOT_DIR)
-                       execute_process(COMMAND ${LLVM_CONFIG} --prefix
-                                                       OUTPUT_VARIABLE LLVM_ROOT_DIR
-                                                       OUTPUT_STRIP_TRAILING_WHITESPACE)
-                       set(LLVM_ROOT_DIR ${LLVM_ROOT_DIR} 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(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'")
+       endif()
 
-               if(LLVM_STATIC)
-                       find_library(LLVM_LIBRARY
-                                    NAMES LLVMAnalysis # first of a whole bunch of libs to get
-                                    PATHS ${LLVM_LIBPATH})
-               else()
-                       find_library(LLVM_LIBRARY
-                                    NAMES LLVM-${LLVM_VERSION}
-                                    PATHS ${LLVM_LIBPATH})
-               endif()
+       if(WITH_OPENSUBDIV)
+               find_package_wrapper(OpenSubdiv)
 
+               set(OPENSUBDIV_LIBRARIES ${OPENSUBDIV_LIBRARIES})
+               set(OPENSUBDIV_LIBPATH)  # TODO, remove and reference the absolute path everywhere
 
-               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
-                               # 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 OPENSUBDIV_FOUND)
+                       set(WITH_OPENSUBDIV OFF)
+                       message(STATUS "OpenSubdiv 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")
        endif()
 
        # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
@@ -1142,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")
@@ -1209,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")
 
@@ -1242,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})
@@ -1280,9 +1344,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)
@@ -1394,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
@@ -1430,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}
@@ -1517,11 +1579,33 @@ 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_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
@@ -1541,12 +1625,7 @@ elseif(WIN32)
                
                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()
-                               set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
-                       endif()
+                       set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw64)
                else()
                        message(STATUS "Compiling for 32 bit with MinGW-w32.")
                        set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/mingw32)
@@ -1667,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)
@@ -1843,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
@@ -1861,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
@@ -2235,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()
 
@@ -2246,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.
@@ -2367,17 +2465,23 @@ if(WITH_GL_EGL)
        list(APPEND GL_DEFINITIONS -DWITH_EGL)
 endif()
 
-if(WITH_GPU_DEBUG)
-       list(APPEND GL_DEFINITIONS -DWITH_GPU_DEBUG)
-endif()
-
 #-----------------------------------------------------------------------------
 # Configure OpenMP.
 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()
@@ -2482,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
 
@@ -2489,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)
@@ -2507,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")
@@ -2519,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)
 
@@ -2534,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")
@@ -2562,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)
@@ -2624,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
@@ -2677,6 +2849,12 @@ if(WITH_CPP11)
        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}")
@@ -2732,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()
@@ -2766,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()
+               set(_config_msg "${_config_msg}\n${_msg}${${_setting}}" PARENT_SCOPE)
+       endfunction()
 
-       macro(info_cfg_text
-               _text)
-               set(_config_msg "${_config_msg}\n\n  ${_text}")
+       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}\"")
@@ -2863,14 +3047,10 @@ if(FIRST_RUN)
        info_cfg_option(WITH_GL_PROFILE_COMPAT)
        info_cfg_option(WITH_GL_PROFILE_CORE)
        info_cfg_option(WITH_GL_PROFILE_ES20)
-       info_cfg_option(WITH_GPU_DEBUG)
        if(WIN32)
                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}")