Index: code/trunk/cmake/BuildConfig.cmake
===================================================================
--- code/trunk/cmake/BuildConfig.cmake	(revision 3111)
+++ code/trunk/cmake/BuildConfig.cmake	(revision 3196)
@@ -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/trunk/cmake/BuildConfigGCC.cmake
===================================================================
--- code/trunk/cmake/BuildConfigGCC.cmake	(revision 3111)
+++ code/trunk/cmake/BuildConfigGCC.cmake	(revision 3196)
@@ -24,4 +24,7 @@
  #
 
+# Shortcut for CMAKE_COMPILER_IS_GNUCXX and ..._GNUC
+SET(CMAKE_COMPILER_IS_GNU TRUE)
+
 # Determine compiler version
 EXEC_PROGRAM(
@@ -38,4 +41,11 @@
 IF(_compare_result LESS 0)
   SET(GCC_NO_SYSTEM_HEADER_SUPPORT TRUE)
+ENDIF()
+
+# GCC only supports PCH in versions 3.4 and above
+INCLUDE(CompareVersionStrings)
+COMPARE_VERSION_STRINGS("${GCC_VERSION}" "3.4.0" _compare_result)
+IF(_compare_result GREATER -1)
+  SET(PCH_COMPILER_SUPPORT TRUE)
 ENDIF()
 
@@ -67,4 +77,7 @@
 ADD_COMPILER_FLAGS("-Wno-deprecated" CXX CACHE)
 
+# Always show why a precompiled header file could not be used
+ADD_COMPILER_FLAGS("-Winvalid-pch" CXX CACHE)
+
 # Increase warning level if requested
 IF(EXTRA_COMPILER_WARNINGS)
Index: code/trunk/cmake/BuildConfigMSVC.cmake
===================================================================
--- code/trunk/cmake/BuildConfigMSVC.cmake	(revision 3111)
+++ code/trunk/cmake/BuildConfigMSVC.cmake	(revision 3196)
@@ -24,7 +24,28 @@
  #
 
+################### Compiler Version ####################
+
+# We make use of variadic macros, which is only supported by MSVC 8 and above
+IF(MSVC_VERSION LESS 1400)
+  MESSAGE(FATAL_ERROR "Microsoft Visual Studio versions below 8 (2005) are not supported because of missing compiler extensions.")
+ENDIF()
+
+
 ######################## Options ########################
 
-OPTION(VISUAL_LEAK_DETECTOR_ENABLE "Memory leak detector" FALSE)
+# 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
+SET(PCH_COMPILER_SUPPORT TRUE)
+
 
 #################### Compiler Flags #####################
@@ -47,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)
@@ -75,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/trunk/cmake/CapitaliseName.cmake
===================================================================
--- code/trunk/cmake/CapitaliseName.cmake	(revision 3196)
+++ code/trunk/cmake/CapitaliseName.cmake	(revision 3196)
@@ -0,0 +1,33 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        This program is free software; you can redistribute it and/or
+ #         modify it under the terms of the GNU General Public License
+ #        as published by the Free Software Foundation; either version 2
+ #            of the License, or (at your option) any later version.
+ #
+ #       This program is distributed in the hope that it will be useful,
+ #        but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ #                 GNU General Public License for more details.
+ #
+ #   You should have received a copy of the GNU General Public License along
+ #      with this program; if not, write to the Free Software Foundation,
+ #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ #
+ #
+ #  Author:
+ #    Reto Grieder
+ #  Examples:
+ #    "orxonox"  --> "Orxonox"
+ #    "ORXONOX"  --> "ORXONOX"
+ #    "1orxonox" --> "1orxonox"
+ #
+
+FUNCTION(CAPITALISE_NAME _name _output_var)
+  STRING(SUBSTRING "${_name}" 0 1 _first_letter)
+  STRING(TOUPPER "${_first_letter}" _first_letter)
+  STRING(REGEX REPLACE "^.(.*)$" "\\1" _rest "${_name}")
+  SET(${_output_var} "${_first_letter}${_rest}" PARENT_SCOPE)
+ENDFUNCTION(CAPITALISE_NAME)
Index: code/trunk/cmake/FlagUtilities.cmake
===================================================================
--- code/trunk/cmake/FlagUtilities.cmake	(revision 3111)
+++ code/trunk/cmake/FlagUtilities.cmake	(revision 3196)
@@ -24,12 +24,12 @@
  #    Release, Debug, RelWithDebInfo, MinSizeRel: Build configs (inclusive)
  #    ReleaseAll: Sets the flags of all three release builds
- #    CACHE: Values are witten with SET_CACHE (see above)
+ #    CACHE: Values are witten with SET_CACHE_ADVANCED
  #    FORCE: When writing to the cache, the values are set anyway
  #    Any variable names (like WIN32, MSVC, etc.): Condition (combined with AND)
  #    You can suffix the condition with a NOT if you wish
- #  Functions:
+ #  Function names:
  #    [ADD/SET/REMOVE]_[COMPILER/LINKER]_FLAGS
  #  Caution: -If you use CACHE after calling the macro without CACHE, the value
- #            Will not get written unless FORCE is specified.
+ #            Will not be written unless FORCE is specified.
  #          - Also be aware to always specify the flags in quotes.
  #  Example:
@@ -37,90 +37,39 @@
  #    This will only remove the CXX (C++) flags on a non Unix system for the
  #    Release, RelWithDebInfo and MinSizeRel configurations. The macros should
- #    be able to cope with "test -foo" that is like another flag in the string.
+ #    be able to cope with "test -foo" as string argument for a flag.
  #
 
-# Write to the cache by force, but only if the user didn't edit the value
-# Additional argument is the value (may also be a list)
-MACRO(SET_CACHE _varname _type _docstring)
-  SET(_value ${ARGN})
-  IF(NOT "${_type}" MATCHES "^(STRING|BOOL|PATH|FILEPATH)$")
-    MESSAGE(FATAL_ERROR "${_type} is not a valid CACHE entry type")
-  ENDIF()
+INCLUDE(SeparateFlags)
+INCLUDE(SetCacheAdvanced)
 
