Index: code/branches/buildsystem/CMakeLists.txt
===================================================================
--- code/branches/buildsystem/CMakeLists.txt	(revision 1875)
+++ code/branches/buildsystem/CMakeLists.txt	(revision 1882)
@@ -44,6 +44,6 @@
 
 # Set binary output directories
-SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
-SET(LIBRARY_OUTPUT_PATH    ${PROJECT_SOURCE_DIR}/bin/lib)
+SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
+SET(LIBRARY_OUTPUT_PATH    ${PROJECT_BINARY_DIR}/bin/lib)
 
 # Global compiler/linker flags. force -O2!
Index: code/branches/buildsystem/cmake/UseTolua.cmake
===================================================================
--- code/branches/buildsystem/cmake/UseTolua.cmake	(revision 1882)
+++ code/branches/buildsystem/cmake/UseTolua.cmake	(revision 1882)
@@ -0,0 +1,46 @@
+#    UseTolua.cmake - CMake Module to generate LUA Bindings with tolua
+#    Copyright (C) 2008  Adrian Friedli
+#
+#    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
+
+SET(_tolua_executable_name tolua_orxonox)
+GET_TARGET_PROPERTY(TOLUA_EXECUTABLE "${_tolua_executable_name}" LOCATION)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -iquote ${CMAKE_CURRENT_SOURCE_DIR} -iquote ${CMAKE_CURRENT_BINARY_DIR}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -iquote ${CMAKE_CURRENT_SOURCE_DIR} -iquote ${CMAKE_CURRENT_BINARY_DIR}")
+
+MACRO(TOLUA _tolua_package _tolua_srcfiles_varname)
+  # TODO: cleaner arguments handling
+  SET(_tolua_inputfiles ${ARGN})
+  LIST(REMOVE_ITEM _tolua_inputfiles "INPUTFILES")
+
+  SET(_tolua_pkgfile "${CMAKE_CURRENT_BINARY_DIR}/tolua.pkg")
+  SET(_tolua_cxxfile "${CMAKE_CURRENT_BINARY_DIR}/tolua_bind.cc")
+  SET(_tolua_hfile "${CMAKE_CURRENT_BINARY_DIR}/tolua_bind.h")
+  SET(${_tolua_srcfiles_varname} ${${_tolua_srcfiles_varname}} "${_tolua_cxxfile}")
+
+  # TODO: check secureness of this temporary file
+  FILE(REMOVE "${_tolua_pkgfile}")
+  FOREACH(_tolua_inputfile ${_tolua_inputfiles})
+    FILE(APPEND "${_tolua_pkgfile}" "\$cfile \"${_tolua_inputfile}\"\n")
+  ENDFOREACH(_tolua_inputfile)
+
+  ADD_CUSTOM_COMMAND(
+    OUTPUT "${_tolua_cxxfile}" "${_tolua_hfile}"
+    COMMAND "${TOLUA_EXECUTABLE}" -n "${_tolua_package}" -o "${_tolua_cxxfile}" -H "${_tolua_hfile}" "${_tolua_pkgfile}"
+    DEPENDS "${_tolua_executable_name}" "${_tolua_inputfiles}"
+    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+  )
+ENDMACRO(TOLUA)
Index: code/branches/buildsystem/src/CMakeLists.txt
===================================================================
--- code/branches/buildsystem/src/CMakeLists.txt	(revision 1875)
+++ code/branches/buildsystem/src/CMakeLists.txt	(revision 1882)
@@ -2,4 +2,5 @@
 INCLUDE_DIRECTORIES(..)
 INCLUDE_DIRECTORIES(orxonox)
+INCLUDE_DIRECTORIES(lua)
 
 ADD_SUBDIRECTORY(cpptcl)
Index: code/branches/buildsystem/src/core/CMakeLists.txt
===================================================================
--- code/branches/buildsystem/src/core/CMakeLists.txt	(revision 1875)
+++ code/branches/buildsystem/src/core/CMakeLists.txt	(revision 1882)
@@ -50,19 +50,8 @@
   input/KeyDetector.cc
   input/SimpleInputState.cc
-
-  tolua/tolua_bind.cc
 )
 
