+###
+# Add Module Macro
+#
+# Optional Arg 1: Main Module Check, set to True/1 if adding a main module
+
+function ( AddModule ModuleType ModuleName )
+ # Module path
+ set ( ModulePath ${ModuleType}/${ModuleName} )
+ set ( ModuleFullPath ${HEAD_DIR}/${ModuleType}/${ModuleName} )
+
+ # Include setup.cmake file
+ include ( ${ModuleFullPath}/setup.cmake )
+
+ # Check if this is a main module add
+ foreach ( extraArg ${ARGN} )
+ # Make sure this isn't a submodule
+ if ( DEFINED SubModule )
+ message ( FATAL_ERROR
+ "The '${ModuleName}' module is not a stand-alone module, and requires further setup."
+ )
+ endif ()
+ endforeach ()
+
+ # PathPrepend to give proper paths to each of the source files
+ PathPrepend ( Module_SRCS ${ModulePath} ${Module_SRCS} )
+
+ # Check the current scope to see if a sub-module added some source files
+ # Append each of the sources to each type of module srcs list
+ set ( ${ModuleType}_SRCS ${${ModuleType}_SRCS} ${Module_SRCS} )
+
+ # Add .h files
+ add_definitions ( -I${ModuleFullPath} )
+
+ # Check module compatibility
+ ModuleCompatibility( ${ModulePath} ${ModuleCompatibility} )
+
+ # Check if this is a main module add
+ foreach ( extraArg ${ARGN} )
+ # Display detected source files
+ if ( NOT DEFINED SubModule )
+ message ( STATUS "Detected ${ModuleType} Module Source Files:" )
+ message ( "${${ModuleType}_SRCS}" )
+ endif ()
+ endforeach ()
+
+ # Check for any capabilities.kll files in the Module
+ set ( kll_capabilities_file "${ModuleFullPath}/capabilities.kll" )
+ if ( EXISTS ${kll_capabilities_file} )
+ # Add the kll file and any submodule kll files to the running list
+ set ( ${ModuleType}Module_KLL ${${ModuleType}Module_KLL} ${kll_capabilities_file} )
+ endif ()