Index: code/trunk/cmake/tools/CheckOGREPlugins.cmake
===================================================================
--- code/trunk/cmake/tools/CheckOGREPlugins.cmake	(revision 8264)
+++ code/trunk/cmake/tools/CheckOGREPlugins.cmake	(revision 8351)
@@ -52,10 +52,10 @@
       NAMES ${_plugin}
       PATHS $ENV{OGRE_HOME} $ENV{OGRE_PLUGIN_DIR}
-      PATH_SUFFIXES bin/Release bin/release Release release lib lib/OGRE bin
+      PATH_SUFFIXES bin/Release bin/release Release release lib lib/OGRE bin Ogre.framework/Resources
     )
     FIND_LIBRARY(OGRE_PLUGIN_${_plugin}_DEBUG
       NAMES ${_plugin}d ${_plugin}_d ${_plugin}
       PATHS $ENV{OGRE_HOME} $ENV{OGRE_PLUGIN_DIR}
-      PATH_SUFFIXES bin/Debug bin/debug Debug debug lib lib/OGRE bin
+      PATH_SUFFIXES bin/Debug bin/debug Debug debug lib lib/OGRE bin Ogre.framework/Resources
     )
     # We only need at least one render system. Check at the end.
Index: code/trunk/cmake/tools/CheckPackageVersion.cmake
===================================================================
--- code/trunk/cmake/tools/CheckPackageVersion.cmake	(revision 8351)
+++ code/trunk/cmake/tools/CheckPackageVersion.cmake	(revision 8351)
@@ -0,0 +1,66 @@
+ #
+ #             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:
+ #    Check package version info
+ #    MAJOR: Breaking change
+ #    MINOR: No breaking changes by the dependency package
+ #           For example any code running on 3.0 should still run on 3.1
+ #           But you can specify that the code only runs on 3.1 and higher
+ #           or 4.0 and higher (so both 3.1 and 4.0 will work).
+
+MACRO(CHECK_PACKAGE_VERSION)
+  SET(_allowed_minimum_versions ${ARGN})
+
+  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)
+  SET(_version_match FALSE)
+  FOREACH(_version ${_allowed_minimum_versions})
+    # Get major version
+    STRING(REGEX REPLACE "^([0-9]+)\\..*$" "\\1" _major_version "${_version}")
+    COMPARE_VERSION_STRINGS(${DEPENDENCY_VERSION} ${_major_version} _result TRUE)
+    IF(_result EQUAL 0)
+      COMPARE_VERSION_STRINGS(${DEPENDENCY_VERSION} ${_version} _result FALSE)
+      IF(NOT _result LESS 0)
+        SET(_version_match TRUE)
+      ENDIF()
+    ENDIF()
+  ENDFOREACH(_version)
+  IF(NOT _version_match)
+    MESSAGE(FATAL_ERROR "Your dependency package version is ${DEPENDENCY_VERSION}\n"
+            "Possible required versions: ${_allowed_minimum_versions}\n"
+            "You can get a new version from www.orxonox.net")
+  ENDIF()
+  
+ENDMACRO(CHECK_PACKAGE_VERSION)
Index: code/trunk/cmake/tools/FindALUT.cmake
===================================================================
--- code/trunk/cmake/tools/FindALUT.cmake	(revision 8264)
+++ code/trunk/cmake/tools/FindALUT.cmake	(revision 8351)
@@ -1,72 +1,52 @@
-# - Locate FreeAlut
-# This module defines
-#  ALUT_LIBRARY
-#  ALUT_FOUND, if false, do not try to link against Alut
-#  ALUT_INCLUDE_DIR, where to find the headers
-#
-# $ALUTDIR is an environment variable that would
-# correspond to the ./configure --prefix=$ALUTDIR
-# used in building Alut.
-#
-# Created by Eric Wing. This was influenced by the FindSDL.cmake module.
-# On OSX, this will prefer the Framework version (if found) over others.
-# People will have to manually change the cache values of
-# ALUT_LIBRARY to override this selection.
-# Tiger will include OpenAL as part of the System.
-# But for now, we have to look around.
-# Other (Unix) systems should be able to utilize the non-framework paths.
-#
-# Several changes and additions by Fabian 'x3n' Landau
-# Some simplifications by Adrian Friedli and Reto Grieder
-#                 > www.orxonox.net <
+ #
+ #             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:
+ #    Kevin Young
+ #  Description:
+ #    Variables defined:
+ #      ALUT_FOUND
+ #      ALUT_INCLUDE_DIR
+ #      ALUT_LIBRARY
+ #
 
 INCLUDE(FindPackageHandleStandardArgs)
 INCLUDE(HandleLibraryTypes)
 
