Index: /code/trunk/cmake/CompilerConfigMSVC.cmake
===================================================================
--- /code/trunk/cmake/CompilerConfigMSVC.cmake	(revision 7817)
+++ /code/trunk/cmake/CompilerConfigMSVC.cmake	(revision 7818)
@@ -35,15 +35,4 @@
 
 ######################## Options ########################
-
-# Currently VLD has a problem with MSVC9 although it actually is supported
-IF(MSVC80)
-  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
@@ -159,4 +148,6 @@
 IF(ORXONOX_RELEASE)
   ADD_LINKER_FLAGS("-INCREMENTAL:NO -OPT:ICF -OPT:REF -LTCG" ReleaseAll   CACHE)
+  # Static linker flags have to be added manually to a target
+  SET(ORXONOX_STATIC_LINKER_FLAGS "/LTCG")
 ELSE()
   ADD_LINKER_FLAGS("-INCREMENTAL:YES"                  RelWithDebInfo     CACHE)
Index: /code/trunk/cmake/PackageConfigMSVC.cmake
===================================================================
--- /code/trunk/cmake/PackageConfigMSVC.cmake	(revision 7817)
+++ /code/trunk/cmake/PackageConfigMSVC.cmake	(revision 7818)
@@ -57,9 +57,3 @@
   SET(ZLIB_LIBRARY ${DEP_LIBRARY_DIR}/zdll.lib  CACHE FILEPATH "")
 
