Merging trunk up to r38329.
[blender.git] / CMakeLists.txt
index ef8b8ef..f5ce397 100644 (file)
 # build the libs and objects in it.
 
 if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
-message(FATAL_ERROR "CMake generation for blender is not allowed within the source directory! 
-Remove the CMakeCache.txt file and try again from another folder, e.g.: 
-
-       rm CMakeCache.txt 
-       cd ..
-       mkdir cmake-make 
-       cd cmake-make
-       cmake ../blender
-")
+       if(NOT DEFINED WITH_IN_SOURCE_BUILD)
+               message(FATAL_ERROR
+                       "CMake generation for blender is not allowed within the source directory!"
+                       "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
+                       "\n "
+                       "\n rm CMakeCache.txt"
+                       "\n cd .."
+                       "\n mkdir cmake-make"
+                       "\n cd cmake-make"
+                       "\n cmake ../blender"
+                       "\n "
+                       "\n Alternately define WITH_IN_SOURCE_BUILD to force this option (not recommended!)"
+               )
+       endif()
 endif()
 
 cmake_minimum_required(VERSION 2.8)
 
+if(NOT EXECUTABLE_OUTPUT_PATH)
+       set(FIRST_RUN "TRUE")
+endif()
+
 # this starts out unset
-set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules/")
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build_files/cmake/Modules")
+
+# avoid having empty buildtype
+set(CMAKE_BUILD_TYPE_INIT "Release")
 
 # quiet output for Makefiles, 'make -s' helps too
 # set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
 
+#-----------------------------------------------------------------------------
+# Load some macros.
+include(build_files/cmake/macros.cmake)
+
+
+#-----------------------------------------------------------------------------
+# Initialize project.
+
+blender_project_hack_pre()
+
 project(Blender)
 
+blender_project_hack_post()
+
 enable_testing()
 
 #-----------------------------------------------------------------------------
@@ -60,10 +84,6 @@ enable_testing()
 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE INTERNAL "" FORCE )
 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "" FORCE )
 
-#-----------------------------------------------------------------------------
-# Load some macros.
-include(build_files/cmake/macros.cmake)
-
 #-----------------------------------------------------------------------------
 # Set default config options
 
@@ -71,8 +91,12 @@ get_blender_version()
 
 # Blender internal features
 option(WITH_INTERNATIONAL "Enable I18N (International fonts and text)" ON)
+
 option(WITH_PYTHON        "Enable Embedded Python API  (only disable for development)" ON)
+option(WITH_PYTHON_SECURITY "Disables execution of scripts within blend files by default (recommend to leave off)" OFF)
 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 distrobutions see this as a security issue, rather than have them patch it, make a build option.
+
 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 (experemental, only enable for development)" OFF)
 option(WITH_BUILDINFO     "Include extra build details (only disable for development & faster builds)" ON)
@@ -81,6 +105,13 @@ option(WITH_FFTW3         "Enable FFTW3 support (Used for smoke and audio effect
 option(WITH_BULLET        "Enable Bullet (Physics Engine)" ON)
 option(WITH_GAMEENGINE    "Enable Game Engine" ON)
 option(WITH_PLAYER        "Build Player" OFF)
+
+option(WITH_AUDASPACE    "Build with blenders audio library" ON)
+mark_as_advanced(WITH_AUDASPACE)
+
+option(WITH_HEADLESS      "Build without graphical support (renderfarm, server mode only)" OFF)
+mark_as_advanced(WITH_HEADLESS)
+
 # (unix defaults to OpenMP On)
 if(UNIX AND NOT APPLE)
        option(WITH_OPENMP        "Enable OpenMP (has to be supported by the compiler)" ON)
@@ -100,6 +131,8 @@ endif()
 option(WITH_MOD_FLUID          "Enable Elbeem Modifier (Fluid Simulation)" ON)
 option(WITH_MOD_DECIMATE               "Enable Decimate Modifier" ON)
 option(WITH_MOD_BOOLEAN                "Enable Boolean Modifier" ON)
+option(WITH_MOD_CLOTH_ELTOPO           "Enable Experemental cloth solver" OFF)
+mark_as_advanced(WITH_MOD_CLOTH_ELTOPO)
 
 # Image format support
 option(WITH_IMAGE_OPENEXR       "Enable OpenEXR Support (http://www.openexr.com)" ON)
@@ -111,7 +144,7 @@ option(WITH_IMAGE_HDR           "Enable HDR Image Support" ON)
 option(WITH_IMAGE_REDCODE       "Enable RedCode Image Support" OFF)
 
 # Audio/Video format support
-option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.mplayerhq.hu)" OFF)
+option(WITH_CODEC_FFMPEG        "Enable FFMPeg Support (http://ffmpeg.org)" OFF)
 option(WITH_CODEC_SNDFILE       "Enable libsndfile Support (http://www.mega-nerd.com/libsndfile)" OFF)
 if(APPLE OR (WIN32 AND NOT UNIX))
        option(WITH_CODEC_QUICKTIME     "Enable Quicktime Support" OFF)
@@ -138,6 +171,10 @@ if(UNIX AND NOT APPLE)
 endif()
 option(WITH_PYTHON_INSTALL       "Copy system python into the blender install folder" ON)
 
+# disable for now, but plan to support on all platforms eventually
+option(WITH_MEM_JEMALLOC   "Enable malloc replacement (http://www.canonware.com/jemalloc)" OFF)
+mark_as_advanced(WITH_MEM_JEMALLOC)
+
 # Debug
 option(WITH_CXX_GUARDEDALLOC "Enable GuardedAlloc for C++ memory allocation tracking (only enable for development)" OFF)
 mark_as_advanced(WITH_CXX_GUARDEDALLOC)
@@ -161,15 +198,15 @@ if(APPLE)
        option(WITH_LIBS10.5  "Use 10.5 libs (needed for 64bit builds)" OFF)
 endif()
 
-# only for developers who want to make this functional
-# option(WITH_LCMS          "Enable color correction with lcms" OFF)
+#-----------------------------------------------------------------------------
+# Check for conflicting/unsupported configurations
 
 if(NOT WITH_GAMEENGINE AND WITH_PLAYER)
        message(FATAL_ERROR "WITH_PLAYER requires WITH_GAMEENGINE")
 endif()
 