-FIND_PATH(ALUT_INCLUDE_DIR AL/alut.h
-  PATHS
-  $ENV{ALUTDIR}
-  ~/Library/Frameworks/OpenAL.framework
-  /Library/Frameworks/OpenAL.framework
-  /System/Library/Frameworks/OpenAL.framework # Tiger
-  PATH_SUFFIXES include include/OpenAL include/AL Headers
+FIND_PATH(ALUT_INCLUDE_DIR alut.h
+  PATHS $ENV{ALUTDIR}
+  PATH_SUFFIXES include include/AL
 )
-
-# I'm not sure if I should do a special casing for Apple. It is
-# unlikely that other Unix systems will find the framework path.
-# But if they do ([Next|Open|GNU]Step?),
-# do they want the -framework option also?
-IF(${ALUT_INCLUDE_DIR} MATCHES ".framework")
-
-  STRING(REGEX REPLACE "(.*)/.*\\.framework/.*" "\\1" ALUT_FRAMEWORK_PATH_TMP ${ALUT_INCLUDE_DIR})
-  IF("${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/Library/Frameworks"
-      OR "${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/System/Library/Frameworks"
-      )
-    # String is in default search path, don't need to use -F
-    SET (ALUT_LIBRARY_OPTIMIZED "-framework OpenAL" CACHE STRING "OpenAL framework for OSX")
-  ELSE()
-    # String is not /Library/Frameworks, need to use -F
-    SET(ALUT_LIBRARY_OPTIMIZED "-F${ALUT_FRAMEWORK_PATH_TMP} -framework OpenAL" CACHE STRING "OpenAL framework for OSX")
-  ENDIF()
-  # Clear the temp variable so nobody can see it
-  SET(ALUT_FRAMEWORK_PATH_TMP "" CACHE INTERNAL "")
-
-ELSE()
-  FIND_LIBRARY(ALUT_LIBRARY_OPTIMIZED
-    NAMES alut
-    PATHS $ENV{ALUTDIR}
-    PATH_SUFFIXES lib libs
-  )
-  FIND_LIBRARY(ALUT_LIBRARY_DEBUG
-    NAMES alutd alut_d alutD alut_D
-    PATHS $ENV{ALUTDIR}
-    PATH_SUFFIXES lib libs
-  )
-ENDIF()
+FIND_LIBRARY(ALUT_LIBRARY_OPTIMIZED
+  NAMES alut ALUT
+  PATHS $ENV{ALUTDIR}
+  PATH_SUFFIXES lib bin/Release bin/release Release release ALUT
+)
+FIND_LIBRARY(ALUT_LIBRARY_DEBUG
+  NAMES alutd alut_d alutD alut_D ALUTd ALUT_d ALUTD ALUT_D
+  PATHS $ENV{ALUTDIR}
+  PATH_SUFFIXES lib bin/Debug bin/debug Debug debug ALUT
+)
 
 # Handle the REQUIRED argument and set ALUT_FOUND
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALUT DEFAULT_MSG
-    ALUT_LIBRARY_OPTIMIZED
-    ALUT_INCLUDE_DIR
+  ALUT_LIBRARY_OPTIMIZED
+  ALUT_INCLUDE_DIR
 )
 
@@ -75,6 +55,6 @@
 
 MARK_AS_ADVANCED(
-    ALUT_INCLUDE_DIR
-    ALUT_LIBRARY_OPTIMIZED
-    ALUT_LIBRARY_DEBUG
+  ALUT_INCLUDE_DIR
+  ALUT_LIBRARY_OPTIMIZED
+  ALUT_LIBRARY_DEBUG
 )
Index: code/trunk/cmake/tools/FindCEGUI.cmake
===================================================================
--- code/trunk/cmake/tools/FindCEGUI.cmake	(revision 8264)
+++ code/trunk/cmake/tools/FindCEGUI.cmake	(revision 8351)
@@ -4,14 +4,11 @@
 #  CEGUI_INCLUDE_DIR
 #  CEGUI_LIBRARY, the library to link against to use CEGUI.
+#  CEGUILUA_LIBRARY, the library to link against to use the CEGUI script module.
+#  CEGUI_TOLUA_LIBRARY, the library to link against to use Tolua++.
 #  CEGUI_FOUND, If false, do not try to use CEGUI
 #  CEGUI_VERSION, the version as string "x.y.z"
-#  CEGUILUA_LIBRARY, Script module library
-#  CEGUILUA_USE_INTERNAL_LIBRARY, True if CEGUILUA_LIBRARY was not defined here
 #
 # Input:
 #  ENV{CEGUIDIR}, CEGUI path, optional
-#  FIND CEGUILUA_INTERNAL_SUPPORT, List of all CEGUILua version supported
-#                                  in the source repository
-#  CEGUILUA_USE_EXTERNAL_LIBRARY, Force finding of CEGUILua
 #
 # Created by Matt Williams to find OGRE libraries
@@ -29,12 +26,19 @@
 #                 > www.orxonox.net <
 
+INCLUDE(CompareVersionStrings)
 INCLUDE(DetermineVersion)
 INCLUDE(FindPackageHandleAdvancedArgs)
 INCLUDE(HandleLibraryTypes)
 
+# Find CEGUI headers
 FIND_PATH(CEGUI_INCLUDE_DIR CEGUI.h
   PATHS $ENV{CEGUIDIR}
-  PATH_SUFFIXES include include/CEGUI CEGUI.framework/Headers
+  PATH_SUFFIXES include include/CEGUI
 )
+
+# Inspect CEGUIVersion.h for the version number
+DETERMINE_VERSION(CEGUI ${CEGUI_INCLUDE_DIR}/CEGUIVersion.h)
+
+# Find CEGUI library
 FIND_LIBRARY(CEGUI_LIBRARY_OPTIMIZED
   NAMES CEGUIBase CEGUI
@@ -50,16 +54,98 @@
 )
 