-GET_TARGET_PROPERTY(TOLUA_EXE tolua_orxonox LOCATION)
-ADD_CUSTOM_COMMAND(
-  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.cc ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.h
-  COMMAND ${TOLUA_EXE} -n Core -o ../../src/core/tolua/tolua_bind.cc -H ../../src/core/tolua/tolua_bind.h ../../src/core/tolua/tolua.pkg
-  DEPENDS
-    tolua_orxonox
-    tolua/tolua.pkg
-    Script.h
-    CommandExecutor.h
-  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib
-)
+INCLUDE(UseTolua)
+TOLUA(Core CORE_SRC_FILES INPUTFILES Script.h CommandExecutor.h)
 
 ADD_LIBRARY(core SHARED ${CORE_SRC_FILES})
Index: code/branches/buildsystem/src/core/Script.cc
===================================================================
--- code/branches/buildsystem/src/core/Script.cc	(revision 1875)
+++ code/branches/buildsystem/src/core/Script.cc	(revision 1882)
@@ -36,6 +36,6 @@
 #include "lua/lua.hpp"
 
-#include "tolua/tolua++.h"
-#include "tolua/tolua_bind.h"
+#include "tolua++.h"
+#include "tolua_bind.h"
 
 namespace orxonox
Index: code/branches/buildsystem/src/core/tolua/tolua.pkg
===================================================================
--- code/branches/buildsystem/src/core/tolua/tolua.pkg	(revision 1875)
+++ 	(revision )
@@ -1,2 +1,0 @@
-$cfile "../../src/core/Script.h"
-$cfile "../../src/core/CommandExecutor.h"
Index: code/branches/buildsystem/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/buildsystem/src/orxonox/CMakeLists.txt	(revision 1875)
+++ code/branches/buildsystem/src/orxonox/CMakeLists.txt	(revision 1882)
@@ -62,19 +62,15 @@
   objects/RotatingProjectile.cc
   objects/ParticleProjectile.cc
-
-  tolua/tolua_bind.cc
 )
 
-GET_TARGET_PROPERTY(TOLUA_EXE tolua_orxonox LOCATION)
-ADD_CUSTOM_COMMAND(
-  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.cc ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.h
-  COMMAND ${TOLUA_EXE} -n Orxonox -o ../../src/orxonox/tolua/tolua_bind.cc -H ../../src/orxonox/tolua/tolua_bind.h ../../src/orxonox/tolua/tolua.pkg
-  DEPENDS
-    tolua_orxonox
-    tolua/tolua.pkg
-    gui/GUIManager.h
-  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib
-)
-	
+INCLUDE(UseTolua)
+TOLUA(Orxonox ORXONOX_SRC_FILES INPUTFILES gui/GUIManager.h)
+
+SET(CORE_SUBDIR src/core)
+SET(CORE_SOURCE_DIR "${CMAKE_SOURCE_DIR}/${CORE_SUBDIR}")
+SET(CORE_BINARY_DIR "${CMAKE_BINARY_DIR}/${CORE_SUBDIR}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -iquote ${CORE_SOURCE_DIR} -iquote ${CORE_BINARY_DIR}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -iquote ${CORE_SOURCE_DIR} -iquote ${CORE_BINARY_DIR}")
+
 ADD_EXECUTABLE( orxonox ${ORXONOX_SRC_FILES} )
 
@@ -110,3 +106,2 @@
   network
 )
-
Index: code/branches/buildsystem/src/orxonox/gui/GUIManager.cc
===================================================================
--- code/branches/buildsystem/src/orxonox/gui/GUIManager.cc	(revision 1875)
+++ code/branches/buildsystem/src/orxonox/gui/GUIManager.cc	(revision 1882)
@@ -43,8 +43,8 @@
 #include "core/input/InputManager.h"
 #include "core/input/SimpleInputState.h"
-#include "core/tolua/tolua_bind.h"
+#include "../core/tolua_bind.h"
 #include "core/ConsoleCommand.h"
 #include "core/Core.h"
-#include "tolua/tolua_bind.h"
+#include "tolua_bind.h"
 #include "GraphicsEngine.h"
 #include "OgreCEGUIRenderer.h"