-  IF(NOT DEFINED _INTERNAL_${_varname} OR "${_INTERNAL_${_varname}}" STREQUAL "${${_varname}}")
-    SET(${_varname} "${_value}" CACHE ${_type} "${_docstring}" FORCE)
-    SET(_INTERNAL_${_varname} "${_value}" CACHE INTERNAL "Do not edit in any case!")
-  ENDIF()
-ENDMACRO(SET_CACHE)
+# Compiler flags, additional arguments:
+# C, CXX: Specify a language, default is both
+MACRO(SET_COMPILER_FLAGS _flags)
+  _INTERNAL_PARSE_FLAGS_ARGS(SET "C;CXX" "" "${_flags}" "${ARGN}")
+ENDMACRO(SET_COMPILER_FLAGS)
+# Add flags (flags don't get added twice)
+MACRO(ADD_COMPILER_FLAGS _flags)
+  _INTERNAL_PARSE_FLAGS_ARGS(APPEND "C;CXX" "" "${_flags}" "${ARGN}")
+ENDMACRO(ADD_COMPILER_FLAGS)
+# Remove flags
+MACRO(REMOVE_COMPILER_FLAGS _flags)
+  _INTERNAL_PARSE_FLAGS_ARGS(REMOVE_ITEM "C;CXX" "" "${_flags}" "${ARGN}")
+ENDMACRO(REMOVE_COMPILER_FLAGS)
 
-# Visual studio (esp. IntelliSense) doesn't like dashes to specify arguments
-# Always use foward slashes instead
-IF(MSVC)
-  SET(ARGUMENT_STARTER "/")
-ELSE()
-  SET(ARGUMENT_STARTER "-")
-ENDIF(MSVC)
 
-# Separates a string of flags. " -" or " /" denotes the start of a flag.
-# The same sequence inside double quotation marks is ignored.
-# Spaces not within quotes are cleaned meaningfully.
-# This macro cannot cope with semicolons in the flag string!
-MACRO(SEPARATE_FLAGS _flags _output_variable)
-  SET(_flags_prep " ${_flags} -")
-  STRING(REPLACE " " " ;" _flag_chunks ${_flags_prep}) # Max loop iterations
-  SET(_flag_string)
-  SET(_parsed_flags)
-  # Loop is necessary because the regex engine is greedy
-  FOREACH(_chunk ${_flag_chunks})
-    SET(_flag_string "${_flag_string}${_chunk}")
-    # Replace all " -" and " /" inside quotation marks
-    STRING(REGEX REPLACE "^(([^\"]*\"[^\"]*\")*[^\"]*\"[^\"]*) [/-]([^\"]*\")"
-           "\\1@39535493@\\3" _flag_string "${_flag_string}")
-    # Extract one flag if possible
-    SET(_flag)
-    STRING(REGEX REPLACE "^.* [/-](.+)( [/-].*$)" "${ARGUMENT_STARTER}\\1" _flag "${_flag_string}")
-    STRING(REGEX REPLACE "^.* [/-](.+)( [/-].*$)" "\\2"  _flag_string "${_flag_string}")
-    IF(NOT _flag STREQUAL _flag_string)
-      LIST(APPEND _parsed_flags "${_flag}")
-    ENDIF(NOT _flag STREQUAL _flag_string)
-  ENDFOREACH(_chunk)
+# Linker flags, additional arguments:
+# EXE, SHARED, MODULE: Specify a linker mode, default is all three
+MACRO(SET_LINKER_FLAGS _flags)
+  _INTERNAL_PARSE_FLAGS_ARGS(SET "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}")
+ENDMACRO(SET_LINKER_FLAGS)
+# Add flags (flags don't get added twice)
+MACRO(ADD_LINKER_FLAGS _flags)
+  _INTERNAL_PARSE_FLAGS_ARGS(APPEND "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}")
+ENDMACRO(ADD_LINKER_FLAGS)
+# Remove flags
+MACRO(REMOVE_LINKER_FLAGS _flags)
+  _INTERNAL_PARSE_FLAGS_ARGS(REMOVE_ITEM "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}")
+ENDMACRO(REMOVE_LINKER_FLAGS)
 
-  # Re-replace all " -" and " /" inside quotation marks
-  STRING(REGEX REPLACE "@39535493@" " -" ${_output_variable} "${_parsed_flags}")
-ENDMACRO(SEPARATE_FLAGS)
-
-# Internal macro, do not use
-# Modifies the flags according to the mode: set, add or remove
-# Also sets flags according to the CACHE and FORCE parameter.
-# If only CACHE is specified, SET_CACHE() is used.
-MACRO(_INTERNAL_PARSE_FLAGS _mode _flags _varname _write_to_cache _force)
-  SEPARATE_FLAGS("${_flags}" _arg_flag_list)
-
-  IF("${_mode}" STREQUAL "SET")
-    # SET
-    SET(_flag_list "${_arg_flag_list}")
-  ELSE()
-    # ADD or REMOVE
-    SEPARATE_FLAGS("${${_varname}}" _flag_list)
-    FOREACH(_flag ${_arg_flag_list})
-      LIST(${_mode} _flag_list "${_flag}")
-    ENDFOREACH(_flag)
-  ENDIF()
-
-  LIST(REMOVE_DUPLICATES _flag_list)
-  LIST(SORT _flag_list)
-  STRING(REPLACE ";" " " _flag_list "${_flag_list}")
-
-  IF(_write_to_cache)
-    IF(_force)
-      SET(${_varname} "${_flag_list}" CACHE STRING "${${_varname}}" FORCE)
-      SET(${_varname} "${_flag_list}" CACHE STRING "${${_varname}}" FORCE)
-    ELSE()
-      SET_CACHE(${_varname} STRING "${${_varname}}" "${_flag_list}")
-    ENDIF()
-  ELSE()
-    SET(${_varname} "${_flag_list}")
-  ENDIF()
-ENDMACRO(_INTERNAL_PARSE_FLAGS)
 
 # Internal macro, do not use
@@ -155,9 +104,9 @@
       IF(_invert_condition)
         SET(_invert_condition FALSE)