-if(NOT WITH_SAMPLERATE AND (WITH_OPENAL OR WITH_SDL OR WITH_JACK))
-       message(FATAL_ERROR "WITH_OPENAL/WITH_SDL/WITH_JACK require WITH_SAMPLERATE")
+if(NOT WITH_AUDASPACE AND (WITH_OPENAL OR WITH_SDL OR WITH_JACK))
+       message(FATAL_ERROR "WITH_OPENAL/WITH_SDL/WITH_JACK/WITH_CODEC_FFMPEG require WITH_AUDASPACE")
 endif()
 
 if(NOT WITH_IMAGE_OPENJPEG AND WITH_IMAGE_REDCODE)
@@ -185,8 +222,16 @@ if(WITH_PYTHON_MODULE AND WITH_PYTHON_INSTALL)
        message(FATAL_ERROR "WITH_PYTHON_MODULE requires WITH_PYTHON_INSTALL to be OFF")
 endif()
 
-# remove old vars
-unset(WITH_INSTALL CACHE)
+if(WITH_CODEC_QUICKTIME AND MINGW)
+       message(FATAL_ERROR "MINGW requires WITH_CODEC_QUICKTIME to be OFF "
+                                               "because it is currently unsupported, remove this "
+                                               "line if youre a developer who wants to add support.")
+endif()
+
+# may as well build python module without a UI
+if(WITH_PYTHON_MODULE)
+       set(WITH_HEADLESS ON)
+endif()
 
 TEST_SSE_SUPPORT()
 
@@ -196,9 +241,25 @@ TEST_SSE_SUPPORT()
 # linux only, not cached
 set(WITH_BINRELOC OFF)
 
+# MAXOSX only, set to avoid uninitialized 
+set(EXETYPE)
+
+# C/C++ flags
+set(PLATFORM_CFLAGS)
+
 # these are added to later on.
-set(C_WARNINGS "")
-set(CXX_WARNINGS "")
+set(C_WARNINGS)
+set(CXX_WARNINGS)
+
+# libraries to link the binary with passed to target_link_libraries()
+# known as LLIBS to scons
+set(PLATFORM_LINKLIBS)
+
+# Added to linker flags in setup_liblinks
+# - CMAKE_EXE_LINKER_FLAGS
+# - CMAKE_EXE_LINKER_FLAGS_DEBUG
+set(PLATFORM_LINKFLAGS)
+set(PLATFORM_LINKFLAGS_DEBUG)
 
 
 # disabled for now, not supported
@@ -208,13 +269,12 @@ set(CXX_WARNINGS "")
 # On Unix: 
 #   cmake ../blender \
 #         -D PYTHON_VERSION=3.2 \
-#         -D PYTHON_INCLUDE_DIRS=/opt/py32/include/python3.2d \
-#         -D PYTHON_LIBPATH=/opt/py32/lib \
-#         -D PYTHON_LIBRARY=python3.2d
+#         -D PYTHON_INCLUDE_DIR=/opt/py32/include/python3.2d \
+#         -D PYTHON_LIBRARY=/opt/py32/lib/libpython3.2d.so
 #
 # On Macs: 
 #   cmake ../blender \
-#         -D PYTHON_INCLUDE_DIRS=/System/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2 \
+#         -D PYTHON_INCLUDE_DIR=/System/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2 \
 #         -D PYTHON_LIBPATH=/System/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/config \
 #         -G Xcode
 #
@@ -230,65 +290,48 @@ if(UNIX AND NOT APPLE)
                set(CMAKE_LIBRARY_PATH "/usr/lib/x86_64-linux-gnu;${CMAKE_LIBRARY_PATH}")
        endif()
 
-       if(WITH_OPENAL)
-               find_package(OpenAL)
-               if(NOT OPENAL_FOUND)
-                       set(WITH_OPENAL OFF)
-               endif()
-       endif()
+       find_package(JPEG REQUIRED)
+       find_package(PNG REQUIRED)
+       find_package(ZLIB REQUIRED)
+       find_package(Freetype REQUIRED)
 
-       if(WITH_JACK)
-               set(JACK /usr)
-               set(JACK_INC ${JACK}/include/jack)
-               set(JACK_LIB jack)
-               set(JACK_LIBPATH ${JACK}/lib)
-       endif()
+       if(WITH_PYTHON)
+               # No way to set py32. remove for now.
+               # find_package(PythonLibs)
 
-       if(WITH_CODEC_SNDFILE)
-               set(SNDFILE /usr)
-               set(SNDFILE_INC ${SNDFILE}/include)
-               set(SNDFILE_LIB sndfile)
-               set(SNDFILE_LIBPATH ${SNDFILE}/lib)
+               # Use our own instead, since wothout py is such a rare case,
+               # require this package
+               find_package(PythonLibsUnix REQUIRED)
        endif()
 
-       if(WITH_INTERNATIONAL)
-               find_library(INTL_LIBRARY
-                       NAMES intl
-                       PATHS
-                       /sw/lib
-               )
 
-               find_library(ICONV_LIBRARY
-                       NAMES iconv
-                       PATHS
-                       /sw/lib
-               )
-               mark_as_advanced(ICONV_LIBRARY)
-               mark_as_advanced(INTL_LIBRARY)
-
-               if(INTL_LIBRARY AND ICONV_LIBRARY)
-                       set(GETTEXT_LIB ${INTL_LIBRARY} ${ICONV_LIBRARY})
+       if(WITH_IMAGE_OPENEXR)
+               find_package(OpenEXR)  # our own module
+               if(NOT OPENEXR_FOUND)
+                       set(WITH_IMAGE_OPENEXR OFF)
                endif()
        endif()
 
-       find_package(Freetype)
-       # unset(FREETYPE_INCLUDE_DIRS CACHE) # cant use
-
-
-       if(WITH_PYTHON)
-               # No way to set py32. remove for now.
-               # find_package(PythonLibs)
-
-               # defines...
-               
-               #  PYTHON_VERSION
-               #  PYTHON_INCLUDE_DIRS
-               #  PYTHON_LIBRARY
-               #  PYTHON_LIBPATH
-               #  PYTHON_LINKFLAGS
+       if(WITH_IMAGE_OPENJPEG)
+               find_package(OpenJPEG)
+               if(NOT OPENJPEG_FOUND)
+                       set(WITH_IMAGE_OPENJPEG OFF)
+               endif()
+       endif()
 
-               include(build_files/cmake/FindPythonLibsUnix.cmake)
+       if(WITH_IMAGE_TIFF)
+               find_package(TIFF)
+               if(NOT TIFF_FOUND)
+                       set(WITH_IMAGE_TIFF OFF)
+               endif()
+       endif()
 
