Index: code/branches/pch/cmake/BuildConfig.cmake
===================================================================
--- code/branches/pch/cmake/BuildConfig.cmake	(revision 3161)
+++ code/branches/pch/cmake/BuildConfig.cmake	(revision 3167)
@@ -70,4 +70,9 @@
 ENDIF()
 
+# Enable expensive optimisations: Use this for a binary release build
+OPTION(ORXONOX_RELEASE "Enable when building restributable releases" FALSE)
+
+# Use WinMain() or main()?
+OPTION(ORXONOX_USE_WINMAIN "Use WinMain (doesn't show console) or main" FALSE)
 
 ################# OGRE Plugins ##################
Index: code/branches/pch/cmake/BuildConfigMSVC.cmake
===================================================================
--- code/branches/pch/cmake/BuildConfigMSVC.cmake	(revision 3161)
+++ code/branches/pch/cmake/BuildConfigMSVC.cmake	(revision 3167)
@@ -34,7 +34,14 @@
 ######################## Options ########################
 
-IF(MSVC80)
-  OPTION(VISUAL_LEAK_DETECTOR_ENABLE "Memory leak detector" FALSE)
-ENDIF(MSVC80)
+# Currently VLD has a problem with MSVC9 although it actually is supported
+IF(MSVC8)
+  OPTION(VISUAL_LEAK_DETECTOR_ENABLE "Memory leak detector" off)
+ENDIF()
+# Make sure the value is "on" or "off" for vld.ini
+IF(VISUAL_LEAK_DETECTOR_ENABLE)
+  SET(VISUAL_LEAK_DETECTOR_ENABLE on)
+ELSE()
+  SET(VISUAL_LEAK_DETECTOR_ENABLE off)
+ENDIF()
 
 # Orxonox only supports MSVC 8 and above, which gets asserted above
@@ -61,5 +68,5 @@
 
 # Overwrite CMake default flags here.
-SET_COMPILER_FLAGS("-MDd -Od -ZI -D_DEBUG -Gm -RTC1" Debug          CACHE)
+SET_COMPILER_FLAGS("-MDd -Od -Zi -D_DEBUG -Gm -RTC1" Debug          CACHE)
 SET_COMPILER_FLAGS("-MD  -O2     -DNDEBUG -MP2"      Release        CACHE)
 SET_COMPILER_FLAGS("-MD  -O2 -Zi -DNDEBUG -MP2"      RelWithDebInfo CACHE)
@@ -89,4 +96,5 @@
 # Happens on STL member variables which are not public
 ADD_COMPILER_FLAGS("-w44251" CACHE)
+ADD_COMPILER_FLAGS("-w44275" CACHE) # For inheritance
 
 # Multiple assignment operators specified
Index: code/branches/pch/cmake/LibraryConfig.cmake
===================================================================
--- code/branches/pch/cmake/LibraryConfig.cmake	(revision 3161)
+++ code/branches/pch/cmake/LibraryConfig.cmake	(revision 3167)
@@ -67,26 +67,6 @@
     INCLUDE(PackageConfigMinGW)
     INCLUDE(PackageConfigMSVC)
-
-    # On Windows, DLLs have to be in the executable folder, install them
-    IF(DEP_BINARY_DIR AND WIN32)
-      # When installing a debug version, we really can't know which libraries
-      # are used in released mode because there might be deps of deps.
-      INSTALL(
-        DIRECTORY ${DEP_BINARY_DIR}/
-        DESTINATION bin
-        CONFIGURATIONS Debug
-        REGEX "^.*\\.pdb$" EXCLUDE
-      )
-
-      # Try to filter out all the debug libraries. If the regex doesn't do the
-      # job anymore, simply adjust it.
-      INSTALL(
-        DIRECTORY ${DEP_BINARY_DIR}/
-        DESTINATION bin
-        CONFIGURATIONS Release RelWithDebInfo MinSizeRel
-        REGEX "_[Dd]\\.[a-zA-Z0-9+-]+$|-mt-gd-|^.*\\.pdb$" EXCLUDE
-      )
-    ENDIF(DEP_BINARY_DIR AND WIN32)
-  ENDIF(NOT DEPENDENCY_PACKAGE_DIR)
+    INCLUDE(PackageConfig) # For both msvc and mingw
+  ENDIF()
 ENDIF(DEPENDENCY_PACKAGE_ENABLE)
 