-    IF(${_arg})
+        IF(${_arg})
           SET(_arg_cond FALSE)
-    ELSE()
+        ELSE()
           SET(_arg_cond TRUE)
-    ENDIF()
+       ENDIF()
       ELSE()
         SET(_arg_cond ${${_arg}})
@@ -191,29 +140,38 @@
 
 
-# Compiler flags, additional arguments:
-# C, CXX: Specify a language, default is both
-MACRO(SET_COMPILER_FLAGS _flags)
-  _INTERNAL_PARSE_FLAGS_ARGS(SET "C;CXX" "" "${_flags}" "${ARGN}")
-ENDMACRO(SET_COMPILER_FLAGS)
-# Add flags (flags don't get added twice)
-MACRO(ADD_COMPILER_FLAGS _flags)
-  _INTERNAL_PARSE_FLAGS_ARGS(APPEND "C;CXX" "" "${_flags}" "${ARGN}")
-ENDMACRO(ADD_COMPILER_FLAGS)
-# Remove flags
-MACRO(REMOVE_COMPILER_FLAGS _flags)
-  _INTERNAL_PARSE_FLAGS_ARGS(REMOVE_ITEM "C;CXX" "" "${_flags}" "${ARGN}")
-ENDMACRO(REMOVE_COMPILER_FLAGS)
+# Internal macro, do not use
+# Modifies the flags according to the mode: set, add or remove
+# Also sets flags according to the CACHE and FORCE parameter.
+# If only CACHE is specified, SET_CACHE_ADVANCED() is used.
+MACRO(_INTERNAL_PARSE_FLAGS _mode _flags _varname _write_to_cache _force)
+  SEPARATE_FLAGS("${_flags}" _arg_flag_list)
 
-# Linker flags, additional arguments:
-# EXE, SHARED, MODULE: Specify a linker mode, default is all three
-MACRO(SET_LINKER_FLAGS _flags)
-  _INTERNAL_PARSE_FLAGS_ARGS(SET "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}")
-ENDMACRO(SET_LINKER_FLAGS)
-# Add flags (flags don't get added twice)
-MACRO(ADD_LINKER_FLAGS _flags)
-  _INTERNAL_PARSE_FLAGS_ARGS(APPEND "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}")
-ENDMACRO(ADD_LINKER_FLAGS)
-# Remove flags
-MACRO(REMOVE_LINKER_FLAGS _flags)
-  _INTERNAL_PARSE_FLAGS_ARGS(REMOVE_ITEM "EXE;SHARED;MODULE" "_LINKER" "${_flags}" "${ARGN}")
-ENDMACRO(REMOVE_LINKER_FLAGS)
+  IF("${_mode}" STREQUAL "SET")
+    # SET
+    SET(_flag_list "${_arg_flag_list}")
+  ELSE()
+    # ADD or REMOVE
+    SEPARATE_FLAGS("${${_varname}}" _flag_list)
+    IF(NOT _flag_list)
+      SET(_flag_list "") # LIST command requires a list in any case
+    ENDIF()
+    FOREACH(_flag ${_arg_flag_list})
+      LIST(${_mode} _flag_list "${_flag}")
+    ENDFOREACH(_flag)
+  ENDIF()
+
+  LIST(REMOVE_DUPLICATES _flag_list)
+  LIST(SORT _flag_list)
+  STRING(REPLACE ";" " " _flag_list "${_flag_list}")
+
+  IF(_write_to_cache)
+    IF(_force)
+      SET(${_varname} "${_flag_list}" CACHE STRING "${${_varname}}" FORCE)
+      SET(${_varname} "${_flag_list}" CACHE STRING "${${_varname}}" FORCE)
+    ELSE()
+      SET_CACHE_ADVANCED(${_varname} STRING "${${_varname}}" "${_flag_list}")
+    ENDIF()
+  ELSE()
+    SET(${_varname} "${_flag_list}")
+  ENDIF()
+ENDMACRO(_INTERNAL_PARSE_FLAGS)
Index: code/trunk/cmake/GenerateToluaBindings.cmake
===================================================================
--- code/trunk/cmake/GenerateToluaBindings.cmake	(revision 3111)
+++ code/trunk/cmake/GenerateToluaBindings.cmake	(revision 3196)
@@ -48,4 +48,8 @@
   )
   SOURCE_GROUP("Tolua" FILES ${_tolua_cxxfile} ${_tolua_hfile})
+  # Disable annoying GCC warnings
+  IF(CMAKE_COMPILER_IS_GNU)
+    SET_SOURCE_FILES_PROPERTIES(${_tolua_cxxfile} PROPERTIES COMPILE_FLAGS "-w")
+  ENDIF()
 
   # Create temporary package file