+       # Audio IO
+       if(WITH_OPENAL)
+               find_package(OpenAL)
+               if(NOT OPENAL_FOUND)
+                       set(WITH_OPENAL OFF)
+               endif()
        endif()
 
        if(WITH_SDL)
@@ -303,109 +346,111 @@ if(UNIX AND NOT APPLE)
                endif()
        endif()
 
-       if(WITH_IMAGE_OPENEXR)
-               set(OPENEXR /usr CACHE FILEPATH "OPENEXR Directory")
-               mark_as_advanced(OPENEXR)
-               find_path(OPENEXR_INC
-                       ImfXdr.h
-                       PATHS
-                       ${OPENEXR}/include/OpenEXR
-                       /usr/local/include/OpenEXR
-                       /sw/include/OpenEXR
-                       /opt/local/include/OpenEXR
-                       /opt/csw/include/OpenEXR
-                       /opt/include/OpenEXR
-               )
-               mark_as_advanced(OPENEXR_INC)
-
-               set(OPENEXR_LIB Half IlmImf Iex Imath)
-               
-               if(NOT OPENEXR_INC)
-                       set(WITH_IMAGE_OPENEXR OFF)
+       if(WITH_JACK)
+               find_package(Jack)
+               if(NOT JACK_FOUND)
+                       set(WITH_JACK OFF)
                endif()
        endif()
 
-       if(WITH_IMAGE_TIFF)
-               find_package(TIFF)
-               if(NOT TIFF_FOUND)
-                       set(WITH_IMAGE_TIFF OFF)
+       # Codecs
+       if(WITH_CODEC_SNDFILE)
+               find_package(SndFile)
+               if(NOT SNDFILE_FOUND)
+                       set(WITH_CODEC_SNDFILE OFF)
                endif()
        endif()
 
-       find_package(JPEG REQUIRED)
-
-       find_package(PNG REQUIRED)
-
-       find_package(ZLIB REQUIRED)
-
-       if(WITH_LCMS)
-               set(LCMS /usr CACHE FILEPATH "LCMS directory")
-               set(LCMS_INCLUDE_DIR ${LCMS}/include)
-               set(LCMS_LIBRARY lcms)
-               set(LCMS_LIBPATH ${LCMS}/lib)
-       endif()
-
        if(WITH_CODEC_FFMPEG)
-               set(FFMPEG /usr CACHE FILEPATH "FFMPEG Directory")
+               set(FFMPEG /usr CACHE PATH "FFMPEG Directory")
                mark_as_advanced(FFMPEG)
-               set(FFMPEG_INC ${FFMPEG}/include)
-               set(FFMPEG_LIB avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
-               mark_as_advanced(FFMPEG_LIB)
+               set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
+               set(FFMPEG_LIBRARIES avformat avcodec avutil avdevice swscale CACHE STRING "FFMPEG Libraries")
+               mark_as_advanced(FFMPEG_LIBRARIES)
                set(FFMPEG_LIBPATH ${FFMPEG}/lib)
                set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
        endif()
 
+       if(WITH_INTERNATIONAL)
+               find_library(INTL_LIBRARY
+                       NAMES intl
+                       PATHS
+                       /sw/lib
+               )
+
+               find_library(ICONV_LIBRARY
+                       NAMES iconv
+                       PATHS
+                       /sw/lib
+               )
+               mark_as_advanced(ICONV_LIBRARY)
+               mark_as_advanced(INTL_LIBRARY)
+
+               if(INTL_LIBRARY AND ICONV_LIBRARY)
+                       set(GETTEXT_LIB ${INTL_LIBRARY} ${ICONV_LIBRARY})
+               endif()
+       endif()
+
        if(WITH_FFTW3)
-               set(FFTW3 /usr)
-               set(FFTW3_INC ${FFTW3}/include)
-               set(FFTW3_LIB fftw3)
-               set(FFTW3_LIBPATH ${FFTW3}/lib)
+               find_package(Fftw3)
+               if(NOT FFTW3_FOUND)
+                       set(WITH_FFTW3 OFF)
+               endif()
        endif()
 
        if(WITH_SAMPLERATE)
-               set(LIBSAMPLERATE /usr)
-               set(LIBSAMPLERATE_INC ${LIBSAMPLERATE}/include)
-               set(LIBSAMPLERATE_LIB samplerate)
-               set(LIBSAMPLERATE_LIBPATH ${LIBSAMPLERATE}/lib)
+               find_package(Samplerate)
+               if(NOT SAMPLERATE_FOUND)
+                       set(WITH_SAMPLERATE OFF)
+               endif()
        endif()
 
        if(WITH_OPENCOLLADA)
-               set(OPENCOLLADA /usr/local/opencollada CACHE FILEPATH "OpenCollada Directory")
+               set(OPENCOLLADA /usr/local/opencollada CACHE PATH "OpenCollada Directory")
                mark_as_advanced(OPENCOLLADA)
                set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
-               set(OPENCOLLADA_LIB OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre ftoa buffer xml2)
-               set(OPENCOLLADA_INC ${OPENCOLLADA})
+               set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre ftoa buffer xml2)
+               set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA})
 
-               set(PCRE /usr CACHE FILEPATH "PCRE Directory")
+               set(PCRE /usr CACHE PATH "PCRE Directory")
                mark_as_advanced(PCRE)
                set(PCRE_LIBPATH ${PCRE}/lib)
                set(PCRE_LIB pcre)
 
-               set(EXPAT /usr CACHE FILEPATH "Expat Directory")
+               set(EXPAT /usr CACHE PATH "Expat Directory")
                mark_as_advanced(EXPAT)
                set(EXPAT_LIBPATH ${EXPAT}/lib)
                set(EXPAT_LIB expat)
        endif()
 
-       find_package(X11 REQUIRED)
-       find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
-       mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
+       if(WITH_MEM_JEMALLOC)
+               find_package(JeMalloc)
+               if(NOT JEMALLOC_FOUND)
+                       set(WITH_MEM_JEMALLOC OFF)
+               endif()
+       endif()
 
        # OpenSuse needs lutil, ArchLinux not, for now keep, can avoid by using --as-needed
-       set(LLIBS "-lutil -lc -lm -lpthread -lstdc++ ${X11_X11_LIB}")
+       set(PLATFORM_LINKLIBS "-lutil -lc -lm -lpthread -lstdc++")
+
+       if(NOT WITH_HEADLESS)
+               find_package(X11 REQUIRED)
+               find_path(X11_XF86keysym_INCLUDE_PATH X11/XF86keysym.h ${X11_INC_SEARCH_PATH})
+               mark_as_advanced(X11_XF86keysym_INCLUDE_PATH)
 