-# Inspect CEGUIVersion.h for the version number
-DETERMINE_VERSION(CEGUI ${CEGUI_INCLUDE_DIR}/CEGUIVersion.h)
+# Find CEGUILua headers
+FIND_PATH(CEGUILUA_INCLUDE_DIR CEGUILua.h
+  PATHS
+    $ENV{CEGUIDIR}
+    $ENV{CEGUILUADIR}
+    ${CEGUI_INCLUDE_DIR}/ScriptingModules/LuaScriptModule
+  PATH_SUFFIXES include include/CEGUI
+)
+# Find CEGUILua libraries
+FIND_LIBRARY(CEGUILUA_LIBRARY_OPTIMIZED
+  NAMES CEGUILua CEGUILuaScriptModule
+  PATHS $ENV{CEGUIDIR} $ENV{CEGUILUADIR}
+  PATH_SUFFIXES lib bin
+)
+FIND_LIBRARY(CEGUILUA_LIBRARY_DEBUG
+  NAMES CEGUILuad CEGUILua_d CEGUILuaScriptModuled CEGUILuaScriptModule_d
+  PATHS $ENV{CEGUIDIR} $ENV{CEGUILUADIR}
+  PATH_SUFFIXES lib bin
+)
+
+# Find CEGUI Tolua++ include file
+# We only need to add this path since we use tolua++ like a normal
+# dependency but it is shipped with CEGUILua.
+FIND_PATH(CEGUI_TOLUA_INCLUDE_DIR tolua++.h
+  PATHS
+    ${CEGUILUA_INCLUDE_DIR}
+    # For newer CEGUI versions >= 0.7
+    ${CEGUILUA_INCLUDE_DIR}/support/tolua++
+    # For Mac OS X, tolua++ is a separate framework in the dependency package
+    ${DEP_FRAMEWORK_DIR}
+  NO_DEFAULT_PATH # Don't attempt to find tolua++ installed on the system
+)
+# Find CEGUI Tolua++ libraries
+FIND_LIBRARY(CEGUI_TOLUA_LIBRARY_OPTIMIZED
+  NAMES CEGUItoluapp tolua++ ceguitolua++
+  PATHS $ENV{CEGUIDIR} ${CEGUITOLUADIR}
+  PATH_SUFFIXES lib bin
+)
+FIND_LIBRARY(CEGUI_TOLUA_LIBRARY_DEBUG
+  NAMES CEGUItoluappd CEGUItoluapp_d tolua++d tolua++_d
+  PATHS $ENV{CEGUIDIR} ${CEGUITOLUADIR}
+  PATH_SUFFIXES lib bin
+)
+
+# Newer versions of CEGUI have the renderer for OGRE shipped with them
+COMPARE_VERSION_STRINGS("${CEGUI_VERSION}" "0.7" _version_compare TRUE)
+IF(_version_compare GREATER -1)
+  # Find CEGUI OGRE Renderer headers
+  FIND_PATH(CEGUI_OGRE_RENDERER_INCLUDE_DIR CEGUIOgreRenderer.h
+    PATHS
+      $ENV{CEGUIDIR}
+      $ENV{CEGUIOGRERENDERERDIR}
+      ${CEGUI_INCLUDE_DIR}/RendererModules/Ogre
+    PATH_SUFFIXES include include/CEGUI
+  )
+  # Find CEGUI OGRE Renderer libraries
+  FIND_LIBRARY(CEGUI_OGRE_RENDERER_LIBRARY_OPTIMIZED
+    NAMES CEGUIOgreRenderer
+    PATHS $ENV{CEGUIDIR} $ENV{CEGUIOGRERENDERERDIR}
+    PATH_SUFFIXES lib bin
+  )
+  FIND_LIBRARY(CEGUI_OGRE_RENDERER_LIBRARY_DEBUG
+    NAMES CEGUIOgreRendererd CEGUIOgreRenderer_d
+    PATHS $ENV{CEGUIDIR} $ENV{CEGUIOGRERENDERERDIR}
+    PATH_SUFFIXES lib bin
+  )
+  SET(CEGUI_OGRE_RENDERER_REQUIRED_VARIABLES
+    CEGUI_OGRE_RENDERER_INCLUDE_DIR
+    CEGUI_OGRE_RENDERER_LIBRARY_OPTIMIZED
+  )
+ELSE()
+  SET(CEGUI_OLD_VERSION TRUE)
+  SET(CEGUI_OGRE_RENDERER_BUILD_REQUIRED TRUE)
+ENDIF()
 
 # Handle the REQUIRED argument and set CEGUI_FOUND
 # Also checks the version requirements if given
 FIND_PACKAGE_HANDLE_ADVANCED_ARGS(CEGUI DEFAULT_MSG "${CEGUI_VERSION}"
+  CEGUI_INCLUDE_DIR
   CEGUI_LIBRARY_OPTIMIZED
-  CEGUI_INCLUDE_DIR
+  CEGUILUA_INCLUDE_DIR
+  CEGUILUA_LIBRARY_OPTIMIZED
+  CEGUI_TOLUA_INCLUDE_DIR
+  CEGUI_TOLUA_LIBRARY_OPTIMIZED
+  ${CEGUI_OGRE_RENDERER_REQUIRED_VARIABLES}
 )
 
 # Collect optimized and debug libraries
 HANDLE_LIBRARY_TYPES(CEGUI)