Index: code/branches/pch/cmake/PackageConfig.cmake
===================================================================
--- code/branches/pch/cmake/PackageConfig.cmake	(revision 3167)
+++ code/branches/pch/cmake/PackageConfig.cmake	(revision 3167)
@@ -0,0 +1,70 @@
+# General package configuration. Merely sets the include paths.
+# Library files are treated separately.
+
+# Check package version info
+# MAJOR: Interface breaking change somewhere (library version changed, etc.)
+# MINOR: Bug fix or small conformant changes
+SET(DEPENDENCY_VERSION_REQUIRED 2)
+IF(NOT EXISTS ${DEPENDENCY_PACKAGE_DIR}/version.txt)
+  SET(DEPENDENCY_VERSION 1.0)
+ELSE()
+  # Get version from file
+  FILE(READ ${DEPENDENCY_PACKAGE_DIR}/version.txt _file_content)
+  SET(_match)
+  STRING(REGEX MATCH "([0-9]+.[0-9]+)" _match ${_file_content})
+  IF(_match)
+    SET(DEPENDENCY_VERSION ${_match})
+  ELSE()
+    MESSAGE(FATAL_ERROR "The version.txt file in the dependency file has corrupt version information.")
+  ENDIF()
+ENDIF()
+
+INCLUDE(CompareVersionStrings)
+COMPARE_VERSION_STRINGS(${DEPENDENCY_VERSION} ${DEPENDENCY_VERSION_REQUIRED} _result)
+IF(NOT _result EQUAL 0)
+  MESSAGE(FATAL_ERROR "Your dependency package version is ${DEPENDENCY_VERSION}\n"
+          "Required version: ${DEPENDENCY_VERSION_REQUIRED}\n"
+	  "You can get a new version from www.orxonox.net")
+ENDIF()
+
+MESSAGE(STATUS "Using library package for the dependencies.")
+
+# Include paths and other special treatments
+SET(ENV{ALUTDIR}               ${DEP_INCLUDE_DIR}/freealut-1.1.0)
+SET(ENV{BOOST_ROOT}            ${DEP_INCLUDE_DIR}/boost-1.37.0)
+SET(ENV{CEGUIDIR}              ${DEP_INCLUDE_DIR}/cegui-0.6.2)
+SET(ENV{DXSDK_DIR}             ${DEP_INCLUDE_DIR}/directx-2007.aug)
+SET(ENV{ENETDIR}               ${DEP_INCLUDE_DIR}/enet-1.2)
+SET(ENV{LUA_DIR}               ${DEP_INCLUDE_DIR}/lua-5.1.4)
+SET(ENV{OGGDIR}                ${DEP_INCLUDE_DIR}/libogg-1.1.3)
+SET(ENV{VORBISDIR}             ${DEP_INCLUDE_DIR}/libvorbis-1.2.0)
+SET(ENV{OGRE_HOME}             ${DEP_INCLUDE_DIR}/ogre-1.4.9)
+SET(ENV{OGRE_PLUGIN_DIR}       ${DEP_BINARY_DIR})
+SET(ENV{OPENALDIR}             ${DEP_INCLUDE_DIR}/openal-1.1)
+LIST(APPEND CMAKE_INCLUDE_PATH ${DEP_INCLUDE_DIR}/tcl-8.5.2/include)
+LIST(APPEND CMAKE_INCLUDE_PATH ${DEP_INCLUDE_DIR}/zlib-1.2.3/include)
+
+### INSTALL ###
+# On Windows, DLLs have to be in the executable folder, install them
+IF(WIN32 AND DEP_BINARY_DIR)
+  ## DEBUG
+  # When installing a debug version, we really can't know which libraries
+  # are used in released mode because there might be deps of deps.
+  # --> Copy all of them, except the debug databases
+  INSTALL(
+    DIRECTORY ${DEP_BINARY_DIR}/
+    DESTINATION bin
+    CONFIGURATIONS Debug
+    REGEX "^.*\\.pdb$" EXCLUDE
+  )
+
+  ## RELEASE
+  # Try to filter out all the debug libraries. If the regex doesn't do the
+  # job anymore, simply adjust it.
+  INSTALL(
+    DIRECTORY ${DEP_BINARY_DIR}/
+    DESTINATION bin
+    CONFIGURATIONS Release RelWithDebInfo MinSizeRel
+    REGEX "_[Dd]\\.[a-zA-Z0-9+-]+$|-mt-gd-|^.*\\.pdb$" EXCLUDE
+  )
+ENDIF()
Index: code/branches/pch/cmake/PackageConfigMSVC.cmake
===================================================================
--- code/branches/pch/cmake/PackageConfigMSVC.cmake	(revision 3161)
+++ code/branches/pch/cmake/PackageConfigMSVC.cmake	(revision 3167)
@@ -28,11 +28,4 @@
 IF(MSVC)
 