-       if(WITH_X11_XINPUT)
-               list(APPEND LLIBS ${X11_Xinput_LIB})
+               list(APPEND PLATFORM_LINKLIBS ${X11_X11_LIB})
+
+               if(WITH_X11_XINPUT)
+                       list(APPEND PLATFORM_LINKLIBS ${X11_Xinput_LIB})
+               endif()
        endif()
 
        if(CMAKE_SYSTEM_NAME MATCHES "Linux")
                if(NOT WITH_PYTHON_MODULE)
                        # BSD's dont use libdl.so
-                       list(APPEND LLIBS -ldl)
-
+                       list(APPEND PLATFORM_LINKLIBS -ldl)
                        # binreloc is linux only
-                       set(BINRELOC ${CMAKE_SOURCE_DIR}/extern/binreloc)
-                       set(BINRELOC_INC ${BINRELOC}/include)
+                       set(BINRELOC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/binreloc/include)
                        set(WITH_BINRELOC ON)
                endif()
        endif()
@@ -458,16 +503,16 @@ elseif(WIN32)
 
        if(WITH_INTERNATIONAL)
                set(ICONV ${LIBDIR}/iconv)
-               set(ICONV_INC ${ICONV}/include)
-               set(ICONV_LIB iconv)
+               set(ICONV_INCLUDE_DIRS ${ICONV}/include)
+               set(ICONV_LIBRARIES iconv)
                set(ICONV_LIBPATH ${ICONV}/lib)
        endif()
 
        if(WITH_SAMPLERATE)
-               set(LIBSAMPLERATE ${LIBDIR}/samplerate)
-               set(LIBSAMPLERATE_INC ${LIBSAMPLERATE}/include)
-               set(LIBSAMPLERATE_LIB libsamplerate)
-               set(LIBSAMPLERATE_LIBPATH ${LIBSAMPLERATE}/lib)
+               set(SAMPLERATE ${LIBDIR}/samplerate)
+               set(SAMPLERATE_INCLUDE_DIRS ${SAMPLERATE}/include)
+               set(SAMPLERATE_LIBRARIES libsamplerate)
+               set(SAMPLERATE_LIBPATH ${SAMPLERATE}/lib)
        endif()
 
        set(PNG "${LIBDIR}/png")
@@ -489,9 +534,9 @@ elseif(WIN32)
 
        if(WITH_CODEC_SNDFILE)
                set(SNDFILE ${LIBDIR}/sndfile)
-               set(SNDFILE_INC ${SNDFILE}/include)
-               set(SNDFILE_LIB libsndfile-1)
-               set(SNDFILE_LIBPATH ${SNDFILE}/lib)
+               set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
+               set(SNDFILE_LIBRARIES libsndfile-1)
+               set(SNDFILE_LIBPATH ${SNDFILE}/lib) # TODO, deprecate
        endif()
 
        if(WITH_SDL)
@@ -503,8 +548,8 @@ elseif(WIN32)
 
        if(WITH_CODEC_QUICKTIME)
                set(QUICKTIME ${LIBDIR}/QTDevWin)
-               set(QUICKTIME_INC ${QUICKTIME}/CIncludes)
-               set(QUICKTIME_LIB qtmlClient)
+               set(QUICKTIME_INCLUDE_DIRS ${QUICKTIME}/CIncludes)
+               set(QUICKTIME_LIBRARIES qtmlClient)
                set(QUICKTIME_LIBPATH ${QUICKTIME}/Libraries)
        endif()
 
@@ -514,13 +559,15 @@ elseif(WIN32)
 
        if(MSVC)
                if(CMAKE_CL_64)
-                       set(LLIBS kernel32 user32 vfw32 winmm ws2_32 )
+                       set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
                else()
-                       set(LLIBS kernel32 user32 gdi32 comdlg32 advapi32 shell32 ole32 oleaut32 uuid ws2_32 vfw32 winmm)
+                       set(PLATFORM_LINKLIBS ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 advapi32 shfolder shell32 ole32 oleaut32 uuid)
                endif()
-               
-               set(CMAKE_CXX_FLAGS "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /we4013 /wd4018 /wd4800 /wd4244 /wd4305 /wd4065 /wd4267" CACHE STRING "MSVC MT C++ flags " FORCE)
-               set(CMAKE_C_FLAGS   "/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /we4013 /wd4018 /wd4800 /wd4244 /wd4305 /wd4065 /wd4267" CACHE STRING "MSVC MT C++ flags " FORCE)
+
+               add_definitions(/D_CRT_NONSTDC_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_CONSOLE /D_LIB)
+
+               set(CMAKE_CXX_FLAGS "/nologo /J /W0 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013" CACHE STRING "MSVC MT C++ flags " FORCE)
+               set(CMAKE_C_FLAGS   "/nologo /J /W0 /Gd /wd4018 /wd4244 /wd4305 /wd4800 /wd4065 /wd4267 /we4013 /EHsc" CACHE STRING "MSVC MT C++ flags " FORCE)
 
                if(CMAKE_CL_64)
                        set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /Od /Gm /EHsc /RTC1 /MTd /W3 /nologo /Zi /J" CACHE STRING "MSVC MT flags " FORCE)
@@ -557,59 +604,67 @@ elseif(WIN32)
                endif()
                set(JPEG_LIBRARIES libjpeg)
 
-               set(ZLIB ${LIBDIR}/zlib)
-               set(ZLIB_INCLUDE_DIRS ${ZLIB}/include)
-               set(ZLIB_LIBPATH ${ZLIB}/lib)
+               set(ZLIB_INCLUDE_DIRS ${LIBDIR}/zlib/include)
                if(CMAKE_CL_64)
-                       set(ZLIB_LIBRARIES libz)
+                       set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/libz.lib)
                else()
-                       set(ZLIB_LIBRARIES zlib)
+                       set(ZLIB_LIBRARIES ${LIBDIR}/zlib/lib/zlib.lib)
                endif()
 
-               set(PTHREADS ${LIBDIR}/pthreads)
-               set(PTHREADS_INC ${PTHREADS}/include)
-               set(PTHREADS_LIBPATH ${PTHREADS}/lib)
-               set(PTHREADS_LIB pthreadVC2)
-               
+               set(PTHREADS_INCLUDE_DIRS ${LIBDIR}/pthreads/include)
+               set(PTHREADS_LIBRARIES ${LIBDIR}/pthreads/lib/pthreadVC2.lib)
+
                set(FREETYPE ${LIBDIR}/freetype)