+HANDLE_LIBRARY_TYPES(CEGUILUA)
+HANDLE_LIBRARY_TYPES(CEGUI_TOLUA)
+IF(NOT CEGUI_OGRE_RENDERER_BUILD_REQUIRED)
+  HANDLE_LIBRARY_TYPES(CEGUI_OGRE_RENDERER)
+ENDIF()
 
 MARK_AS_ADVANCED(
@@ -67,37 +153,12 @@
   CEGUI_LIBRARY_OPTIMIZED
   CEGUI_LIBRARY_DEBUG
+  CEGUILUA_INCLUDE_DIR
+  CEGUILUA_LIBRARY_OPTIMIZED
+  CEGUILUA_LIBRARY_DEBUG
+  CEGUI_TOLUA_INCLUDE_DIR
+  CEGUI_TOLUA_LIBRARY_OPTIMIZED
+  CEGUI_TOLUA_LIBRARY_DEBUG
+  CEGUI_OGRE_RENDERER_INCLUDE_DIR
+  CEGUI_OGRE_RENDERER_LIBRARY_OPTIMIZED
+  CEGUI_OGRE_RENDERER_LIBRARY_DEBUG
 )
-
-LIST(FIND CEGUILUA_INTERNAL_SUPPORT "${CEGUI_VERSION}" _find_result)
-IF(CEGUILUA_USE_EXTERNAL_LIBRARY OR _find_result EQUAL -1)
-  # Also try to find the CEGUILua libraries.
-  # There would already be libraries in src/ for versions 0.5 and 0.6
-  FIND_LIBRARY(CEGUILUA_LIBRARY_OPTIMIZED
-    NAMES CEGUILua
-    PATHS $ENV{CEGUIDIR}
-    PATH_SUFFIXES lib bin
-  )
-  FIND_LIBRARY(CEGUILUA_LIBRARY_DEBUG
-    NAMES CEGUILuad CEGUILua_d
-    PATHS $ENV{CEGUIDIR}
-    PATH_SUFFIXES lib bin
-  )
-
-  SET(CEGUILua_FIND_REQUIRED ${CEGUI_FIND_REQUIRED})
-  # Handle the REQUIRED argument and set CEGUILUA_FOUND
-  FIND_PACKAGE_HANDLE_STANDARD_ARGS(CEGUILua DEFAULT_MSG
-    CEGUILUA_LIBRARY_OPTIMIZED
-  )
-
-  # Collect optimized and debug libraries
-  HANDLE_LIBRARY_TYPES(CEGUILUA)
-
-  MARK_AS_ADVANCED(
-    CEGUILUA_LIBRARY_OPTIMIZED
-    CEGUILUA_LIBRARY_DEBUG
-  )
-
-ELSE(CEGUILUA_USE_EXTERNAL_LIBRARY OR _find_result EQUAL -1)
-  SET(CEGUILUA_USE_INTERNAL_LIBRARY TRUE)
-ENDIF(CEGUILUA_USE_EXTERNAL_LIBRARY OR _find_result EQUAL -1)
-
Index: code/trunk/cmake/tools/FindLua.cmake
===================================================================
--- code/trunk/cmake/tools/FindLua.cmake	(revision 8264)
+++ 	(revision )
@@ -1,184 +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:
- #    Finds either Lua 5.0 or Lua 5.1 on the system. The script regards the
- #    VERSION, EXACT, REQUIRED and QUIET arguments. A note about the EXACT
- #    argument: EXACT 5 will match all Lua 5 versions.
- #    When the search was successful, the following variables are set:
- #    LUA_INCLUDE_DIR, LUA_LIBRARIES, LUA_VERSION, LUA_FOUND
- #
-
-INCLUDE(CompareVersionStrings)
-INCLUDE(FindPackageHandleAdvancedArgs)
-INCLUDE(HandleLibraryTypes)
-
-# Macro that determines Lua version. Should work for versions 2.2 and above (current release: 5.1.4)
-FUNCTION(DETERMINE_LUA_VERSION _file _varname)
-  IF(EXISTS ${_file})
-    FILE(STRINGS ${_file} _file_content REGEX "LUA_VERSION|LUA_RELEASE")
-  ELSE()
-    SET(${_varname} "0" PARENT_SCOPE)
-    RETURN()
-  ENDIF()
-  STRING(REGEX REPLACE "^.*LUA_RELEASE[ \t]+\"Lua[ \t]+([.0-9]+)\".*$" "\\1" ${_varname} "${_file_content}")
-  IF(${_varname} STREQUAL "${_file_content}")
-    # At most version 5.1.0
-    STRING(REGEX REPLACE "^.*LUA_VERSION[ \t]+\"Lua[ \t]+([.0-9]+)\".*$" "\\1" ${_varname} "${_file_content}")
-    IF(${_varname} STREQUAL "${_file_content}")
-      MESSAGE(FATAL_ERROR "Could not determine Lua version which means this script has a bug")
-    ENDIF()
-    IF(${_varname} MATCHES "^[0-9]+\\.[0-9]+$")
-      SET(${_varname} "${${_varname}}.0") # E.g. "3.2" is "3.2.0" actually
-    ENDIF()
-  ENDIF()
-  SET(${_varname} "${${_varname}}" PARENT_SCOPE)
-ENDFUNCTION(DETERMINE_LUA_VERSION)
-
-
-# Find Lua 5.1
-FIND_PATH(LUA_5.1_INCLUDE_DIR lua.h
-  PATHS $ENV{LUA_DIR}
-  PATH_SUFFIXES include/lua51 include/lua5.1 include/lua include
-)
-IF(LUA_5.1_INCLUDE_DIR)
-  DETERMINE_LUA_VERSION(${LUA_5.1_INCLUDE_DIR}/lua.h LUA_5.1_VERSION)
-  COMPARE_VERSION_STRINGS("${LUA_5.1_VERSION}" "5.1" _version_compare TRUE)
-  IF(NOT _version_compare EQUAL 0)
-    # Incorrect version found, abort search
-    SET(LUA_5.1_INCLUDE_DIR "LUA_5.1_INCLUDE_DIR-NOTFOUND" CACHE PATH "" FORCE)
-  ELSE()
-    FIND_LIBRARY(LUA_5.1_LIBRARY_OPTIMIZED
-      NAMES lua51 lua5.1 lua
-      PATHS $ENV{LUA_DIR}
-      PATH_SUFFIXES lib64 lib
-    )
-    FIND_LIBRARY(LUA_5.1_LIBRARY_DEBUG
-      NAMES lua51d lua51_d lua5.1d lua5.1_d luad lua_d
-            lua51D lua51_D lua5.1D lua5.1_D luad lua_D
-      PATHS $ENV{LUA_DIR}
-      PATH_SUFFIXES lib64 lib
-    )
-    HANDLE_LIBRARY_TYPES(LUA_5.1)
-    SET(LUA_5.1_LIBRARIES ${LUA_5.1_LIBRARY})
-    IF(LUA_5.1_LIBRARIES)
-      SET(LUA_5.1_FOUND TRUE)
-    ENDIF()
-  ENDIF(NOT _version_compare EQUAL 0)
-ENDIF(LUA_5.1_INCLUDE_DIR)
-
-
-# Find Lua 5.0
-FIND_PATH(LUA_5.0_INCLUDE_DIR lua.h
-  PATHS $ENV{LUA_DIR}
-  PATH_SUFFIXES include/lua50 include/lua5.0 include/lua5 include/lua include
-)
-IF(LUA_5.0_INCLUDE_DIR)
-  DETERMINE_LUA_VERSION(${LUA_5.0_INCLUDE_DIR}/lua.h LUA_5.0_VERSION)
-  COMPARE_VERSION_STRINGS("${LUA_5.0_VERSION}" "5.0" _version_compare TRUE)
-  IF(NOT _version_compare EQUAL 0)
-    # Incorrect version found, abourt search
-    SET(LUA_5.0_INCLUDE_DIR "LUA_5.0_INCLUDE_DIR-NOTFOUND" CACHE PATH "" FORCE)
-  ELSE()
-    FIND_LIBRARY(LUA_5.0_LUA_LIBRARY_OPTIMIZED
-      NAMES lua50 lua5.0 lua5 lua
-      PATHS $ENV{LUA_DIR}
-      PATH_SUFFIXES lib64 lib
-    )
-    FIND_LIBRARY(LUA_5.0_LUA_LIBRARY_DEBUG
-      NAMES lua50d lua50_d lua5.0d lua5.0_d lua5d lua5_d luad lua_d
-            lua50D lua50_D lua5.0D lua5.0_D lua5d lua5_D luaD lua_D
-      PATHS $ENV{LUA_DIR}
-      PATH_SUFFIXES lib64 lib
-    )
-    HANDLE_LIBRARY_TYPES(LUA_5.0_LUA)
-
-    # In an OS X framework, lualib is usually included as part of the framework
-    # (like GLU in OpenGL.framework)
-    IF(${LUA_5.0_LUA_LIBRARY} MATCHES "framework")
-      SET(LUA_5.0_LIBRARIES ${LUA_5.0_LUA_LIBRARY})
-    ELSE()
-      FIND_LIBRARY(LUA_5.0_LUALIB_LIBRARY_OPTIMIZED
-        NAMES lualib50 lualib5.0 lualib5 lualib
-        PATHS $ENV{LUALIB_DIR} $ENV{LUA_DIR}
-        PATH_SUFFIXES lib64 lib
-      )
-      FIND_LIBRARY(LUA_5.0_LUALIB_LIBRARY_DEBUG
-        NAMES lualib50d lualib50_d lualib5.0d lualib5.0_d
-              lualib5d lualib5_d lualibd lualib_d
-              lualib50D lualib50_D lualib5.0D lualib5.0_D
-              lualib5D lualib5_D lualibD lualib_D
-        PATHS $ENV{LUALIB_DIR} $ENV{LUA_DIR}
-        PATH_SUFFIXES lib64 lib
-      )
-      HANDLE_LIBRARY_TYPES(LUA_5.0_LUALIB)
-      # Both libraries are required for Lua 5.0 to be found
-      IF(LUA_5.0_LUA_LIBRARY AND LUA_5.0_LUALIB_LIBRARY)
-        SET(LUA_5.0_LIBRARIES ${LUA_5.0_LUA_LIBRARY} ${LUA_5.0_LUALIB_LIBRARY})
-      ENDIF()
-    ENDIF(${LUA_5.0_LUA_LIBRARY} MATCHES "framework")
-
-    IF(LUA_5.0_LIBRARIES)
-      SET(LUA_5.0_FOUND TRUE)
-    ENDIF()
-  ENDIF(NOT _version_compare EQUAL 0)
-ENDIF(LUA_5.0_INCLUDE_DIR)
-
-# Pick the right version
-IF(Lua_FIND_VERSION_EXACT AND NOT Lua_FIND_VERSION MATCHES "^[0-9]*$")
-  STRING(REGEX REPLACE "^([0-9]+\\.[0-9]+)(\\..*)?$" "\\1" LUA_VERSION_SELECTION ${Lua_FIND_VERSION})
-ELSE()
-  IF(LUA_5.1_FOUND) # Prefer version 5.1 if found
-    SET(LUA_VERSION_SELECTION "5.1")
-  ELSEIF(LUA_5.0_FOUND)
-    SET(LUA_VERSION_SELECTION "5.0")
-  ENDIF()
-ENDIF()
-
-SET(LUA_INCLUDE_DIR "${LUA_${LUA_VERSION_SELECTION}_INCLUDE_DIR}")
-SET(LUA_LIBRARIES "${LUA_${LUA_VERSION_SELECTION}_LIBRARIES}")
-SET(LUA_VERSION_LONG "${LUA_${LUA_VERSION_SELECTION}_VERSION}")
-SET(LUA_VERSION "${LUA_VERSION_SELECTION}")
-
-FIND_PACKAGE_HANDLE_ADVANCED_ARGS(Lua DEFAULT_MSG "${LUA_VERSION_LONG}"
-  LUA_LIBRARIES
-  LUA_INCLUDE_DIR
-)
-
-# Include the math library for Unix only
-IF(LUA_FOUND)
-  IF(UNIX AND NOT APPLE)
-    FIND_LIBRARY(UNIX_MATH_LIBRARY m)
-    SET(LUA_LIBRARIES ${LUA_LIBRARIES} ${UNIX_MATH_LIBRARY})
-  ENDIF()
-ENDIF(LUA_FOUND)
-
-MARK_AS_ADVANCED(
-  LUA_5.0_INCLUDE_DIR
-  LUA_5.0_LUA_LIBRARY_OPTIMIZED
-  LUA_5.0_LUA_LIBRARY_DEBUG
-  LUA_5.0_LUALIB_LIBRARY_OPTIMIZED
-  LUA_5.0_LUALIB_LIBRARY_DEBUG
-  LUA_5.1_INCLUDE_DIR
-  LUA_5.1_LIBRARY_OPTIMIZED
-  LUA_5.1_LIBRARY_DEBUG
-  UNIX_MATH_LIBRARY
-)
Index: code/trunk/cmake/tools/FindLua5.1.cmake
===================================================================
--- code/trunk/cmake/tools/FindLua5.1.cmake	(revision 8351)
+++ code/trunk/cmake/tools/FindLua5.1.cmake	(revision 8351)
@@ -0,0 +1,100 @@
+ #
+ #             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:
+ #    Finds Lua 5.1 on the system.
+ #    Handles REQUIRED and QUIET arguments.
+ #    When the search was successful, the following variables are set:
+ #    LUA5.1_INCLUDE_DIR, LUA5.1_LIBRARY, LUA5.1_VERSION, LUA5.1_FOUND
+ #
+
+INCLUDE(CompareVersionStrings)
+INCLUDE(FindPackageHandleAdvancedArgs)
+INCLUDE(HandleLibraryTypes)
+
+# Macro that determines Lua version. Should work for versions 2.2 and above (current release: 5.1.4)
+FUNCTION(DETERMINE_LUA_VERSION _file _varname)
+  IF(EXISTS ${_file})
+    FILE(STRINGS ${_file} _file_content REGEX "LUA_VERSION|LUA_RELEASE")
+  ELSE()
+    SET(${_varname} "0" PARENT_SCOPE)
+    RETURN()
+  ENDIF()
+  STRING(REGEX REPLACE "^.*LUA_RELEASE[ \t]+\"Lua[ \t]+([.0-9]+)\".*$" "\\1" ${_varname} "${_file_content}")
+  IF(${_varname} STREQUAL "${_file_content}")
+    # At most version 5.1.0
+    STRING(REGEX REPLACE "^.*LUA_VERSION[ \t]+\"Lua[ \t]+([.0-9]+)\".*$" "\\1" ${_varname} "${_file_content}")
+    IF(${_varname} STREQUAL "${_file_content}")
+      MESSAGE(FATAL_ERROR "Could not determine Lua version which means this script has a bug")
+    ENDIF()
+    IF(${_varname} MATCHES "^[0-9]+\\.[0-9]+$")
+      SET(${_varname} "${${_varname}}.0") # E.g. "3.2" is "3.2.0" actually
+    ENDIF()
+  ENDIF()
+  SET(${_varname} "${${_varname}}" PARENT_SCOPE)
+ENDFUNCTION(DETERMINE_LUA_VERSION)
+
+
+# Find include path
+FIND_PATH(LUA5.1_INCLUDE_DIR lua.h
+  PATHS $ENV{LUA5.1_DIR} $ENV{LUA_DIR}
+  PATH_SUFFIXES include/lua51 include/lua5.1 include/lua include
+)
+
+# Check whether we really found Lua version 5.1
+IF(LUA5.1_INCLUDE_DIR)
+  DETERMINE_LUA_VERSION(${LUA5.1_INCLUDE_DIR}/lua.h LUA5.1_VERSION)
+  COMPARE_VERSION_STRINGS("${LUA5.1_VERSION}" "5.1" _version_compare TRUE)
+  IF(NOT _version_compare EQUAL 0)
+    # Wrong version
+    MESSAGE(SEND_ERROR "Version of Lua header found is not 5.1")
+    SET(LUA5.1_INCLUDE_DIR "LUA5.1_INCLUDE_DIR-NOTFOUND" CACHE PATH "" FORCE)
+  ENDIF(NOT _version_compare EQUAL 0)
+ENDIF(LUA5.1_INCLUDE_DIR)
+
+# Find library
+FIND_LIBRARY(LUA5.1_LIBRARY_OPTIMIZED
+  NAMES lua51 lua5.1 lua
+  PATHS $ENV{LUA5.1_DIR} $ENV{LUA_DIR}
+  PATH_SUFFIXES lib64 lib
+)
+FIND_LIBRARY(LUA5.1_LIBRARY_DEBUG
+  NAMES lua51d lua51_d lua5.1d lua5.1_d
+        lua51D lua51_D lua5.1D lua5.1_D
+        luad lua_d luad lua_D
+  PATHS $ENV{LUA5.1_DIR} $ENV{LUA_DIR}
+  PATH_SUFFIXES lib64 lib
+)
+
+# Handle the REQUIRED argument and set LUA5.1_FOUND
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua5.1 DEFAULT_MSG
+  LUA5.1_LIBRARY_OPTIMIZED
+  LUA5.1_INCLUDE_DIR
+)
+
+# Collect optimized and debug libraries
+HANDLE_LIBRARY_TYPES(LUA5.1)
+
+MARK_AS_ADVANCED(
+  LUA5.1_INCLUDE_DIR
+  LUA5.1_LIBRARY_OPTIMIZED
+  LUA5.1_LIBRARY_DEBUG
+)
Index: code/trunk/cmake/tools/FindOGRE.cmake
===================================================================
--- code/trunk/cmake/tools/FindOGRE.cmake	(revision 8264)
+++ code/trunk/cmake/tools/FindOGRE.cmake	(revision 8351)
@@ -23,5 +23,5 @@
 FIND_PATH(OGRE_INCLUDE_DIR Ogre.h
   PATHS $ENV{OGRE_HOME}
-  PATH_SUFFIXES include include/OGRE Ogre.framework/Headers
+  PATH_SUFFIXES include include/OGRE
 )
 FIND_LIBRARY(OGRE_LIBRARY_OPTIMIZED
@@ -33,5 +33,5 @@
   NAMES OgreMaind OgreMain_d OgreMainD OgreMain_D Ogred Ogre_d OgreD Ogre_d
   PATHS $ENV{OGRE_HOME}
-  PATH_SUFFIXES lib bin/Debug bin/debug Debug debug Versions/A
+  PATH_SUFFIXES lib bin/Debug bin/debug Debug debug
 )
 