Index: code/trunk/cmake/GetGCCCompilerFlags.cmake
===================================================================
--- code/trunk/cmake/GetGCCCompilerFlags.cmake	(revision 3196)
+++ code/trunk/cmake/GetGCCCompilerFlags.cmake	(revision 3196)
@@ -0,0 +1,73 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        This program is free software; you can redistribute it and/or
+ #         modify it under the terms of the GNU General Public License
+ #        as published by the Free Software Foundation; either version 2
+ #            of the License, or (at your option) any later version.
+ #
+ #       This program is distributed in the hope that it will be useful,
+ #        but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ #                 GNU General Public License for more details.
+ #
+ #   You should have received a copy of the GNU General Public License along
+ #      with this program; if not, write to the Free Software Foundation,
+ #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ #
+ #
+ #  Author:
+ #    Reto Grieder
+ #  Description:
+ #    Tries to return all GCC compiler flags set for a target. This also
+ #    all definitions of the current directory.
+ #
+
+INCLUDE(SeparateFlags)
+
+FUNCTION(GET_GCC_COMPILER_FLAGS _target _flagsvar)
+
+  # General flags
+  STRING(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type_upper)
+  SET(_flag_str "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_build_type_upper}}")
+
+  # Include directories
+  GET_DIRECTORY_PROPERTY(_include_dirs INCLUDE_DIRECTORIES)
+  IF(_include_dirs)
+    FOREACH(_directory ${_include_dirs})
+      SET(_flag_str "${_flag_str} -I${_directory}")
+    ENDFOREACH(_directory)
+  ENDIF()
+
+  # For shared libraries linked with gcc, we have to add -fPIC
+  GET_TARGET_PROPERTY(_target_type ${_target} TYPE)
+  IF(NOT MINGW AND ${_target_type} STREQUAL SHARED_LIBRARY)
+    SET(_flag_str "${_flag_str} -fPIC")
+  ENDIF()
+
+  # Target compile flags
+  GET_TARGET_PROPERTY(_target_flags ${_target} COMPILE_FLAGS)
+  IF(_target_flags)
+    SET(_flag_str "${_flag_str} ${_target_flags}")
+  ENDIF()
+
+  # Definitions from target and directory
+  GET_DIRECTORY_PROPERTY(_directory_defs                 COMPILE_DEFINITIONS)
+  GET_DIRECTORY_PROPERTY(_directory_defs_build_type      COMPILE_DEFINITIONS_${_build_type_upper})
+  GET_TARGET_PROPERTY(_target_defs            ${_target} COMPILE_DEFINITIONS)
+  GET_TARGET_PROPERTY(_target_defs_build_type ${_target} COMPILE_DEFINITIONS_${_build_type_upper})
+  GET_TARGET_PROPERTY(_target_def_symbol      ${_target} DEFINE_SYMBOL)
+  # Prefix them all with a "-D" if the property was found
+  FOREACH(_def ${_directory_defs} ${_directory_defs_build_type} ${_target_defs}
+               ${_target_defs_build_type} ${_target_def_symbol})
+    IF(_def)
+      SET(_flag_str "${_flag_str} -D${_def}")
+    ENDIF(_def)
+  ENDFOREACH(_def)
+
+  SEPARATE_FLAGS("${_flag_str}" _flags)
+  LIST(REMOVE_DUPLICATES _flags)
+  SET(${_flagsvar} ${_flags} PARENT_SCOPE)
+
+ENDFUNCTION(GET_GCC_COMPILER_FLAGS)
Index: code/trunk/cmake/InstallUtilities.cmake
===================================================================
--- code/trunk/cmake/InstallUtilities.cmake	(revision 3111)
+++ 	(revision )
@@ -1,34 +1,0 @@
- #
- #             ORXONOX - the hottest 3D action shooter ever to exist
- #                             > www.orxonox.net <
- #
- #        This program is free software; you can redistribute it and/or
- #         modify it under the terms of the GNU General Public License
- #        as published by the Free Software Foundation; either version 2
- #            of the License, or (at your option) any later version.
- #
- #       This program is distributed in the hope that it will be useful,
- #        but WITHOUT ANY WARRANTY; without even the implied warranty of
- #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- #                 GNU General Public License for more details.
- #
- #   You should have received a copy of the GNU General Public License along
- #      with this program; if not, write to the Free Software Foundation,
- #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- #
- #
- #  Author:
- #    Reto Grieder
- #  Description:
- #    Helps configuring the INSTALL command in more global way.
- #  Parameters:
- #    Specifiy the targets as additional parameter.
- #
-
-FUNCTION(ORXONOX_INSTALL)
-  INSTALL(TARGETS ${ARGN}
-    RUNTIME DESTINATION ${ORXONOX_RUNTIME_INSTALL_PATH}
-    LIBRARY DESTINATION ${ORXONOX_LIBRARY_INSTALL_PATH}
-    #ARCHIVE DESTINATION ${ORXONOX_ARCHIVE_INSTALL_PATH}
-  )
-ENDFUNCTION(ORXONOX_INSTALL)
Index: code/trunk/cmake/LibraryConfig.cmake
===================================================================
--- code/trunk/cmake/LibraryConfig.cmake	(revision 3111)
+++ code/trunk/cmake/LibraryConfig.cmake	(revision 3196)
@@ -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)
 
@@ -172,5 +152,5 @@
 ##### Boost #####
 # Expand the next statement if newer boost versions than 1.36.1 are released
-SET(Boost_ADDITIONAL_VERSIONS 1.37 1.37.0)
+SET(Boost_ADDITIONAL_VERSIONS 1.37 1.37.0 1.38 1.38.0 1.39 1.39.0)
 # MSVC seems to be the only compiler requiring date_time
 IF(MSVC)
