LayerManagerPlugins: introduced WITH_STATIC_PLUGINS to statically link plugins
authorTimo Lotterbach <timo.lotterbach@bmw-carit.de>
Wed, 28 Nov 2012 10:08:04 +0000 (02:08 -0800)
committerTimo Lotterbach <timo.lotterbach@bmw-carit.de>
Mon, 14 Jan 2013 08:34:16 +0000 (00:34 -0800)
the build system was enhanced to create a list of
statically linked plungins. All plugins in this list are statically linked
against LayerManagerService.

To enable this option, the build flag WITH_STATIC_PLUGINS was added.

Plugins supporting this features must add themselves to the list of
statically linked plugins based on the setting of WITH_STATIC_PLUGINS.

additionally the macro DECLARE_LAYERMANAGEMENT_PLUGIN was added to
simplify the definition of a plugin entry point for loading.

Signed-off-by: Timo Lotterbach <timo.lotterbach@bmw-carit.de>
CMakeLists.txt
LayerManagerService/CMakeLists.txt
config/CMakeLists.txt
config/res/config.h.cmake

index 90eaa83..839f846 100644 (file)
@@ -58,11 +58,13 @@ option (WITH_SERVICE_BIN    "Build LayerManagerService Binary"
 option (WITH_CLIENT_LIB     "Build LayerManagement Client Lib"                    ON)
 option (WITH_COMMUNICATOR_GEN "Build Generic Communicator Plugin"                 ON)
 
-option (WITH_PLUGIN_SYSTEMD_HEALTH_MONITOR "Build plugin for systemd health monitoring" OFF)
+option (WITH_SYSTEMD_HEALTH_MONITOR "Build plugin for systemd health monitoring" OFF)
 
 option (WITH_TEXT_RENDERER  "Build renderer renderer (only logging)"              OFF)
 
-option (WITH_PLUGIN_EXAMPLE_SCENE_PROVIDER "Build scene provider plugin for example applciations" OFF)
+option (WITH_EXAMPLE_SCENE_PROVIDER "Build scene provider plugin for example applciations" OFF)
+
+option (WITH_STATIC_PLUGINS "Link all plugins statically"                         OFF)
 
 
 #==============================================================================
@@ -71,6 +73,7 @@ option (WITH_PLUGIN_EXAMPLE_SCENE_PROVIDER "Build scene provider plugin for exam
 set (WITH_WAYLAND    OFF)
 set (BUILD_UTILS_LIB  OFF)
 set (INSTALL_UTILS_LIB  OFF)
+set (STATICALLY_LINKED_PLUGINS "" CACHE INTERNAL "list of static plugins" FORCE)
 
 
 #==============================================================================
@@ -105,7 +108,6 @@ endif(NumberOfWaylandRenderers GREATER 1)
 # set default build parameters
 #==============================================================================
 add_subdirectory(cmake/optionalFeatures)
-add_subdirectory(config)
 
 include_directories ("${PROJECT_SOURCE_DIR}/config")
 include_directories ("${PROJECT_SOURCE_DIR}/3rdParty/")
@@ -160,13 +162,13 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
 #set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
 #==============================================================================
 
-if (WITH_PLUGIN_EXAMPLE_SCENE_PROVIDER)
+if (WITH_EXAMPLE_SCENE_PROVIDER)
     add_subdirectory (LayerManagerPlugins/SceneProvider/ExampleSceneProvider)
-endif(WITH_PLUGIN_EXAMPLE_SCENE_PROVIDER)
+endif(WITH_EXAMPLE_SCENE_PROVIDER)
 
-if (WITH_PLUGIN_SYSTEMD_HEALTH_MONITOR)
+if (WITH_SYSTEMD_HEALTH_MONITOR)
     add_subdirectory (LayerManagerPlugins/HealthMonitor/SystemdHealthMonitor)
-endif(WITH_PLUGIN_SYSTEMD_HEALTH_MONITOR)
+endif(WITH_SYSTEMD_HEALTH_MONITOR)
 
 if (WITH_COMMUNICATOR_GEN)
     add_subdirectory (LayerManagerCommands)
@@ -226,3 +228,8 @@ endif (BUILD_UTILS_LIB)
 if (WITH_TESTS)
     enable_testing()
 endif(WITH_TESTS)
+
+#==============================================================================
+# store used build configuration
+#==============================================================================
+add_subdirectory(config)
index 83e325d..2207e59 100644 (file)
@@ -41,11 +41,13 @@ add_dependencies(LayerManagerService LayerManagerCommands)
 
 find_package (Threads)
 set(LIBS ${LIBS}
-         LayerManagerUtils 
-         LayerManagerCommands
-         dl
-         ${CMAKE_THREAD_LIBS_INIT}
-         ${DLT_LIBRARY}) 
+    LayerManagerUtils 
+    LayerManagerCommands
+    dl
+    ${CMAKE_THREAD_LIBS_INIT}
+    ${DLT_LIBRARY}
+    ${STATICALLY_LINKED_PLUGINS}
+) 
 
 target_link_libraries(LayerManagerService ${LIBS})
 
index 06a9f51..f35ad2b 100644 (file)
@@ -24,6 +24,10 @@ cmake_minimum_required (VERSION 2.6)
 
 message(STATUS "Generating config.h header file with build system configuration.")
 
+foreach(PLUGIN ${STATICALLY_LINKED_PLUGINS})
+    SET(STATIC_PLUGIN_REGISTRATION "${STATIC_PLUGIN_REGISTRATION} \\\n        REGISTER_PLUGIN(${PLUGIN})")
+endforeach(PLUGIN ${STATICALLY_LINKED_PLUGINS})
+
 configure_file(
     ${CMAKE_SOURCE_DIR}/config/res/config.h.cmake
     ${CMAKE_SOURCE_DIR}/config/config.h
index 0b73804..f0fa1a3 100644 (file)
@@ -142,9 +142,30 @@ const BuildFlag gBuildFlags[] =
     { DEBUG_FLAG, "WITH_WAYLAND_X11      = ${WITH_WAYLAND_X11}" },
     { DEBUG_FLAG, "WITH_WL_EXAMPLE       = ${WITH_WL_EXAMPLE}" },
     { DEBUG_FLAG, "WITH_X11_GLES         = ${WITH_X11_GLES}" },
-    { DEBUG_FLAG, "WITH_PLUGIN_SYSTEMD.. = ${WITH_PLUGIN_SYSTEMD_HEALTH_MONITOR}" }
+    { DEBUG_FLAG, "WITH_SYSTEMD_HEALTH_MONITOR = ${WITH_SYSTEMD_HEALTH_MONITOR}" },
+    { DEBUG_FLAG, "WITH_EXAMPLE_SCENE_PROVIDER = ${WITH_EXAMPLE_SCENE_PROVIDER}" },
+    { DEBUG_FLAG, "WITH_STATIC_PLUGINS   = ${WITH_STATIC_PLUGINS}" }
 };
 
 const int gBuildFlagCount = sizeof(gBuildFlags) / sizeof(gBuildFlags[0]);
 
+
+//-----------------------------------------------------------------------------
+// manage list of statically linked plugins
+//-----------------------------------------------------------------------------
+#define REGISTER_PLUGIN(PLUGIN) \
+    extern "C" IPlugin* create ## PLUGIN(ICommandExecutor& executor, Configuration& config); \
+    static bool PLUGIN ## _instance = PluginManager::registerStaticPluginCreateFunction(create ## PLUGIN);
+
+#define STATIC_PLUGIN_REGISTRATION ${STATIC_PLUGIN_REGISTRATION}
+
+//-----------------------------------------------------------------------------
+// define plugin entry point depending on build settings
+//-----------------------------------------------------------------------------
+#define DECLARE_LAYERMANAGEMENT_PLUGIN(name) \
+extern "C" IPlugin* create ## name(ICommandExecutor& executor, Configuration& config) \
+{ \
+    return new name(executor, config); \
+}
+
 #endif // __CONFIG_H__