-  # MAJOR: Interface breaking change somewhere or added a new library
-  # MINOR: Updated a library to a new version
-  # PATCH: Bug fix or smaller things
-  SET(DEPENDENCY_VERSION 0.0.1)
-
-  MESSAGE(STATUS "Using library package for the dependencies.")
-
   # 64 bit system?
   IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
@@ -45,7 +38,4 @@
   STRING(REGEX REPLACE "^Visual Studio ([0-9][0-9]?) .*$" "\\1"
          _msvc_version "${CMAKE_GENERATOR}")
-  IF(MSVC71)
-    SET(_msvc_version "7.1")
-  ENDIF(MSVC71)
 
   SET(DEP_INCLUDE_DIR ${DEPENDENCY_PACKAGE_DIR}/include)
@@ -62,20 +52,14 @@
   SET(CMAKE_LIBRARY_PATH ${DEP_LIBRARY_DIR})
 
-  # Include paths and other special treatments
-  SET(ENV{ALUTDIR}               ${DEP_INCLUDE_DIR}/freealut-1.1.0)
-  SET(ENV{BOOST_ROOT}            ${DEP_INCLUDE_DIR}/boost-1.37.0)
-  SET(ENV{CEGUIDIR}              ${DEP_INCLUDE_DIR}/cegui-0.6.2)
-  SET(ENV{DXSDK_DIR}             ${DEP_INCLUDE_DIR}/directx-2007.aug)
-  SET(ENV{ENETDIR}               ${DEP_INCLUDE_DIR}/enet-1.2)
-  SET(ENV{LUA_DIR}               ${DEP_INCLUDE_DIR}/lua-5.1.4)
-  SET(ENV{OGGDIR}                ${DEP_INCLUDE_DIR}/libogg-1.1.3)
-  SET(ENV{VORBISDIR}             ${DEP_INCLUDE_DIR}/libvorbis-1.2.0)
-  SET(ENV{OGRE_HOME}             ${DEP_INCLUDE_DIR}/ogre-1.4.9)
-  SET(ENV{OGRE_PLUGIN_DIR}       ${DEP_BINARY_DIR})
-  SET(ENV{OPENALDIR}             ${DEP_INCLUDE_DIR}/openal-1.1)
-  LIST(APPEND CMAKE_INCLUDE_PATH ${DEP_INCLUDE_DIR}/tcl-8.5.2/include)
-  SET(TCL_LIBRARY                ${DEP_LIBRARY_DIR}/tcl85.lib CACHE FILEPATH "")
-  LIST(APPEND CMAKE_INCLUDE_PATH ${DEP_INCLUDE_DIR}/zlib-1.2.3/include)
-  SET(ZLIB_LIBRARY               ${DEP_LIBRARY_DIR}/zdll.lib CACHE FILEPATH "")
+  # Certain find scripts don't behave as ecpected to we have
+  # to specify the libraries ourselves.
+  SET(TCL_LIBRARY  ${DEP_LIBRARY_DIR}/tcl85.lib CACHE FILEPATH "")
+  SET(ZLIB_LIBRARY ${DEP_LIBRARY_DIR}/zdll.lib  CACHE FILEPATH "")
+
+  # Visual Leak Detector
+  SET(VLD_INCLUDE_DIR  ${DEP_INCLUDE_DIR}/vld-1.9h CACHE PATH "")
+  SET(VLD_LIBRARY_DIR  ${DEP_LIBRARY_DIR}          CACHE PATH "")
+  LINK_DIRECTORIES(${VLD_LIBRARY_DIR}) # Used for auto-linking
+  MARK_AS_ADVANCED(VLD_INCLUDE_DIR VLD_LIBRARY_DIR)
 
 ENDIF(MSVC)
Index: code/branches/pch/cmake/PackageConfigMinGW.cmake
===================================================================
--- code/branches/pch/cmake/PackageConfigMinGW.cmake	(revision 3161)
+++ code/branches/pch/cmake/PackageConfigMinGW.cmake	(revision 3167)
@@ -28,11 +28,4 @@
 IF(MINGW)
 
-  # MAJOR: Interface breaking change somewhere or added a new library
-  # MINOR: Updated a library to a new version
-  # PATCH: Bug fix or smaller things
-  SET(DEPENDENCY_VERSION 0.0.1)
-
-  MESSAGE(STATUS "Using library package for the dependencies.")
-
   # 64 bit system?
   IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
