Index: code/trunk/cmake/TargetUtilities.cmake
===================================================================
--- code/trunk/cmake/TargetUtilities.cmake	(revision 3371)
+++ code/trunk/cmake/TargetUtilities.cmake	(revision 5693)
@@ -24,4 +24,6 @@
  #    accepts a lot more input information. Simply supply the keywords
  #    described below in any order you wish.
+ #    The output is then stored in "_arg_ARGNAME" where ARGNAME is the the
+ #    name of the switch or list.
  #
  #    Switches: (when given --> TRUE, FALSE otherwise)
@@ -33,7 +35,10 @@
  #      NO_SOURCE_GROUPS:  Don't create msvc source groups
  #      STATIC/SHARED:     Inherited from ADD_LIBRARY
+ #      MODULE:            For dynamic module libraries
  #      WIN32:             Inherited from ADD_EXECUTABLE
  #      PCH_NO_DEFAULT:    Do not make precompiled header files default if
  #                         specified with PCH_FILE
+ #      NO_INSTALL:        Do not install the target at all
+ #
  #    Lists:
  #      LINK_LIBRARIES:    Redirects to TARGET_LINK_LIBRARIES
@@ -44,4 +49,5 @@
  #      PCH_FILE:          Precompiled header file
  #      PCH_EXCLUDE:       Source files to be excluded from PCH support
+ #      OUTPUT_NAME:       If you want a different name than the target name
  #  Note:
  #    This function also installs the target!
@@ -75,7 +81,7 @@
   SET(_switches   FIND_HEADER_FILES  EXCLUDE_FROM_ALL  ORXONOX_EXTERNAL
                   NO_DLL_INTERFACE   NO_SOURCE_GROUPS  ${_additional_switches}
-                  PCH_NO_DEFAULT NO_INSTALL)
+                  PCH_NO_DEFAULT     NO_INSTALL        MODULE)
   SET(_list_names LINK_LIBRARIES  VERSION   SOURCE_FILES  DEFINE_SYMBOL
-                  TOLUA_FILES     PCH_FILE  PCH_EXCLUDE)
+                  TOLUA_FILES     PCH_FILE  PCH_EXCLUDE OUTPUT_NAME)
   PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
 
@@ -142,4 +148,11 @@
   ENDIF()
 
+  # MODULE A
+  # Always create shared libraries
+  IF(_arg_MODULE)
+    SET(_arg_SHARED SHARED)
+    SET(_arg_STATIC)
+  ENDIF()
+
   # Add the library/executable
   IF("${_target_type}" STREQUAL "LIBRARY")
@@ -151,4 +164,13 @@
   ENDIF()
 
+  # MODULE B
+  IF (_arg_MODULE)
+    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES
+      RUNTIME_OUTPUT_DIRECTORY ${CMAKE_MODULE_OUTPUT_DIRECTORY} # Windows
+      LIBRARY_OUTPUT_DIRECTORY ${CMAKE_MODULE_OUTPUT_DIRECTORY} # Unix
+    )
+    ADD_MODULE(${_target_name})
+  ENDIF()
+
   # LINK_LIBRARIES
   IF(_arg_LINK_LIBRARIES)
@@ -168,4 +190,9 @@
   ENDIF()
 
+  # OUTPUT_NAME
+  IF(_arg_OUTPUT_NAME)
+    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES OUTPUT_NAME  ${_arg_OUTPUT_NAME})
+  ENDIF()
+
   # Second part of precompiled header files
   IF(PCH_COMPILER_SUPPORT AND PCH_ENABLE_${_target_name_upper} AND _arg_PCH_FILE)
@@ -174,10 +201,51 @@
 
   IF(NOT _arg_STATIC AND NOT _arg_NO_INSTALL)
-    INSTALL(TARGETS ${_target_name}
-      RUNTIME DESTINATION ${ORXONOX_RUNTIME_INSTALL_PATH}
-      LIBRARY DESTINATION ${ORXONOX_LIBRARY_INSTALL_PATH}
-      #ARCHIVE DESTINATION ${ORXONOX_ARCHIVE_INSTALL_PATH}
+    IF(_arg_MODULE)
+      INSTALL(TARGETS ${_target_name}
+        RUNTIME DESTINATION ${ORXONOX_MODULE_INSTALL_PATH}
+        LIBRARY DESTINATION ${ORXONOX_MODULE_INSTALL_PATH}
+      )
+    ELSE()
+      INSTALL(TARGETS ${_target_name}
+        RUNTIME DESTINATION ${ORXONOX_RUNTIME_INSTALL_PATH}
+        LIBRARY DESTINATION ${ORXONOX_LIBRARY_INSTALL_PATH}
+      )
+    ENDIF()
+  ENDIF()
+
+ENDFUNCTION(TU_ADD_TARGET)
+
+
+# Creates a helper file with name <name_of_the_library>.module
+# This helps finding dynamically loadable modules at runtime
+
+FUNCTION(ADD_MODULE _target)
+  # We use the properties to get the name because the librarys name may differ from
+  # the target name (for example orxonox <-> liborxonox)
+
+  GET_TARGET_PROPERTY(_target_loc ${_target} LOCATION)
+  GET_FILENAME_COMPONENT(_target_name ${_target_loc} NAME_WE)
+
+  IF(CMAKE_CONFIGURATION_TYPES)
+    FOREACH(_config ${CMAKE_CONFIGURATION_TYPES})
+      SET(_module_filename ${CMAKE_MODULE_OUTPUT_DIRECTORY}/${_config}/${_target_name}${ORXONOX_MODULE_EXTENSION})
+
+      FILE(WRITE ${_module_filename})
+
+      INSTALL(
+        FILES ${_module_filename}
+        DESTINATION ${ORXONOX_MODULE_INSTALL_PATH}
+        CONFIGURATIONS ${_config}
+      )
+    ENDFOREACH()
+  ELSE()
+    SET(_module_filename ${CMAKE_MODULE_OUTPUT_DIRECTORY}/${_target_name}${ORXONOX_MODULE_EXTENSION})
+
+    FILE(WRITE ${_module_filename})
+
+    INSTALL(
+      FILES ${_module_filename}
+      DESTINATION ${ORXONOX_MODULE_INSTALL_PATH}
     )
   ENDIF()
-
-ENDFUNCTION(TU_ADD_TARGET)
+ENDFUNCTION(ADD_MODULE)