Index: code/trunk/cmake/tools/FindOgg.cmake
===================================================================
--- code/trunk/cmake/tools/FindOgg.cmake	(revision 8264)
+++ code/trunk/cmake/tools/FindOgg.cmake	(revision 8351)
@@ -22,10 +22,10 @@
 )
 FIND_LIBRARY(OGG_LIBRARY_OPTIMIZED
-  NAMES ogg
+  NAMES ogg ogg-0 libogg
   PATHS $ENV{OGGDIR}
   PATH_SUFFIXES lib
 )
 FIND_LIBRARY(OGG_LIBRARY_DEBUG
-  NAMES oggd ogg_d oggD ogg_D
+  NAMES oggd ogg_d oggD ogg_D libogg_d
   PATHS $ENV{OGGDIR}
   PATH_SUFFIXES lib
Index: code/trunk/cmake/tools/FindPOCO.cmake
===================================================================
--- code/trunk/cmake/tools/FindPOCO.cmake	(revision 8264)
+++ code/trunk/cmake/tools/FindPOCO.cmake	(revision 8351)
@@ -29,5 +29,5 @@
 FIND_PATH(POCO_INCLUDE_DIR Poco/Poco.h
   PATHS $ENV{POCODIR}
-  PATH_SUFFIXES include
+  PATH_SUFFIXES include Foundation/include
 )
 FIND_LIBRARY(POCO_LIBRARY_OPTIMIZED
Index: code/trunk/cmake/tools/FindVorbis.cmake
===================================================================
--- code/trunk/cmake/tools/FindVorbis.cmake	(revision 8264)
+++ code/trunk/cmake/tools/FindVorbis.cmake	(revision 8351)
@@ -22,20 +22,20 @@
 )
 FIND_LIBRARY(VORBIS_LIBRARY_OPTIMIZED
-  NAMES vorbis
+  NAMES vorbis vorbis-0 libvorbis
   PATHS $ENV{VORBISDIR}
   PATH_SUFFIXES lib
 )
 FIND_LIBRARY(VORBIS_LIBRARY_DEBUG
-  NAMES vorbisd vorbis_d vorbisD vorbis_D
+  NAMES vorbisd vorbis_d vorbisD vorbis_D libvorbis_d
   PATHS $ENV{VORBISDIR}
   PATH_SUFFIXES lib
 )
 FIND_LIBRARY(VORBISFILE_LIBRARY_OPTIMIZED
-  NAMES vorbisfile
+  NAMES vorbisfile vorbisfile-3 libvorbisfile
   PATHS $ENV{VORBISDIR}
   PATH_SUFFIXES lib
 )
 FIND_LIBRARY(VORBISFILE_LIBRARY_DEBUG
-  NAMES vorbisfiled vorbisfile_d vorbisfileD vorbisfile_D
+  NAMES vorbisfiled vorbisfile_d vorbisfileD vorbisfile_D libvorbisfile_d
   PATHS $ENV{VORBISDIR}
   PATH_SUFFIXES lib
Index: code/trunk/cmake/tools/GenerateToluaBindings.cmake
===================================================================
--- code/trunk/cmake/tools/GenerateToluaBindings.cmake	(revision 8264)
+++ code/trunk/cmake/tools/GenerateToluaBindings.cmake	(revision 8351)
@@ -32,4 +32,14 @@
  #    RUNTIME_LIBRARY_DIRECTORY - Working directory
  #
+
+# Workaround for XCode: The folder where the bind files are written to has
+# to be present beforehand.
+# We have to do this here because the header files are all stored in a single
+# location per configuration.
+IF(CMAKE_CONFIGURATION_TYPES)
+  FOREACH(_dir ${CMAKE_CONFIGURATION_TYPES})
+    FILE(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/src/toluabind/${_dir}")
+  ENDFOREACH(_dir)
+ENDIF()
 
 FUNCTION(GENERATE_TOLUA_BINDINGS _tolua_package _target_source_files)
Index: code/trunk/cmake/tools/TargetUtilities.cmake
===================================================================
--- code/trunk/cmake/tools/TargetUtilities.cmake	(revision 8264)
+++ code/trunk/cmake/tools/TargetUtilities.cmake	(revision 8351)
@@ -43,4 +43,8 @@
  #    Lists:
  #      LINK_LIBRARIES:    Redirects to TARGET_LINK_LIBRARIES
+ #      LINK_LIBS_LINUX:   Redirects to TARGET_LINK_LIBRARIES only on Linux
+ #      LINK_LIBS_WIN32:   Redirects to TARGET_LINK_LIBRARIES only on Windows
+ #      LINK_LIBS_APPLE:   Redirects to TARGET_LINK_LIBRARIES only on Apple
+ #      LINK_LIBS_UNIX:    Redirects to TARGET_LINK_LIBRARIES only on UNIX
  #      VERSION:           Set version to the binary
  #      SOURCE_FILES:      Source files for the target
@@ -53,5 +57,5 @@
  #    This function also installs the target!
  #  Prerequisistes:
- #    ORXONOX_DEFAULT_LINK, ORXONOX_CONFIG_FILES
+ #    ORXONOX_DEFAULT_LINK
  #  Parameters:
  #    _target_name, ARGN for the macro arguments
@@ -86,5 +90,6 @@
   SET(_list_names LINK_LIBRARIES     VERSION           SOURCE_FILES
                   DEFINE_SYMBOL      TOLUA_FILES       PCH_FILE
-                  PCH_EXCLUDE        OUTPUT_NAME)
+                  PCH_EXCLUDE        OUTPUT_NAME       LINK_LIBS_LINUX
+                  LINK_LIBS_WIN32    LINK_LIBS_APPLE   LINK_LIBS_UNIX)
 
   PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
@@ -104,8 +109,8 @@
         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(NOT _compilation_include_string)
+          MESSAGE(STATUS "Warning: Empty source file compilation!")
+        ENDIF()
         IF(EXISTS ${_compilation_file})
           FILE(READ ${_compilation_file} _include_string_file)
@@ -169,4 +174,11 @@
     GENERATE_TOLUA_BINDINGS(${_target_name_capitalised} _${_target_name}_files
                             INPUTFILES ${_arg_TOLUA_FILES})
+    # Workaround for XCode: The folder where the bind files are written to has
+    # to be present beforehand.
+    IF(CMAKE_CONFIGURATION_TYPES)
+      FOREACH(_dir ${CMAKE_CONFIGURATION_TYPES})
+        FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_dir})
+      ENDFOREACH(_dir)
+    ENDIF()
   ENDIF()
 