-               set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
-               set(FREETYPE_LIBPATH ${FREETYPE}/lib)
-               set(FREETYPE_LIBRARY freetype2ST)
+               set(FREETYPE_INCLUDE_DIRS
+                       ${LIBDIR}/freetype/include
+                       ${LIBDIR}/freetype/include/freetype2
+               )
+               set(FREETYPE_LIBRARY ${LIBDIR}/freetype/lib/freetype2ST.lib)
 
                if(WITH_FFTW3)
                        set(FFTW3 ${LIBDIR}/fftw3)
-                       set(FFTW3_LIB libfftw)
-                       set(FFTW3_INC ${FFTW3}/include)
+                       set(FFTW3_LIBRARIES libfftw)
+                       set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
                        set(FFTW3_LIBPATH ${FFTW3}/lib)
                endif()
 
                if(WITH_OPENCOLLADA)
-                       set(OPENCOLLADA ${LIBDIR}/opencollada)
-                       set(OPENCOLLADA_INC ${OPENCOLLADA}/include)
-                       set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
-                       set(OPENCOLLADA_LIB OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils OpenCOLLADAStreamWriter MathMLSolver GeneratedSaxParser xml2 buffer ftoa UTF)
-                       set(PCRE_LIB pcre)
-               endif()
-               
-               if(WITH_LCMS)
-                       set(LCMS ${LIBDIR}/lcms)
-                       set(LCMS_INCLUDE_DIR ${LCMS}/include)
-                       set(LCMS_LIBPATH ${LCMS}/lib)
-                       set(LCMS_LIB lcms)
+                       set(OPENCOLLADA_INCLUDE_DIR
+                               ${LIBDIR}/opencollada/include
+                       )
+                       set(OPENCOLLADA_LIBRARIES
+                               ${LIBDIR}/opencollada/lib/OpenCOLLADASaxFrameworkLoader.lib
+                               ${LIBDIR}/opencollada/lib/OpenCOLLADAFramework.lib
+                               ${LIBDIR}/opencollada/lib/OpenCOLLADABaseUtils.lib
+                               ${LIBDIR}/opencollada/lib/OpenCOLLADAStreamWriter.lib
+                               ${LIBDIR}/opencollada/lib/MathMLSolver.lib
+                               ${LIBDIR}/opencollada/lib/GeneratedSaxParser.lib
+                               ${LIBDIR}/opencollada/lib/xml2.lib
+                               ${LIBDIR}/opencollada/lib/buffer.lib
+                               ${LIBDIR}/opencollada/lib/ftoa.lib
+                               ${LIBDIR}/opencollada/lib/UTF.lib
+                       )
+                       set(PCRE_LIB
+                               ${LIBDIR}/opencollada/lib/pcre.lib
+                       )
                endif()
 
                if(WITH_CODEC_FFMPEG)
-                       set(FFMPEG ${LIBDIR}/ffmpeg)
-                       set(FFMPEG_INC ${FFMPEG}/include ${FFMPEG}/include/msvc)
-                       set(FFMPEG_LIB avcodec-52 avformat-52 avdevice-52 avutil-50 swscale-0)
-                       set(FFMPEG_LIBPATH ${FFMPEG}/lib)
+                       set(FFMPEG_INCLUDE_DIRS
+                               ${LIBDIR}/ffmpeg/include
+                               ${LIBDIR}/ffmpeg/include/msvc
+                       )
+                       set(FFMPEG_LIBRARIES
+                               ${LIBDIR}/ffmpeg/lib/avcodec-52.lib
+                               ${LIBDIR}/ffmpeg/lib/avformat-52.lib
+                               ${LIBDIR}/ffmpeg/lib/avdevice-52.lib
+                               ${LIBDIR}/ffmpeg/lib/avutil-50.lib
+                               ${LIBDIR}/ffmpeg/lib/swscale-0.lib
+                       )
                endif()
 
                if(WITH_IMAGE_OPENEXR)
-                       if(MSVC80)
-                               set(MSVC_LIB _vs2005)
-                               set(MSVC_INC)
-                       elseif(MSVC90)
+                       if(MSVC90)
                                set(MSVC_LIB _vs2008)
                                set(MSVC_INC)
                        elseif(MSVC10)
@@ -619,53 +674,64 @@ elseif(WIN32)
                                set(MSVC_LIB msvc)
                                set(MSVC_INC)
                        endif()
-                       set(OPENEXR ${LIBDIR}/openexr)                  
-                       set(OPENEXR_LIB Iex Half IlmImf Imath IlmThread)
+                       set(OPENEXR ${LIBDIR}/openexr)
                        set(OPENEXR_LIBPATH ${OPENEXR}/lib${MSVC_LIB})
+                       set(OPENEXR_LIBRARIES
+                               ${OPENEXR_LIBPATH}/Iex.lib
+                               ${OPENEXR_LIBPATH}/Half.lib
+                               ${OPENEXR_LIBPATH}/IlmImf.lib
+                               ${OPENEXR_LIBPATH}/Imath.lib
+                               ${OPENEXR_LIBPATH}/IlmThread.lib
+                       )
                        set(OPENEXR_INCUDE ${OPENEXR}/include${MSVC_INC})
-                       set(OPENEXR_INC ${OPENEXR_INCUDE}/ ${OPENEXR_INCUDE}/IlmImf ${OPENEXR_INCUDE}/Iex ${OPENEXR_INCUDE}/Imath)
+                       set(OPENEXR_INCLUDE_DIRS
+                               ${OPENEXR_INCUDE}
+                               ${OPENEXR_INCUDE}/IlmImf
+                               ${OPENEXR_INCUDE}/Iex
+                               ${OPENEXR_INCUDE}/Imath
+                       )
+                       unset(OPENEXR_INCUDE)
+                       unset(OPENEXR_LIBPATH)
                endif()
 
                if(WITH_IMAGE_TIFF)
-                       set(TIFF ${LIBDIR}/tiff)
-                       set(TIFF_LIBRARY libtiff)
-                       set(TIFF_INCLUDE_DIR ${TIFF}/include)
-                       set(TIFF_LIBPATH ${TIFF}/lib)
+                       set(TIFF_LIBRARY ${LIBDIR}/tiff/lib/libtiff.lib)
+                       set(TIFF_INCLUDE_DIR ${LIBDIR}/tiff/include)
                endif()
 
                if(WITH_JACK)