@@ -52,20 +45,8 @@
   SET(CMAKE_LIBRARY_PATH ${DEP_LIBRARY_DIR} ${DEP_BINARY_DIR})
 
-  # Include paths and other special treatments
-  SET(ENV{ALUTDIR}               ${DEP_INCLUDE_DIR}/freealut-1.1.0)
-  SET(ENV{BOOST_ROOT}            ${DEP_INCLUDE_DIR}/boost-1.37.0)
-  SET(ENV{CEGUIDIR}              ${DEP_INCLUDE_DIR}/cegui-0.6.2)
-  SET(ENV{DXSDK_DIR}             ${DEP_INCLUDE_DIR}/directx-2007.aug)
-  SET(ENV{ENETDIR}               ${DEP_INCLUDE_DIR}/enet-1.2)
-  SET(ENV{LUA_DIR}               ${DEP_INCLUDE_DIR}/lua-5.1.4)
-  SET(ENV{OGGDIR}                ${DEP_INCLUDE_DIR}/libogg-1.1.3)
-  SET(ENV{VORBISDIR}             ${DEP_INCLUDE_DIR}/libvorbis-1.2.0)
-  SET(ENV{OGRE_HOME}             ${DEP_INCLUDE_DIR}/ogre-1.4.9)
-  SET(ENV{OGRE_PLUGIN_DIR}       ${DEP_BINARY_DIR})
-  SET(ENV{OPENALDIR}             ${DEP_INCLUDE_DIR}/openal-1.1)
-  LIST(APPEND CMAKE_INCLUDE_PATH ${DEP_INCLUDE_DIR}/tcl-8.5.2/include)
-  SET(TCL_LIBRARY                ${DEP_BINARY_DIR}/tcl85.dll CACHE FILEPATH "")
-  LIST(APPEND CMAKE_INCLUDE_PATH ${DEP_INCLUDE_DIR}/zlib-1.2.3/include)
-  SET(ZLIB_LIBRARY               ${DEP_BINARY_DIR}/zlib1.dll CACHE FILEPATH "")
+  # Certain find scripts don't behave as ecpected to we have
+  # to specify the libraries ourselves.
+  SET(TCL_LIBRARY  ${DEP_BINARY_DIR}/tcl85.dll CACHE FILEPATH "")
+  SET(ZLIB_LIBRARY ${DEP_BINARY_DIR}/zlib1.dll CACHE FILEPATH "")
 
 ENDIF(MINGW)
Index: code/branches/pch/cmake/PrecompiledHeaderFiles.cmake
===================================================================
--- code/branches/pch/cmake/PrecompiledHeaderFiles.cmake	(revision 3161)
+++ code/branches/pch/cmake/PrecompiledHeaderFiles.cmake	(revision 3167)
@@ -110,5 +110,8 @@
     GET_GCC_COMPILER_FLAGS(${_target_name} _pch_gcc_flags)
     # Make sure we recompile the pch file even if only the flags change
-    FILE(WRITE ${_pch_dep_helper_file} "/* ${_pch_gcc_flags} */")
+    IF(NOT "${_pch_gcc_flags}" STREQUAL "${_INTERNAL_PCH_GCC_FLAGS}")
+      SET(_INTERNAL_PCH_GCC_FLAGS "${_pch_gcc_flags}" CACHE INTERNAL "")
+      FILE(WRITE ${_pch_dep_helper_file} "/* ${_pch_gcc_flags} */")
+    ENDIF()
 
     # Set Compile flags for the other source files
@@ -157,5 +160,2 @@
     ENDIF(CMAKE_COMPILER_IS_GNU)
 ENDFUNCTION(PRECOMPILED_HEADER_FILES_POST_TARGET)
-
-# TODO: Investigate what happens when we suddenly disable PCH for a library
-# TODO: C and CXX
Index: code/branches/pch/cmake/TargetUtilities.cmake
===================================================================
--- code/branches/pch/cmake/TargetUtilities.cmake	(revision 3161)
+++ code/branches/pch/cmake/TargetUtilities.cmake	(revision 3167)
@@ -164,5 +164,5 @@
   IF(_arg_VERSION)
     SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${_arg_VERSION})
-  ELSEIF(NOT ORXONOX_EXTERNAL)
+  ELSEIF(NOT _arg_ORXONOX_EXTERNAL)
     SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${ORXONOX_VERSION})
   ENDIF()