-  # Visual Leak Detector
-  SET(VLD_INCLUDE_DIR  ${DEP_INCLUDE_DIR}/vld   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/tools/SourceFileUtilities.cmake
===================================================================
--- /code/trunk/cmake/tools/SourceFileUtilities.cmake	(revision 7817)
+++ /code/trunk/cmake/tools/SourceFileUtilities.cmake	(revision 7818)
@@ -34,52 +34,16 @@
 
 FUNCTION(PREPARE_SOURCE_FILES)
-  SET(_fullpath_sources)
+  SET(_source_files)
   FOREACH(_file ${ARGN})
-    IF(_file STREQUAL "COMPILATION_BEGIN")
-      SET(_compile TRUE)
-      # Next file is the name of the compilation
-      SET(_get_name TRUE)
-    ELSEIF(_get_name)
-      SET(_get_name FALSE)
-      SET(_compilation_name ${_file})
-    ELSEIF(_file STREQUAL "COMPILATION_END")
-      IF(NOT _compilation_name)
-        MESSAGE(FATAL_ERROR "No name provided for source file compilation")
-      ENDIF()
-      IF(NOT DISABLE_COMPILATIONS)
-        SET(_compilation_file ${CMAKE_CURRENT_BINARY_DIR}/${_compilation_name})
-        SET(_include_string)
-        FOREACH(_file2 ${_compilation})
-          SET(_include_string "${_include_string}#include \"${_file2}\"\n")
-        ENDFOREACH(_file2)
-        IF(EXISTS ${_compilation_file})
-          FILE(READ ${_compilation_file} _include_string_file)
-        ENDIF()
-        IF(NOT _include_string STREQUAL "${_include_string_file}")
-          FILE(WRITE ${_compilation_file} "${_include_string}")
-        ENDIF()
-        LIST(APPEND _fullpath_sources ${_compilation_file})
-        # MSVC hack that excludes the compilations from the intellisense database
-        # (There is a bug with the "-" instead of "/". Only works for "Zm#" argument)
-        # 2nd Note: Exploiting this results in a strange separation of the compilation
-        # file, causing the compiler not to use multi processing --> slower compiling.
-        #IF(MSVC)
-        #    SET_SOURCE_FILES_PROPERTIES(${_compilation_file} PROPERTIES COMPILE_FLAGS "-Zm1000")
-        #ENDIF()
-      ENDIF()
-      SET(_compilation_name)
-      SET(_compilation)
-      SET(_compile FALSE)
+    IF(_file MATCHES "^(COMPILATION_BEGIN|COMPILATION_END)$")
+      # Append keywords verbatim
+      LIST(APPEND _source_files ${_file})
     ELSE()
-      # Prefix the full path
-      GET_SOURCE_FILE_PROPERTY(_filepath ${_file} LOCATION)
-      LIST(APPEND _fullpath_sources ${_filepath})
-      IF(_compile AND NOT DISABLE_COMPILATIONS)
-        LIST(APPEND _compilation ${_filepath})
-        LIST(APPEND _fullpath_sources "H")
-      ENDIF()
+      # Store file with path relative to the root source directory
+      FILE(RELATIVE_PATH _file_rel ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
+      LIST(APPEND _source_files ./${_file_rel})
     ENDIF()
   ENDFOREACH(_file)
-  SET(_fullpath_sources ${_fullpath_sources} PARENT_SCOPE)
+  SET(_source_files ${_source_files} PARENT_SCOPE)
 ENDFUNCTION(PREPARE_SOURCE_FILES)
 
@@ -89,5 +53,5 @@
   PREPARE_SOURCE_FILES(${ARGN})
   # Write into the cache to avoid variable scoping in subdirs
-  SET(${_varname} ${${_varname}} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
+  SET(${_varname} ${${_varname}} ${_source_files} CACHE INTERNAL "Do not edit")
 ENDFUNCTION(ADD_SOURCE_FILES)
 
@@ -97,5 +61,5 @@
   PREPARE_SOURCE_FILES(${ARGN})
   # Write into the cache to avoid variable scoping in subdirs
-  SET(${_varname} ${_fullpath_sources} CACHE INTERNAL "Do not edit")
+  SET(${_varname} ${_source_files} CACHE INTERNAL "Do not edit")
 ENDFUNCTION(SET_SOURCE_FILES)
 
@@ -113,5 +77,5 @@
     GET_SOURCE_FILE_PROPERTY(_full_filepath ${_file} LOCATION)
     FILE(RELATIVE_PATH _relative_path ${CMAKE_CURRENT_SOURCE_DIR} ${_full_filepath})
-    IF(NOT _relative_path MATCHES "^\\.\\.")
+    IF(NOT _relative_path MATCHES "^\\.\\./") # Has "../" at the beginning
       GET_FILENAME_COMPONENT(_relative_path ${_relative_path} PATH)
       STRING(REPLACE "/" "\\\\" _group_path "${_relative_path}")
Index: /code/trunk/cmake/tools/TargetUtilities.cmake
===================================================================
--- /code/trunk/cmake/tools/TargetUtilities.cmake	(revision 7817)
+++ /code/trunk/cmake/tools/TargetUtilities.cmake	(revision 7818)
@@ -90,13 +90,63 @@
   PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
 
-
-  # Workaround: Source file properties get lost when leaving a subdirectory
-  # Therefore an "H" after a file means we have to set it as HEADER_FILE_ONLY
+  # Process source files with support for compilations
+  # Note: All file paths are relative to the root source directory, even the
+  #       name of the compilation file.
+  SET(_${_target_name}_source_files)
+  SET(_get_compilation_file FALSE)
+  SET(_add_to_compilation FALSE)
   FOREACH(_file ${_arg_SOURCE_FILES})
-    IF(_file STREQUAL "H")
-      SET_SOURCE_FILES_PROPERTIES(${_last_file} PROPERTIES HEADER_FILE_ONLY TRUE)
+    IF(_file STREQUAL "COMPILATION_BEGIN")
+      # Next file is the name of the compilation
+      SET(_get_compilation_file TRUE)
+    ELSEIF(_file STREQUAL "COMPILATION_END")
+      IF(NOT _compilation_file)
+        MESSAGE(FATAL_ERROR "No name provided for source file compilation")
+      ENDIF()
+      IF(NOT _compilation_include_string)
+        MESSAGE(STATUS "Warning: Empty source file compilation!")
+      ENDIF()
+      IF(NOT DISABLE_COMPILATIONS)
+        IF(EXISTS ${_compilation_file})
+          FILE(READ ${_compilation_file} _include_string_file)
+        ENDIF()
+        IF(NOT _compilation_include_string STREQUAL "${_include_string_file}")
+          FILE(WRITE ${_compilation_file} "${_compilation_include_string}")
+        ENDIF()
+        LIST(APPEND _${_target_name}_source_files ${_compilation_file})
+      ENDIF()
+      SET(_add_to_compilation FALSE)
+    ELSEIF(_get_compilation_file)
+      SET(_compilation_file ${CMAKE_BINARY_DIR}/${_file})
+      SET(_get_compilation_file FALSE)
+      SET(_add_to_compilation TRUE)
+      SET(_compilation_include_string)
     ELSE()
-      SET(_last_file ${_file})
+      # Default, add source file
+
+      # Prepare relative paths
+      IF(NOT _file MATCHES "^(.\\:|\\/)")
+        # Path can be relative to the current source directory if the file was
+        # not added with the source file macros. Otherwise there is a "./" at
+        # the beginning of each file and the filename is relative
+        # to the CMAKE_SOURCE_DIR
+        STRING(REGEX REPLACE "^\\.\\/(.+)$" "\\1" _temp ${_file})
+        IF(NOT ${_temp} STREQUAL ${_file})
+          SET(_file ${CMAKE_SOURCE_DIR}/${_temp})
+        ELSE()
+          SET(_file ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
+        ENDIF()
+      ENDIF()
+
       LIST(APPEND _${_target_name}_source_files ${_file})
+
+      # Handle compilations
+      IF(_add_to_compilation AND NOT DISABLE_COMPILATIONS)
+        IF(_file MATCHES "\\.(c|cc|cpp|cxx)$")
+          SET(_compilation_include_string "${_compilation_include_string}#include \"${_file}\"\n")
+        ENDIF()
+        # Don't compile these files, even if they are source files
+        SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
+      ENDIF()
     ENDIF()
   ENDFOREACH(_file)
@@ -172,5 +222,5 @@
   # Don't compile header files
   FOREACH(_file ${_${_target_name}_files})
-    IF(NOT _file MATCHES "\\.(c|cc|cpp)")
+    IF(NOT _file MATCHES "\\.(c|cc|cpp|cxx)$")
       SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
     ENDIF()
@@ -217,4 +267,9 @@
     # Ensure that the main program depends on the module
     SET(ORXONOX_MODULES ${ORXONOX_MODULES} ${_target_name} CACHE STRING "" FORCE)
+  ENDIF()
+
+  # Static library flags are not globally available
+  IF(ORXONOX_STATIC_LINKER_FLAGS)
+    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES STATIC_LIBRARY_FLAGS ${ORXONOX_STATIC_LINKER_FLAGS})
   ENDIF()
 
Index: /code/trunk/doc/api/doxy.config.in
===================================================================
--- /code/trunk/doc/api/doxy.config.in	(revision 7817)
+++ /code/trunk/doc/api/doxy.config.in	(revision 7818)
@@ -609,6 +609,6 @@
 FILE_PATTERNS          = *.cpp \
                          *.cc \
+                         *.c \
                          *.h \
-                         *.hh \
                          *.hpp \
                          *.dox
Index: /code/trunk/src/CMakeLists.txt
===================================================================
--- /code/trunk/src/CMakeLists.txt	(revision 7817)
+++ /code/trunk/src/CMakeLists.txt	(revision 7818)
@@ -84,5 +84,4 @@
   ${DIRECTX_INCLUDE_DIR}
   ${ZLIB_INCLUDE_DIR}
-  ${VLD_INCLUDE_DIR}
 
   # All includes in "externals" should be prefixed with the path
@@ -123,4 +122,6 @@
 ################## Executable ###################
 
+SET_SOURCE_FILES(ORXONOX_MAIN_SRC_FILES Orxonox.cc)
+
 INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_SOURCE_DIR}/libraries
@@ -139,5 +140,5 @@
     orxonox
   SOURCE_FILES
-    Orxonox.cc
+    ${ORXONOX_MAIN_SRC_FILES}
   OUTPUT_NAME orxonox
 )
Index: /code/trunk/src/OrxonoxConfig.cmake
===================================================================
--- /code/trunk/src/OrxonoxConfig.cmake	(revision 7817)
+++ /code/trunk/src/OrxonoxConfig.cmake	(revision 7818)
@@ -79,4 +79,20 @@
 CHECK_INCLUDE_FILE_CXX(iso646.h HAVE_ISO646_H)
 
+IF(MSVC)
+  # Check whether we can use Visual Leak Detector
+  FIND_FILE(VLD_DLL vld_x86.dll)
+  IF(VLD_DLL)
+    SET(HAVE_VLD TRUE)
+    OPTION(VISUAL_LEAK_DETECTOR_ENABLE "Memory leak detector" off)
+    # 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()
+  ENDIF()
+  MARK_AS_ADVANCED(VLD_DLL)
+ENDIF()
+
 ############## Configured Headers ###############
 
Index: /code/trunk/src/OrxonoxConfig.h.in
===================================================================
--- /code/trunk/src/OrxonoxConfig.h.in	(revision 7817)
+++ /code/trunk/src/OrxonoxConfig.h.in	(revision 7818)
@@ -179,7 +179,15 @@
 */
 
-// Always include the memory leak detector for MSVC except for actual releases
-// Note: Although officially supported, VLD does not work with MSVC 9
-#if defined(ORXONOX_COMPILER_MSVC) && _MSC_VER < 1500 && !defined(ORXONOX_RELEASE)
+// Include memory leak detector if available and not building actual release
+#cmakedefine HAVE_VLD
+#if defined(HAVE_VLD) && !defined(ORXONOX_RELEASE)
+typedef uint32_t UINT32;
+typedef wchar_t WCHAR;
+struct HINSTANCE__;
+typedef struct HINSTANCE__* HINSTANCE;
+typedef HINSTANCE HMODULE;
+#  ifndef NULL
+#    define NULL 0
+#  endif
 #  include <vld.h>
 #endif
Index: /code/trunk/src/SpecialConfig.h.in
===================================================================
--- /code/trunk/src/SpecialConfig.h.in	(revision 7817)
+++ /code/trunk/src/SpecialConfig.h.in	(revision 7818)
@@ -52,5 +52,5 @@
 #cmakedefine DBGHELP_FOUND                  ///< If DbgHelp was found on windows
 
-#cmakedefine ORXONOX_USE_WINMAIN            ///< Using MSVC or XCode IDE
+#cmakedefine ORXONOX_USE_WINMAIN            ///< Whether or not the console window is started as well
 
 // Handle default ConfigValues