-                       set(JACK ${LIBDIR}/jack)
-                       set(JACK_INC ${JACK}/include/jack ${JACK}/include)
-                       set(JACK_LIB libjack)
-                       set(JACK_LIBPATH ${JACK}/lib)
+                       set(JACK_INCLUDE_DIRS
+                               ${LIBDIR}/jack/include/jack
+                               ${LIBDIR}/jack/include
+                       )
+                       set(JACK_LIBRARIES ${LIBDIR}/jack/lib/libjack.lib)
                endif()
 
                if(WITH_PYTHON)
-                       set(PYTHON ${LIBDIR}/python)
                        set(PYTHON_VERSION 3.2)
-                       set(PYTHON_INCLUDE_DIRS "${PYTHON}/include/python${PYTHON_VERSION}")
+                       set(PYTHON_INCLUDE_DIRS "${LIBDIR}/python/include/python${PYTHON_VERSION}")
                        # set(PYTHON_BINARY python) # not used yet
-                       set(PYTHON_LIBRARY python32)
-                       set(PYTHON_LIBPATH ${PYTHON}/lib)
+                       set(PYTHON_LIBRARIES ${LIBDIR}/python/lib/python32.lib)
                endif()
 
+               set(PLATFORM_LINKFLAGS "/SUBSYSTEM:CONSOLE /STACK:2097152 /INCREMENTAL:NO /NODEFAULTLIB:msvcrt.lib /NODEFAULTLIB:msvcmrt.lib /NODEFAULTLIB:msvcurt.lib /NODEFAULTLIB:msvcrtd.lib")
+
                # MSVC only, Mingw doesnt need
                if(CMAKE_CL_64)
-                       set(PLATFORM_LINKFLAGS "/MACHINE:X64 /NODEFAULTLIB:libc.lib /STACK:2097152 ")
+                       set(PLATFORM_LINKFLAGS "/MACHINE:X64 /OPT:NOREF ${PLATFORM_LINKFLAGS}")
                else()
-                       set(PLATFORM_LINKFLAGS "/NODEFAULTLIB:libc.lib /STACK:2097152 ")
+                       set(PLATFORM_LINKFLAGS "/MACHINE:IX86 /LARGEADDRESSAWARE ${PLATFORM_LINKFLAGS}")
                endif()
 
-               set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib;libc.lib ")
+               set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
 
        else()
                # keep GCC spesific stuff here
                if(CMAKE_COMPILER_IS_GNUCC)
-                       set(LLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid")
+                       set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid")
                        set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")
 
-                       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE")
-                       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE")
+                       add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
                endif()
 
                add_definitions(-DFREE_WINDOWS)
@@ -689,9 +755,9 @@ elseif(WIN32)
                set(ZLIB_LIBRARIES z)
 
                set(PTHREADS ${LIBDIR}/pthreads)
-               set(PTHREADS_INC ${PTHREADS}/include)
+               set(PTHREADS_INCLUDE_DIRS ${PTHREADS}/include)
                set(PTHREADS_LIBPATH ${PTHREADS}/lib)
-               set(PTHREADS_LIB pthreadGC2)
+               set(PTHREADS_LIBRARIES pthreadGC2)
                
                set(FREETYPE ${LIBDIR}/gcc/freetype)
                set(FREETYPE_INCLUDE_DIRS ${FREETYPE}/include ${FREETYPE}/include/freetype2)
@@ -700,34 +766,31 @@ elseif(WIN32)
 
                if(WITH_FFTW3)
                        set(FFTW3 ${LIBDIR}/gcc/fftw3)
-                       set(FFTW3_LIB fftw3)
-                       set(FFTW3_INC ${FFTW3}/include)
+                       set(FFTW3_LIBRARIES fftw3)
+                       set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
                        set(FFTW3_LIBPATH ${FFTW3}/lib)
                endif()
 
                if(WITH_OPENCOLLADA)
                        set(OPENCOLLADA ${LIBDIR}/gcc/opencollada)
-                       set(OPENCOLLADA_INC ${OPENCOLLADA}/include)
+                       set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}/include)
                        set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib ${OPENCOLLADA}/lib)
-                       set(OPENCOLLADA_LIB OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
+                       set(OPENCOLLADA_LIBRARIES OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver expat pcre buffer ftoa)
                        set(PCRE_LIB pcre)
                endif()
                
                if(WITH_CODEC_FFMPEG)
                        set(FFMPEG ${LIBDIR}/ffmpeg)
-                       set(FFMPEG_INC ${FFMPEG}/include ${FFMPEG}/include)
-                       set(FFMPEG_LIB avcodec-52 avformat-52 avdevice-52 avutil-50 swscale-0)
+                       set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include ${FFMPEG}/include)
+                       set(FFMPEG_LIBRARIES avcodec-52 avformat-52 avdevice-52 avutil-50 swscale-0)
                        set(FFMPEG_LIBPATH ${FFMPEG}/lib)
                endif()
 
                if(WITH_IMAGE_OPENEXR)
                        set(OPENEXR ${LIBDIR}/gcc/openexr)
-                       set(OPENEXR_INC ${OPENEXR}/include ${OPENEXR}/include/OpenEXR)
-                       set(OPENEXR_LIB Half IlmImf Imath IlmThread)
+                       set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
+                       set(OPENEXR_LIBRARIES Half IlmImf Imath IlmThread Iex)
                        set(OPENEXR_LIBPATH ${OPENEXR}/lib)
-
-                       # TODO, gives linking errors, force off
-                       set(WITH_IMAGE_OPENEXR OFF)
                endif()
 
                if(WITH_IMAGE_TIFF)
@@ -739,8 +802,8 @@ elseif(WIN32)
 
                if(WITH_JACK)
                        set(JACK ${LIBDIR}/jack)
-                       set(JACK_INC ${JACK}/include/jack ${JACK}/include)
-                       set(JACK_LIB jack)
+                       set(JACK_INCLUDE_DIRS ${JACK}/include/jack ${JACK}/include)
+                       set(JACK_LIBRARIES jack)
                        set(JACK_LIBPATH ${JACK}/lib)
                        
                        # TODO, gives linking errors, force off
@@ -752,7 +815,7 @@ elseif(WIN32)
                        set(PYTHON_VERSION 3.2)
                        set(PYTHON_INCLUDE_DIRS "${PYTHON}/include/python${PYTHON_VERSION}")
                        # set(PYTHON_BINARY python) # not used yet
-                       set(PYTHON_LIBRARY python32mw)
+                       set(PYTHON_LIBRARIES ${PYTHON}/lib/python32mw.lib)
                        set(PYTHON_LIBPATH ${PYTHON}/lib)
                endif()
 
