Index: code/branches/kicklib/cmake/LibraryConfig.cmake
===================================================================
--- code/branches/kicklib/cmake/LibraryConfig.cmake	(revision 7940)
+++ code/branches/kicklib/cmake/LibraryConfig.cmake	(revision 7941)
@@ -109,31 +109,18 @@
 ##### CEGUI #####
 # We make use of the CEGUI script module called CEGUILua.
-# However there is a small issue with that: We use Tolua, a C++ binding
-# generator ourselves. And we also have to use our bindings in the same
-# lua state is CEGUILua's. Unfortunately this implies that both lua runtime
-# version are equal or else you get segmentation faults.
-# In order to match the Lua versions we decided to ship CEGUILua in our
-# repository, mainly because there is no way to determine which version of
-# Lua CEGUILua was linked against (you'd have to specify yourself) and secondly
-# because we can then choose the Lua version. Future plans might involve only
-# accepting Lua 5.1.
-
-# Insert all internally supported CEGUILua versions here
-SET(CEGUILUA_INTERNAL_SUPPORT 0.5.0 0.6.0 0.6.1 0.6.2)
-OPTION(CEGUILUA_USE_EXTERNAL_LIBRARY "Force the use of external CEGUILua library" OFF)
+# However there is a small issue with that: Both CEGUILua and Orxonox use
+# Lua library functions on the same objects. And it turns out that in this case
+# the linked library must be EXACTLY the same.
+# That means for us we have to find the Lua library that CEGUI was
+# linked against if we don't use a dependency package.
+
 FIND_PACKAGE(CEGUI 0.5 REQUIRED)
 
 ##### Lua #####
-IF(CEGUILUA_USE_EXTERNAL_LIBRARY)
-  COMPARE_VERSION_STRINGS(${CEGUI_VERSION} "0.6" _version_comparison)
-  IF(version_comparison LESS 0)
-    SET(LUA_VERSION_REQUEST 5.0)
-  ELSE()
-    SET(LUA_VERSION_REQUEST 5.1)
-  ENDIF()
+IF(NOT LUA_VERSION_REQUIREMENT)
+  FIND_PACKAGE(Lua 5 REQUIRED)
 ELSE()
-  SET(LUA_VERSION_REQUEST 5)
-ENDIF()
-FIND_PACKAGE(Lua ${LUA_VERSION_REQUEST} EXACT REQUIRED)
+  FIND_PACKAGE(Lua ${LUA_VERSION_REQUIREMENT} EXACT REQUIRED)
+ENDIF()
 
 ##### OpenAL #####
Index: code/branches/kicklib/cmake/tools/FindCEGUI.cmake
===================================================================
--- code/branches/kicklib/cmake/tools/FindCEGUI.cmake	(revision 7940)
+++ code/branches/kicklib/cmake/tools/FindCEGUI.cmake	(revision 7941)
@@ -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
@@ -33,4 +30,5 @@
 INCLUDE(HandleLibraryTypes)
 
+# Find CEGUI library
 FIND_PATH(CEGUI_INCLUDE_DIR CEGUI.h
   PATHS $ENV{CEGUIDIR}
@@ -50,4 +48,28 @@
 )
 
+# Find CEGUILua libraries
+FIND_LIBRARY(CEGUILUA_LIBRARY_OPTIMIZED
+  NAMES CEGUILua CEGUILuaScriptModule
+  PATHS $ENV{CEGUIDIR}
+  PATH_SUFFIXES lib bin
+)
+FIND_LIBRARY(CEGUILUA_LIBRARY_DEBUG
+  NAMES CEGUILuad CEGUILua_d CEGUILuaScriptModuled CEGUILuaScriptModule_d
+  PATHS $ENV{CEGUIDIR}
+  PATH_SUFFIXES lib bin
+)
+
+# Find CEGUI Tolua++ libraries
+FIND_LIBRARY(CEGUI_TOLUA_LIBRARY_OPTIMIZED
+  NAMES CEGUItoluapp tolua++
+  PATHS $ENV{CEGUIDIR}
+  PATH_SUFFIXES lib bin
+)
+FIND_LIBRARY(CEGUI_TOLUA_LIBRARY_DEBUG
+  NAMES CEGUItoluappd CEGUItoluapp_d tolua++d tolua++_d
+  PATHS $ENV{CEGUIDIR}
+  PATH_SUFFIXES lib bin
+)
+
 # Inspect CEGUIVersion.h for the version number
 DETERMINE_VERSION(CEGUI ${CEGUI_INCLUDE_DIR}/CEGUIVersion.h)
@@ -56,10 +78,14 @@
 # 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_LIBRARY_OPTIMIZED
+  CEGUI_TOLUA_LIBRARY_OPTIMIZED
 )
 
 # Collect optimized and debug libraries
 HANDLE_LIBRARY_TYPES(CEGUI)
+HANDLE_LIBRARY_TYPES(CEGUILUA)
+HANDLE_LIBRARY_TYPES(CEGUI_TOLUA)
 
 MARK_AS_ADVANCED(
@@ -67,37 +93,7 @@
   CEGUI_LIBRARY_OPTIMIZED
   CEGUI_LIBRARY_DEBUG
+  CEGUILUA_LIBRARY_OPTIMIZED
+  CEGUILUA_LIBRARY_DEBUG
+  CEGUI_TOLUA_LIBRARY_OPTIMIZED
+  CEGUI_TOLUA_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)
-