@@ -192,11 +204,11 @@
 
     IF(NOT _arg_ORXONOX_EXTERNAL)
-      # Move the prereqs.h file to the config section
+      # Move the ...Prereqs.h and the PCH files 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 config files to the config section
-      LIST(APPEND _${_target_name}_files ${ORXONOX_CONFIG_FILES})
-      SOURCE_GROUP("Config" FILES ${ORXONOX_CONFIG_FILES})
+      IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_arg_PCH_FILE})
+        SOURCE_GROUP("Config" FILES ${CMAKE_CURRENT_SOURCE_DIR}/${_arg_PCH_FILE})
+      ENDIF()
     ENDIF()
   ENDIF()
@@ -217,10 +229,11 @@
   IF(_arg_ORXONOX_EXTERNAL)
     REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC)
-    ADD_COMPILER_FLAGS("-w")
+    ADD_COMPILER_FLAGS("-w" NOT MSVC)
+    ADD_COMPILER_FLAGS("-W0" MSVC)
   ENDIF()
 
   # Don't compile header files
   FOREACH(_file ${_${_target_name}_files})
-    IF(NOT _file MATCHES "\\.(c|cc|cpp|cxx)$")
+    IF(NOT _file MATCHES "\\.(c|cc|cpp|cxx|mm)$")
       SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
     ENDIF()
@@ -278,4 +291,28 @@
     TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBRARIES})
   ENDIF()
+  IF(_arg_LINK_LIBS_LINUX AND LINUX)
+    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_LINUX})
+  ENDIF()
+  IF(_arg_LINK_LIBS_WIN32 AND WIN32)
+    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_WIN32})
+  ENDIF()
+  IF(_arg_LINK_LIBS_APPLE AND APPLE)
+    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_APPLE})
+  ENDIF()
+  IF(_arg_LINK_LIBS_UNIX AND UNIX)
+    TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_UNIX})
+  ENDIF()
+
+  # RPATH settings for the installation
+  IF("${_target_type}" STREQUAL "LIBRARY")
+    IF(_arg_MODULE)
+      SET(_rpath "${MODULE_RPATH}")
+    ELSE()
+      SET(_rpath "${LIBRARY_RPATH}")
+    ENDIF()
+  ELSE()
+    SET(_rpath "${RUNTIME_RPATH}")
+  ENDIF()
+  SET_TARGET_PROPERTIES(${_target_name} PROPERTIES INSTALL_RPATH "${_rpath}")
 
   # DEFINE_SYMBOL