@@ -761,7 +824,7 @@ elseif(WIN32)
        endif()
 
        # used in many places so include globally, like OpenGL
-       blender_include_dirs("${PTHREADS_INC}")
+       blender_include_dirs("${PTHREADS_INCLUDE_DIRS}")
 
 elseif(APPLE)
 
@@ -792,16 +855,16 @@ elseif(APPLE)
 
        if(WITH_JACK)
                set(JACK /usr)
-               set(JACK_INC ${JACK}/include/jack)
-               set(JACK_LIB jack)
+               set(JACK_INCLUDE_DIRS ${JACK}/include/jack)
+               set(JACK_LIBRARIES jack)
                set(JACK_LIBPATH ${JACK}/lib)
        endif()
 
        if(WITH_CODEC_SNDFILE)
                set(SNDFILE ${LIBDIR}/sndfile)
-               set(SNDFILE_INC ${SNDFILE}/include)
-               set(SNDFILE_LIB sndfile FLAC ogg vorbis vorbisenc)
-               set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)
+               set(SNDFILE_INCLUDE_DIRS ${SNDFILE}/include)
+               set(SNDFILE_LIBRARIES sndfile FLAC ogg vorbis vorbisenc)
+               set(SNDFILE_LIBPATH ${SNDFILE}/lib ${FFMPEG}/lib)  # TODO, deprecate
        endif()
 
        set(PYTHON_VERSION 3.2)
@@ -812,7 +875,7 @@ elseif(APPLE)
                set(PYTHON ${LIBDIR}/python)
                set(PYTHON_INCLUDE_DIRS "${PYTHON}/include/python${PYTHON_VERSION}")
                # set(PYTHON_BINARY "${PYTHON}/bin/python${PYTHON_VERSION}") # not used yet
-               set(PYTHON_LIBRARY python${PYTHON_VERSION})
+               set(PYTHON_LIBRARIES python${PYTHON_VERSION})
                set(PYTHON_LIBPATH "${PYTHON}/lib/python${PYTHON_VERSION}")
                # set(PYTHON_LINKFLAGS "-u _PyMac_Error")  # won't  build with this enabled
        else()
@@ -822,7 +885,7 @@ elseif(APPLE)
                set(PYTHON_VERSION 3.2)
                set(PYTHON_INCLUDE_DIRS "${PYTHON}${PYTHON_VERSION}/include/python${PYTHON_VERSION}")
                # set(PYTHON_BINARY ${PYTHON}${PYTHON_VERSION}/bin/python${PYTHON_VERSION}) # not used yet
-               set(PYTHON_LIBRARY "")
+               set(PYTHON_LIBRARIES "")
                set(PYTHON_LIBPATH ${PYTHON}${PYTHON_VERSION}/lib/python${PYTHON_VERSION}/config)
                set(PYTHON_LINKFLAGS "-u _PyMac_Error -framework System -framework Python")
        endif()
@@ -833,11 +896,11 @@ elseif(APPLE)
                set(GETTEXT_LIB intl iconv)
                set(GETTEXT_LIBPATH ${GETTEXT}/lib)
        endif()
-  
+
        if(WITH_FFTW3)
                set(FFTW3 ${LIBDIR}/fftw3)
-               set(FFTW3_INC ${FFTW3}/include)
-               set(FFTW3_LIB fftw3)
+               set(FFTW3_INCLUDE_DIRS ${FFTW3}/include)
+               set(FFTW3_LIBRARIES fftw3)
                set(FFTW3_LIBPATH ${FFTW3}/lib)
        endif()
 
@@ -855,34 +918,27 @@ elseif(APPLE)
 
        if(WITH_IMAGE_OPENEXR)
                set(OPENEXR ${LIBDIR}/openexr)
-               set(OPENEXR_INC ${OPENEXR}/include/OpenEXR ${OPENEXR}/include)
-               set(OPENEXR_LIB Iex Half IlmImf Imath IlmThread)
+               set(OPENEXR_INCLUDE_DIRS ${OPENEXR}/include/OpenEXR)
+               set(OPENEXR_LIBRARIES Iex Half IlmImf Imath IlmThread)
                set(OPENEXR_LIBPATH ${OPENEXR}/lib)
        endif()
 
-       if(WITH_LCMS)
-               set(LCMS ${LIBDIR}/lcms)
-               set(LCMS_INCLUDE_DIR ${LCMS}/include)
-               set(LCMS_LIBRARY lcms)
-               set(LCMS_LIBPATH ${LCMS}/lib)
-       endif()
-
        if(WITH_CODEC_FFMPEG)
                set(FFMPEG ${LIBDIR}/ffmpeg)