Index: code/trunk/cmake/PackageConfig.cmake
===================================================================
--- code/trunk/cmake/PackageConfig.cmake	(revision 3196)
+++ code/trunk/cmake/PackageConfig.cmake	(revision 3196)
@@ -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/trunk/cmake/PackageConfigMSVC.cmake
===================================================================
--- code/trunk/cmake/PackageConfigMSVC.cmake	(revision 3111)
+++ code/trunk/cmake/PackageConfigMSVC.cmake	(revision 3196)
@@ -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/trunk/cmake/PackageConfigMinGW.cmake
===================================================================
--- code/trunk/cmake/PackageConfigMinGW.cmake	(revision 3111)
+++ code/trunk/cmake/PackageConfigMinGW.cmake	(revision 3196)
@@ -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/trunk/cmake/ParseMacroArguments.cmake
===================================================================
--- code/trunk/cmake/ParseMacroArguments.cmake	(revision 3196)
+++ code/trunk/cmake/ParseMacroArguments.cmake	(revision 3196)
@@ -0,0 +1,76 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        This program is free software; you can redistribute it and/or
+ #         modify it under the terms of the GNU General Public License
+ #        as published by the Free Software Foundation; either version 2
+ #            of the License, or (at your option) any later version.
+ #
+ #       This program is distributed in the hope that it will be useful,
+ #        but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ #                 GNU General Public License for more details.
+ #
+ #   You should have received a copy of the GNU General Public License along
+ #      with this program; if not, write to the Free Software Foundation,
+ #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ #
+ #
+ #  Author:
+ #    Reto Grieder
+ #  Description:
+ #    Parses a list of macro arguments which are separated by keywords and
+ #    writes the result to the _arg_KEYWORD variable. Switches are set to their
+ #    literal name if found and the lists contain their elements.
+ #    The order of the arguments is arbitrary.
+ #  Note:
+ #    You have to specify the switches and list_names as a
+ #    semicolon separated list or all hell breaks loose!
+ #  Example:
+ #    The arguments  BLUBB_FILES foo.cc bar.c NO_ASDF  will do the following:
+ #    SET(_arg_NO_ASDF _arg_NO_ASDF)
+ #    SET(_arg_BLUBB_FILES foo.cc bar.c)
+ #    But NO_FOO will not be set at all if it was specified as a switch
+ #
+
+MACRO(PARSE_MACRO_ARGUMENTS _switches _list_names)
+  # Parse all the arguments and set the corresponding variable
+  # If the option is just a switch, set the variable to its name for later use
+  FOREACH(_arg ${ARGN})
+    SET(_arg_found FALSE)
+
+    # Switches
+    FOREACH(_switch ${_switches})
+      IF(${_switch} STREQUAL ${_arg})
+        SET(_arg_${_switch} ${_switch})
+	SET(_arg_found TRUE)
+        # Avoid interpreting arguments after this one as options args for the previous one
+	SET(_storage_var)
+        BREAK()
+      ENDIF()
+    ENDFOREACH(_switch)
+
+    # Input options
+    IF(NOT _arg_found)
+      FOREACH(_list_name ${_list_names})
+        IF(${_list_name} STREQUAL ${_arg})
+          SET(_storage_var _arg_${_list_name})
+	  SET(_arg_found TRUE)
+          BREAK()
+        ENDIF()
+      ENDFOREACH(_list_name)
+    ENDIF(NOT _arg_found)
+
+    # Arguments of an input option (like source files for SOURCE_FILES)
+    IF(NOT _arg_found)
+      IF(_storage_var)
+        # Store in variable define above in the foreach loop
+        SET(${_storage_var} ${${_storage_var}} ${_arg})
+      ELSE()
+        MESSAGE(FATAL_ERROR "ORXONOX_ADD_${_target_type} was given a non compliant argument: ${_arg}")
+      ENDIF(_storage_var)
+    ENDIF(NOT _arg_found)
+
+  ENDFOREACH(_arg)
+ENDMACRO(PARSE_MACRO_ARGUMENTS)
Index: code/trunk/cmake/PrecompiledHeaderFiles.cmake
===================================================================
--- code/trunk/cmake/PrecompiledHeaderFiles.cmake	(revision 3196)
+++ code/trunk/cmake/PrecompiledHeaderFiles.cmake	(revision 3196)
@@ -0,0 +1,161 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        This program is free software; you can redistribute it and/or
+ #         modify it under the terms of the GNU General Public License
+ #        as published by the Free Software Foundation; either version 2
+ #            of the License, or (at your option) any later version.
+ #
+ #       This program is distributed in the hope that it will be useful,
+ #        but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ #                 GNU General Public License for more details.
+ #
+ #   You should have received a copy of the GNU General Public License along
+ #      with this program; if not, write to the Free Software Foundation,
+ #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ #
+ #
+ #  Author:
+ #    Reto Grieder
+ #
+
+INCLUDE(GetGCCCompilerFlags)
+ 
+MACRO(PRECOMPILED_HEADER_FILES_PRE_TARGET _target_name _header_file_arg _sourcefile_var)
+
+  GET_FILENAME_COMPONENT(_pch_header_file ${_header_file_arg} ABSOLUTE)
+  GET_FILENAME_COMPONENT(_pch_header_filename ${_pch_header_file} NAME)
+  GET_FILENAME_COMPONENT(_pch_header_filename_we ${_pch_header_file} NAME_WE)
+
+  IF(NOT EXISTS ${_pch_header_file})
+    MESSAGE(FATAL_ERROR "Specified precompiled headerfile '${_header_file_arg}' does not exist.")
+  ENDIF()
+
+  # Extract arguments from ARGN
+  FOREACH(_arg ${ARGN})
+    IF(NOT "${_arg}" STREQUAL "EXCLUDE")
+      IF(NOT _arg_second)
+        # Source files with PCH support
+        SET(_included_files ${_included_files} ${_arg})
+      ELSE()
+        # Source files to be excluded from PCH support (easier syntax this way)
+        SET(_excluded files ${_excluded_files} ${_arg})
+      ENDIF()
+    ELSE()
+      SET(_arg_second TRUE)
+    ENDIF()
+  ENDFOREACH(_arg)
+
+  # Use ${_sourcefile_var} if no files were specified explicitely
+  IF(NOT _included_files)
+    SET(_source_files ${${_sourcefile_var}})
+  ELSE()
+    SET(_source_files ${_included_files})
+  ENDIF()
+
+  # Exclude files (if specified)
+  FOREACH(_file ${_excluded_files})
+    LIST(FIND _source_files ${_file} _list_index)
+    IF(_list_index GREATER -1)
+      LIST(REMOVE_AT _source_files _list_index)
+    ELSE()
+      MESSAGE(FATAL_ERROR "Could not exclude file ${_file} in target ${_target_name}")
+    ENDIF()
+  ENDFOREACH(_file)
+
+  LIST(FIND ${_sourcefile_var} ${_pch_header_file} _list_index)
+  IF(_list_index EQUAL -1) # Header file could already be included with GET_ALL_HEADER_FILES
+    LIST(APPEND ${_sourcefile_var} ${_pch_header_file})
+  ENDIF()
+  SOURCE_GROUP("PCH" FILES ${_pch_header_file})
+
+  IF(MSVC)
+
+    # Write and add one source file, which generates the precompiled header file
+    SET(_pch_source_file "${CMAKE_CURRENT_BINARY_DIR}/${_pch_header_filename_we}.cc")
+    IF(NOT EXISTS ${_pch_source_file})
+      FILE(WRITE ${_pch_source_file} "#include \"${_pch_header_file}\"\n")
+    ENDIF()
+    SET_SOURCE_FILES_PROPERTIES(_pch_source_file PROPERTIES GENERATED TRUE)
+    LIST(APPEND ${_sourcefile_var} ${_pch_source_file})
+    SOURCE_GROUP("PCH" FILES ${_pch_source_file})
+
+    SET(_pch_file "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${_pch_header_filename}.pch")
+    # Set compile flags for generated source file
+    SET_SOURCE_FILES_PROPERTIES(${_pch_source_file} PROPERTIES COMPILE_FLAGS "/c /Yc\"${_pch_header_file}\" /Fp\"${_pch_file}\"")
+    # Set Compile flags for the other source files
+    FOREACH(_file ${_source_files})
+      GET_SOURCE_FILE_PROPERTY(_is_header ${_file} HEADER_FILE_ONLY)
+      IF(NOT _is_header)
+        GET_SOURCE_FILE_PROPERTY(_old_flags ${_file} COMPILE_FLAGS)
+        IF(NOT _old_flags)
+          SET(_old_flags "")
+        ENDIF()
+	SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES COMPILE_FLAGS "${_old_flags} /FI\"${_pch_header_file}\" /Yu\"${_pch_header_file}\" /Fp\"${_pch_file}\"")
+      ENDIF(NOT _is_header)
+    ENDFOREACH(_file)
+
+  ELSEIF(CMAKE_COMPILER_IS_GNU)
+
+    SET(_pch_file "${CMAKE_CURRENT_BINARY_DIR}/${_pch_header_filename}.gch")
+    SET(_pch_dep_helper_file "${CMAKE_CURRENT_BINARY_DIR}/${_target_name}PCHDependencyHelper.h")
+
+    # Append the gch-dir to make sure gcc finds the pch file
+    INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
+
+    # Get compiler flags of the source files (target does not yet exist!)
+    # This is just the best possible opportunity to address this dependency issue
+    GET_GCC_COMPILER_FLAGS(${_target_name} _pch_gcc_flags)
+    # Make sure we recompile the pch file even if only the flags change
+    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
+    FOREACH(_file ${_source_files})
+      GET_SOURCE_FILE_PROPERTY(_is_header ${_file} HEADER_FILE_ONLY)
+      IF(NOT _is_header)
+        GET_SOURCE_FILE_PROPERTY(_old_flags ${_file} COMPILE_FLAGS)
+        IF(NOT _old_flags)
+          SET(_old_flags "")
+        ENDIF()
+        SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES
+          COMPILE_FLAGS "${_old_flags} -include ${_pch_header_filename}"
+          OBJECT_DEPENDS "${_pch_header_file};${_pch_file}"
+        )
+      ENDIF(NOT _is_header)
+    ENDFOREACH(_file)
+
+  ENDIF()
+
+ENDMACRO(PRECOMPILED_HEADER_FILES_PRE_TARGET)
+
+FUNCTION(PRECOMPILED_HEADER_FILES_POST_TARGET _target_name)
+    # This macro is only necessary for GCC
+    IF(CMAKE_COMPILER_IS_GNU)
+
+      # Workaround for distcc
+      IF(CMAKE_CXX_COMPILER_ARG1)
+        # remove leading space in compiler argument
+        STRING(REGEX REPLACE "^ +" "" _pch_cmake_cxx_compiler_arg1 "${CMAKE_CXX_COMPILER_ARG1}")
+      ENDIF()
+
+      # Get compiler flags of the source files again (target exists this time)
+      GET_GCC_COMPILER_FLAGS(${_target_name} _pch_gcc_flags)
+
+      # Compile the header file
+      ADD_CUSTOM_COMMAND(
+        OUTPUT ${_pch_file}
+        COMMAND ${CMAKE_CXX_COMPILER}
+        ARGS ${pchsupport_compiler_cxx_arg1} ${_pch_gcc_flags} -c -x c++-header -o ${_pch_file} ${_pch_header_file}
+	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+        DEPENDS ${_pch_header_file} ${_pch_dep_helper_file}
+        IMPLICIT_DEPENDS ${_pch_header_file}
+        VERBATIM
+      )
+
+    ENDIF(CMAKE_COMPILER_IS_GNU)
+ENDFUNCTION(PRECOMPILED_HEADER_FILES_POST_TARGET)
Index: code/trunk/cmake/SeparateFlags.cmake
===================================================================
--- code/trunk/cmake/SeparateFlags.cmake	(revision 3196)
+++ code/trunk/cmake/SeparateFlags.cmake	(revision 3196)
@@ -0,0 +1,63 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        This program is free software; you can redistribute it and/or
+ #         modify it under the terms of the GNU General Public License
+ #        as published by the Free Software Foundation; either version 2
+ #            of the License, or (at your option) any later version.
+ #
+ #       This program is distributed in the hope that it will be useful,
+ #        but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ #                 GNU General Public License for more details.
+ #
+ #   You should have received a copy of the GNU General Public License along
+ #      with this program; if not, write to the Free Software Foundation,
+ #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ #
+ #
+ #  Author:
+ #    Reto Grieder
+ #  Description:
+ #    Separates a string of program flags like "--blubb -test -D AA".
+ #    " -" or " /" denotes the start of a flag.
+ #    The same sequence inside double quotation marks is being ignored.
+ #    Spaces not within quotes are cleaned meaningfully.
+ #  Note:
+ #    This macro cannot cope with semicolons in the flag string!
+
+FUNCTION(SEPARATE_FLAGS _flags _output_variable)
+  # Visual studio (esp. IntelliSense) doesn't like dashes to specify arguments
+  # Always use foward slashes instead
+  IF(MSVC)
+    SET(_argument_starter "/")
+  ELSE()
+    SET(_argument_starter "-")
+  ENDIF(MSVC)
+
+  SET(_flags_prep " ${_flags} -")
+  # Separate the chunks
+  STRING(REPLACE " " " ;" _flag_chunks "${_flags_prep}") # Max loop iterations
+  SET(_flag_string)
+  SET(_parsed_flags)
+  # Loop is necessary because the regex engine is greedy
+  FOREACH(_chunk ${_flag_chunks})
+    SET(_flag_string "${_flag_string}${_chunk}")
+    # Replace all " -" and " /" inside quotation marks
+    STRING(REGEX REPLACE "^(([^\"]*\"[^\"]*\")*[^\"]*\"[^\"]*) [/-]([^\"]*\")"
+           "\\1@39535493@\\3" _flag_string "${_flag_string}")
+    # Extract one flag if possible
+    SET(_flag)
+    STRING(REGEX REPLACE "^.* [/-](.+)( [/-].*$)" "${_argument_starter}\\1" _flag "${_flag_string}")
+    STRING(REGEX REPLACE "^.* [/-](.+)( [/-].*$)" "\\2"  _flag_string "${_flag_string}")
+    IF(NOT _flag STREQUAL _flag_string)
+      STRING(STRIP "${_flag}" _flag_stripped)
+      LIST(APPEND _parsed_flags "${_flag_stripped}")
+    ENDIF(NOT _flag STREQUAL _flag_string)
+  ENDFOREACH(_chunk)
+
+  # Re-replace all " -" and " /" inside quotation marks
+  STRING(REGEX REPLACE "@39535493@" " -" _parsed_flags "${_parsed_flags}")
+  SET(${_output_variable} "${_parsed_flags}" PARENT_SCOPE)
+ENDFUNCTION(SEPARATE_FLAGS)
Index: code/trunk/cmake/SetCacheAdvanced.cmake
===================================================================
--- code/trunk/cmake/SetCacheAdvanced.cmake	(revision 3196)
+++ code/trunk/cmake/SetCacheAdvanced.cmake	(revision 3196)
@@ -0,0 +1,36 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        This program is free software; you can redistribute it and/or
+ #         modify it under the terms of the GNU General Public License
+ #        as published by the Free Software Foundation; either version 2
+ #            of the License, or (at your option) any later version.
+ #
+ #       This program is distributed in the hope that it will be useful,
+ #        but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ #                 GNU General Public License for more details.
+ #
+ #   You should have received a copy of the GNU General Public License along
+ #      with this program; if not, write to the Free Software Foundation,
+ #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ #
+ #
+ #  Author:
+ #    Reto Grieder
+ #  Description:
+ #    Write to the cache by force, but only if the user hasn't changed the value
+ #    Additional argument is the value (may also be a list)
+
+FUNCTION(SET_CACHE_ADVANCED _varname _type _docstring)
+  SET(_value ${ARGN})
+  IF(NOT "${_type}" MATCHES "^(STRING|BOOL|PATH|FILEPATH)$")
+    MESSAGE(FATAL_ERROR "${_type} is not a valid CACHE entry type")
+  ENDIF()
+
+  IF(NOT DEFINED _INTERNAL_${_varname} OR "${_INTERNAL_${_varname}}" STREQUAL "${${_varname}}")
+    SET(${_varname} "${_value}" CACHE ${_type} "${_docstring}" FORCE)
+    SET(_INTERNAL_${_varname} "${_value}" CACHE INTERNAL "Do not edit in any case!")
+  ENDIF()
+ENDFUNCTION(SET_CACHE_ADVANCED)
Index: code/trunk/cmake/TargetUtilities.cmake
===================================================================
--- code/trunk/cmake/TargetUtilities.cmake	(revision 3196)
+++ code/trunk/cmake/TargetUtilities.cmake	(revision 3196)
@@ -0,0 +1,183 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        This program is free software; you can redistribute it and/or
+ #         modify it under the terms of the GNU General Public License
+ #        as published by the Free Software Foundation; either version 2
+ #            of the License, or (at your option) any later version.
+ #
+ #       This program is distributed in the hope that it will be useful,
+ #        but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ #                 GNU General Public License for more details.
+ #
+ #   You should have received a copy of the GNU General Public License along
+ #      with this program; if not, write to the Free Software Foundation,
+ #     Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ #
+ #
+ #  Author:
+ #    Reto Grieder
+ #  Description:
+ #    Adds a library or an executable like ADD_LIBRARY/ADD_EXECUTABLE, but
+ #    accepts a lot more input information. Simply supply the keywords
+ #    described below in any order you wish.
+ #
+ #    Switches: (when given --> TRUE, FALSE otherwise)
+ #      FIND_HEADER_FILES: Searches the current directory for all header files
+ #                         and adds them to the target.
+ #      EXCLUDE_FROM_ALL:  Inherited from ADD_LIBRARY/ADD_EXECUTABLE
+ #      ORXONOX_EXTERNAL:  Specify this for third party libraries
+ #      NO_DLL_INTERFACE:  Link statically with MSVC
+ #      NO_SOURCE_GROUPS:  Don't create msvc source groups
+ #      STATIC/SHARED:     Inherited from ADD_LIBRARY
+ #      WIN32:             Inherited from ADD_EXECUTABLE
+ #      PCH_NO_DEFAULT:    Do not make precompiled header files default if
+ #                         specified with PCH_FILE
+ #    Lists:
+ #      LINK_LIBRARIES:    Redirects to TARGET_LINK_LIBRARIES
+ #      VERSION:           Set version to the binary
+ #      SOURCE_FILES:      Source files for the target
+ #      DEFINE_SYMBOL:     Sets the DEFINE_SYMBOL target property
+ #      TOLUA_FILES:       Files with tolua interface
+ #      PCH_FILE:          Precompiled header file
+ #      PCH_EXCLUDE:       Source files to be excluded from PCH support
+ #  Note:
+ #    This function also installs the target!
+ #  Prerequisistes:
+ #    ORXONOX_DEFAULT_LINK, ORXONOX_CONFIG_FILES
+ #  Parameters:
+ #    _target_name, ARGN for the macro arguments
+ #
+
+INCLUDE(CapitaliseName)
+INCLUDE(GenerateToluaBindings)
+INCLUDE(ParseMacroArguments)
+INCLUDE(SourceFileUtilities)
+IF(PCH_COMPILER_SUPPORT)
+  INCLUDE(PrecompiledHeaderFiles)
+ENDIF()
+
+FUNCTION(ORXONOX_ADD_LIBRARY _target_name)
+  TU_ADD_TARGET(${_target_name} LIBRARY "STATIC;SHARED" ${ARGN})
+ENDFUNCTION(ORXONOX_ADD_LIBRARY)
+
+FUNCTION(ORXONOX_ADD_EXECUTABLE _target_name)
+  TU_ADD_TARGET(${_target_name} EXECUTABLE "WIN32" ${ARGN})
+ENDFUNCTION(ORXONOX_ADD_EXECUTABLE)
+
+
+FUNCTION(TU_ADD_TARGET _target_name _target_type _additional_switches)
+  CAPITALISE_NAME(${_target_name} _target_name_capitalised)
+
+  # Specify all possible options (either switch or with add. arguments)
+  SET(_switches   FIND_HEADER_FILES  EXCLUDE_FROM_ALL  ORXONOX_EXTERNAL
+                  NO_DLL_INTERFACE   NO_SOURCE_GROUPS  ${_additional_switches}
+                  PCH_NO_DEFAULT)
+  SET(_list_names LINK_LIBRARIES  VERSION   SOURCE_FILES  DEFINE_SYMBOL
+                  TOLUA_FILES     PCH_FILE  PCH_EXCLUDE)
+  PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
+
+
+  # GET_HEADER_FILES
+  IF(_arg_FIND_HEADER_FILES)
+    GET_ALL_HEADER_FILES(_${target_name}_header_files)
+  ENDIF()
+
+  # Remove potential duplicates
+  SET(_${_target_name}_files ${_${target_name}_header_files} ${_arg_SOURCE_FILES})
+  LIST(REMOVE_DUPLICATES _${_target_name}_files)
+
+  # Generate the source groups
+  IF(NOT _arg_NO_SOURCE_GROUPS)
+    GENERATE_SOURCE_GROUPS(${_${_target_name}_files})
+
+    IF(NOT _arg_ORXONOX_EXTERNAL)
+      # Move the prereqs.h file to the config section
+      IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_target_name_capitalised}Prereqs.h)
+        SOURCE_GROUP("Config" FILES ${_target_name_capitalised}Prereqs.h)
+      ENDIF()
+      # Add the config files in a special source group
+      LIST(APPEND _${_target_name}_files ${ORXONOX_CONFIG_FILES})
+      SOURCE_GROUP("Config" FILES ${ORXONOX_CONFIG_FILES})
+    ENDIF()
+  ENDIF(NOT _arg_NO_SOURCE_GROUPS)
+
+  # TOLUA_FILES
+  IF(_arg_TOLUA_FILES)
+    GENERATE_TOLUA_BINDINGS(${_target_name_capitalised} _${_target_name}_files
+                            INPUTFILES ${_arg_TOLUA_FILES})
+  ENDIF()
+
+  # First part (pre target) of precompiled header files
+  IF(PCH_COMPILER_SUPPORT AND _arg_PCH_FILE)
+    # Provide convenient option to control PCH
+    STRING(TOUPPER "${_target_name}" _target_name_upper)
+    IF(_arg_PCH_NO_DEFAULT)
+      SET(PCH_DEFAULT FALSE)
+    ELSE()
+      SET(PCH_DEFAULT TRUE)
+    ENDIF()
+    OPTION(PCH_ENABLE_${_target_name_upper} "Enable using precompiled header files for library ${_target_name}." ${PCH_DEFAULT})
+
+    IF(PCH_ENABLE_${_target_name_upper})
+      PRECOMPILED_HEADER_FILES_PRE_TARGET(${_target_name} ${_arg_PCH_FILE} _${_target_name}_files EXCLUDE ${_arg_PCH_EXCLUDE})
+    ENDIF()
+  ENDIF()
+
+  # Certain libraries don't have dllexport/dllimport and can't be linked shared with msvc
+  IF(MSVC AND _arg_NO_DLL_INTERFACE)
+    SET(_arg_SHARED)
+    SET(_arg_STATIC STATIC)
+  ENDIF()
+
+  # Set default linking if required
+  IF(NOT _arg_SHARED AND NOT _arg_STATIC)
+    IF("${ORXONOX_DEFAULT_LINK}" STREQUAL "STATIC")
+      SET(_arg_STATIC STATIC)
+    ELSEIF("${ORXONOX_DEFAULT_LINK}" STREQUAL "SHARED")
+      SET(_arg_SHARED SHARED)
+    ENDIF()
+  ENDIF()
+
+  # Add the library/executable
+  IF("${_target_type}" STREQUAL "LIBRARY")
+    ADD_LIBRARY(${_target_name} ${_arg_STATIC} ${_arg_SHARED}
+                ${_arg_EXCLUDE_FROM_ALL} ${_${_target_name}_files})
+  ELSE()
+    ADD_EXECUTABLE(${_target_name} ${_arg_WIN32} ${_arg_EXCLUDE_FROM_ALL}
+                   ${_${_target_name}_files})
+  ENDIF()
+
+  # LINK_LIBRARIES
+  IF(_arg_LINK_LIBRARIES)
+    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBRARIES})
+  ENDIF()
+
+  # DEFINE_SYMBOL
+  IF(_arg_DEFINE_SYMBOL)
+    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES DEFINE_SYMBOL ${_arg_DEFINE_SYMBOL})
+  ENDIF()
+
+  # VERSION
+  IF(_arg_VERSION)
+    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${_arg_VERSION})
+  ELSEIF(NOT _arg_ORXONOX_EXTERNAL)
+    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES VERSION ${ORXONOX_VERSION})
+  ENDIF()
+
+  # Second part of precompiled header files
+  IF(PCH_COMPILER_SUPPORT AND PCH_ENABLE_${_target_name_upper} AND _arg_PCH_FILE)
+    PRECOMPILED_HEADER_FILES_POST_TARGET(${_target_name} ${_arg_PCH_FILE})
+  ENDIF()
+
+  IF(NOT _arg_STATIC)
+    INSTALL(TARGETS ${_target_name}
+      RUNTIME DESTINATION ${ORXONOX_RUNTIME_INSTALL_PATH}
+      LIBRARY DESTINATION ${ORXONOX_LIBRARY_INSTALL_PATH}
+      #ARCHIVE DESTINATION ${ORXONOX_ARCHIVE_INSTALL_PATH}
+    )
+  ENDIF()
+
+ENDFUNCTION(TU_ADD_TARGET)