Index: code/branches/buildsystem/src/orxonox/tolua/tolua.pkg
===================================================================
--- code/branches/buildsystem/src/orxonox/tolua/tolua.pkg	(revision 1875)
+++ 	(revision )
@@ -1,1 +1,0 @@
-$cfile "../../src/orxonox/gui/GUIManager.h"
Index: code/branches/buildsystem/src/tolua/CMakeLists.txt
===================================================================
--- code/branches/buildsystem/src/tolua/CMakeLists.txt	(revision 1875)
+++ code/branches/buildsystem/src/tolua/CMakeLists.txt	(revision 1882)
@@ -28,9 +28,9 @@
 
 
-SET (TOLUA_PACKAGE "../../src/tolua/tolua-5.1.pkg")
+SET (TOLUA_PACKAGE "${CMAKE_CURRENT_SOURCE_DIR}/tolua-5.1.pkg")
 GET_TARGET_PROPERTY(TOLUAGEN_EXE toluagen_orxonox LOCATION)
 ADD_CUSTOM_COMMAND(
-  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/toluabind_orxonox.c
-  COMMAND ${TOLUAGEN_EXE} -n tolua -o ../../src/tolua/toluabind_orxonox.c -H ../../src/tolua/toluabind_orxonox.h ${TOLUA_PACKAGE}
+  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/toluabind_orxonox.c
+  COMMAND ${TOLUAGEN_EXE} -n tolua -o ${CMAKE_CURRENT_BINARY_DIR}/toluabind_orxonox.c -H ${CMAKE_CURRENT_BINARY_DIR}/toluabind_orxonox.h ${TOLUA_PACKAGE}
   DEPENDS
     toluagen_orxonox
@@ -57,5 +57,5 @@
     lua/clean.lua
     lua/doit.lua
-  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
 )
 
Index: code/branches/buildsystem/src/tolua/lua/package.lua
===================================================================
--- code/branches/buildsystem/src/tolua/lua/package.lua	(revision 1875)
+++ code/branches/buildsystem/src/tolua/lua/package.lua	(revision 1882)
@@ -213,5 +213,5 @@
 
  if not flags.h then
-  output('#include "../'..self.name..'Prereqs.h"\n')
+  output('#include "'..self.name..'Prereqs.h"\n')
   output('/* Exported function */')
   output('_'..self.name..'Export int  tolua_'..self.name..'_open (lua_State* tolua_S);')
Index: code/branches/buildsystem/src/tolua/tolua-5.1.pkg
===================================================================
--- code/branches/buildsystem/src/tolua/tolua-5.1.pkg	(revision 1875)
+++ code/branches/buildsystem/src/tolua/tolua-5.1.pkg	(revision 1882)
@@ -1,23 +1,23 @@
-$lfile "../../src/tolua/lua/compat-5.1.lua"
-$lfile "../../src/tolua/lua/compat.lua"
-$lfile "../../src/tolua/lua/basic.lua"
-$lfile "../../src/tolua/lua/feature.lua"
-$lfile "../../src/tolua/lua/verbatim.lua"
-$lfile "../../src/tolua/lua/code.lua"
-$lfile "../../src/tolua/lua/typedef.lua"
-$lfile "../../src/tolua/lua/container.lua"
-$lfile "../../src/tolua/lua/package.lua"
-$lfile "../../src/tolua/lua/module.lua"
-$lfile "../../src/tolua/lua/namespace.lua"
-$lfile "../../src/tolua/lua/define.lua"
-$lfile "../../src/tolua/lua/enumerate.lua"
-$lfile "../../src/tolua/lua/declaration.lua"
-$lfile "../../src/tolua/lua/variable.lua"
-$lfile "../../src/tolua/lua/array.lua"
-$lfile "../../src/tolua/lua/function.lua"
-$lfile "../../src/tolua/lua/operator.lua"
-$lfile "../../src/tolua/lua/class.lua"
-$lfile "../../src/tolua/lua/clean.lua"
-$lfile "../../src/tolua/lua/doit.lua"
+$lfile "lua/compat-5.1.lua"
+$lfile "lua/compat.lua"
+$lfile "lua/basic.lua"
+$lfile "lua/feature.lua"
+$lfile "lua/verbatim.lua"
+$lfile "lua/code.lua"
+$lfile "lua/typedef.lua"
+$lfile "lua/container.lua"
+$lfile "lua/package.lua"
+$lfile "lua/module.lua"
+$lfile "lua/namespace.lua"
+$lfile "lua/define.lua"
+$lfile "lua/enumerate.lua"
+$lfile "lua/declaration.lua"
+$lfile "lua/variable.lua"
+$lfile "lua/array.lua"
+$lfile "lua/function.lua"
+$lfile "lua/operator.lua"
+$lfile "lua/class.lua"
+$lfile "lua/clean.lua"
+$lfile "lua/doit.lua"
 
 $[