-               set(FFMPEG_INC ${FFMPEG}/include)
-               set(FFMPEG_LIB avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
+               set(FFMPEG_INCLUDE_DIRS ${FFMPEG}/include)
+               set(FFMPEG_LIBRARIES avcodec avdevice avformat avutil mp3lame swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg)
                set(FFMPEG_LIBPATH ${FFMPEG}/lib)
                set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS")
        endif()
 
        if(WITH_SAMPLERATE)
-               set(LIBSAMPLERATE ${LIBDIR}/samplerate)
-               set(LIBSAMPLERATE_INC ${LIBSAMPLERATE}/include)
-               set(LIBSAMPLERATE_LIB samplerate)
-               set(LIBSAMPLERATE_LIBPATH ${LIBSAMPLERATE}/lib)
+               set(SAMPLERATE ${LIBDIR}/samplerate)
+               set(SAMPLERATE_INCLUDE_DIRS ${SAMPLERATE}/include)
+               set(SAMPLERATE_LIBRARIES samplerate)
+               set(SAMPLERATE_LIBPATH ${SAMPLERATE}/lib)
        endif()
 
-       set(LLIBS stdc++ SystemStubs)
+       set(PLATFORM_LINKLIBS stdc++ SystemStubs)
 
        if(WITH_COCOA)
                set(PLATFORM_CFLAGS "-pipe -funsigned-char -DGHOST_COCOA")
@@ -904,9 +960,9 @@ elseif(APPLE)
 
        if(WITH_OPENCOLLADA)
                set(OPENCOLLADA ${LIBDIR}/opencollada)
-               set(OPENCOLLADA_INC ${OPENCOLLADA}/include)
+               set(OPENCOLLADA_INCLUDE_DIR ${OPENCOLLADA}/include)
                set(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib)
-               set(OPENCOLLADA_LIB "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa" )
+               set(OPENCOLLADA_LIBRARIES "OpenCOLLADASaxFrameworkLoader -lOpenCOLLADAFramework -lOpenCOLLADABaseUtils -lOpenCOLLADAStreamWriter -lMathMLSolver -lGeneratedSaxParser -lUTF -lxml2 -lbuffer -lftoa" )
                #pcre is bundled with openCollada
                #set(PCRE ${LIBDIR}/pcre)
                #set(PCRE_LIBPATH ${PCRE}/lib)
@@ -958,6 +1014,12 @@ endif()
 #-----------------------------------------------------------------------------
 # Common.
 
+if(APPLE OR WIN32)
+       if(NOT EXISTS "${LIBDIR}/")
+               message(FATAL_ERROR "Apple and Windows require pre-compiled libs at: '${LIBDIR}'")
+       endif()
+endif()
+
 if(WITH_RAYOPTIMIZATION)
        if(CMAKE_COMPILER_IS_GNUCC)
                if(SUPPORT_SSE_BUILD)
@@ -976,13 +1038,9 @@ endif()
 
 if(WITH_IMAGE_OPENJPEG)
        if(UNIX AND NOT APPLE)
-               set(OPENJPEG /usr)
-               set(OPENJPEG_INC ${OPENJPEG}/include)
-               set(OPENJPEG_LIB openjpeg)
-               set(OPENJPEG_LIBPATH ${OPENJPEG}/lib)
+               # dealt with above
        else()
-               set(OPENJPEG ${CMAKE_SOURCE_DIR}/extern/libopenjpeg)
-               set(OPENJPEG_INC ${OPENJPEG})
+               set(OPENJPEG_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/extern/libopenjpeg")
        endif()
 endif()
 
@@ -1005,7 +1063,7 @@ endif()
 #-----------------------------------------------------------------------------
 # Configure OpenGL.
 find_package(OpenGL)
-blender_include_dirs("${OPENGL_INCLUDE_DIR}")
+blender_include_dirs_sys("${OPENGL_INCLUDE_DIR}")
 # unset(OPENGL_LIBRARIES CACHE) # not compat with older cmake 
 # unset(OPENGL_xmesa_INCLUDE_DIR CACHE) # not compat with older cmake 
 
@@ -1104,6 +1162,18 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
 
 endif()
 
+# MSVC2010 fails to links C++ libs right
+if(MSVC10)
+       if(WITH_IMAGE_OPENEXR)
+               message(WARNING "MSVC 2010 does not support OpenEXR, disabling WITH_IMAGE_OPENEXR. To enable support use Use MSVC 2008")
+               set(WITH_IMAGE_OPENEXR OFF)
+       endif()
+       if(WITH_OPENCOLLADA)
+               message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008")
+               set(WITH_OPENCOLLADA OFF)
+       endif()
+endif()
+
 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
        if(WITH_IK_ITASC OR WITH_MOD_FLUID)
                message(WARNING "Using Clang as CXX compiler: disabling WITH_IK_ITASC and WITH_MOD_FLUID, these features will be missing.")
@@ -1118,9 +1188,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PLATFORM_CFLAGS} ${CXX_WARNINGS}")
 #-------------------------------------------------------------------------------
 # Global Defines
 
-# better not define flags here but this is a debugging option thats off by default.
+# better not set includes here but this debugging option is off by default.
 if(WITH_CXX_GUARDEDALLOC)
-       set(CMAKE_CXX_FLAGS " -DWITH_CXX_GUARDEDALLOC -I${CMAKE_SOURCE_DIR}/intern/guardedalloc ${CMAKE_CXX_FLAGS}")
+       include_directories(${CMAKE_SOURCE_DIR}/intern/guardedalloc)
 endif()
 
 if(WITH_ASSERT_ABORT)
@@ -1152,3 +1222,83 @@ endif()
 #-----------------------------------------------------------------------------
 # CPack for generating packages
 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}")
+               string(LENGTH "${_msg}" _len)
+               while("28" 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}")
+               
+               
+       endmacro()
+
+       info_cfg_text("Build Options:")
+       info_cfg_option(WITH_GAMEENGINE)
+       info_cfg_option(WITH_PLAYER)
+       info_cfg_option(WITH_BULLET)
+       info_cfg_option(WITH_IK_ITASC)
+       info_cfg_option(WITH_OPENCOLLADA)
+       info_cfg_option(WITH_FFTW3)
+       info_cfg_option(WITH_INTERNATIONAL)
+
+       info_cfg_text("Compiler Options:")
+       info_cfg_option(WITH_BUILDINFO)
+       info_cfg_option(WITH_OPENMP)
+       info_cfg_option(WITH_RAYOPTIMIZATION)
+
+       info_cfg_text("System Options:")
+       info_cfg_option(WITH_INSTALL_PORTABLE)
+       info_cfg_option(WITH_X11_XINPUT)
+       info_cfg_option(WITH_BUILTIN_GLEW)
+
+       info_cfg_text("Image Formats:")
+       info_cfg_option(WITH_IMAGE_CINEON)
+       info_cfg_option(WITH_IMAGE_DDS)
+       info_cfg_option(WITH_IMAGE_HDR)
+       info_cfg_option(WITH_IMAGE_OPENEXR)
+       info_cfg_option(WITH_IMAGE_OPENJPEG)
+       info_cfg_option(WITH_IMAGE_REDCODE)
+       info_cfg_option(WITH_IMAGE_TIFF)
+
+       info_cfg_text("Audio:")
+       info_cfg_option(WITH_OPENAL)
+       info_cfg_option(WITH_SDL)
+       info_cfg_option(WITH_JACK)
+       info_cfg_option(WITH_CODEC_FFMPEG)
+       info_cfg_option(WITH_CODEC_SNDFILE)
+       info_cfg_option(WITH_SAMPLERATE)
+
+       info_cfg_text("Compression:")
+       info_cfg_option(WITH_LZMA)
+       info_cfg_option(WITH_LZO)
+
+       info_cfg_text("Python:")
+       info_cfg_option(WITH_PYTHON_INSTALL)
+       info_cfg_option(WITH_PYTHON_MODULE)
+       info_cfg_option(WITH_PYTHON_SAFETY)
+
+       info_cfg_text("Modifiers:")
+       info_cfg_option(WITH_MOD_BOOLEAN)
+       info_cfg_option(WITH_MOD_DECIMATE)
+       info_cfg_option(WITH_MOD_FLUID)
+
+       info_cfg_text("")
+
+       message("${_config_msg}")
+endif()