From 9ab7f1adfb63fee2fa8cafa6aa4f8896b45468b2 Mon Sep 17 00:00:00 2001
From: Isaak Lim <isaak.lim@rwth-aachen.de>
Date: Mon, 2 May 2016 14:06:25 +0200
Subject: [PATCH] Add ADD_CORE_APP_LIBRARIES option for openflipper_plugin,
 which allows the specification of additional libraries for each plugin to be
 linked into the core.

---
 OpenFlipper/CoreApp/CMakeLists.txt |  7 +++++
 OpenFlipper/cmake/plugin.cmake     | 41 ++++++++++++++++++++----------
 2 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/OpenFlipper/CoreApp/CMakeLists.txt b/OpenFlipper/CoreApp/CMakeLists.txt
index f98193534..28e33f5d6 100644
--- a/OpenFlipper/CoreApp/CMakeLists.txt
+++ b/OpenFlipper/CoreApp/CMakeLists.txt
@@ -162,12 +162,19 @@ endif ()
 # where we need to link the library directly into the core to prevent 
 # linker problems
 # ====================================================================================
+
 # Get the property containing the list of all dependencies of the plugins
 # List is created when the plugins are added
 get_property( global_dependency_list GLOBAL PROPERTY GLOBAL_PLUGIN_DEPENDENCIES_LIST)
 
 set(COREAPP_ADDITIONAL_LINK_LIBRARIES "")
 
+# Get additional libraries from plugins that should be linked into the core
+get_property( global_core_app_libraries GLOBAL PROPERTY GLOBAL_CORE_APP_LIBRARIES)
+foreach (_val ${global_core_app_libraries})
+  list(APPEND COREAPP_ADDITIONAL_LINK_LIBRARIES ${_val})
+endforeach ()
+
 # Special Handling for mpi
 list( FIND global_dependency_list "MPI" found)
 if ( NOT found EQUAL -1 )
diff --git a/OpenFlipper/cmake/plugin.cmake b/OpenFlipper/cmake/plugin.cmake
index 78b946d32..9fe8513c0 100644
--- a/OpenFlipper/cmake/plugin.cmake
+++ b/OpenFlipper/cmake/plugin.cmake
@@ -7,6 +7,7 @@
 #                      [CFLAGSADD flag1 flag2 ...]
 #                      [CDEFINITIONSADD definition1 definition2 ...]
 #                      [LIBRARIES lib1 lib2 ...]
+#                      [ADD_CORE_APP_LIBRARIES lib1 lib2 ...]
 #                      [LIBDIRS dir1 dir2 ...]
 #                      [INCDIRS dir1 dir2 ...]
 #                      [ADDSRC file1 file2 ...]
@@ -15,17 +16,18 @@
 #                      [TRANSLATION_ADDFILES file1 file2 ...]
 #                      [LICENSEMANAGER])
 #
-# DIRS            = additional directories with source files
-# DEPS            = required dependencies for find_package macro
-# OPTDEPS         = optional dependencies for find_package macro, if found, a define ENABLE_<Depname> will be added automatically
-# LDFLAGSADD      = flags added to the link command
-# CFLAGSADD       = flags added to the compile command
-# CDEFINITIONSADD = definitions added to the compile command
-# LIBRARIES       = libraries added to link command
-# LIBDIRS         = additional link directories
-# INCDIRS         = additional include directories
-# ADDSRC          = additional source files
-# INSTALLDATA     = directories that will be installed into the openflipper data directory
+# DIRS                   = additional directories with source files
+# DEPS                   = required dependencies for find_package macro
+# OPTDEPS                = optional dependencies for find_package macro, if found, a define ENABLE_<Depname> will be added automatically
+# LDFLAGSADD             = flags added to the link command
+# CFLAGSADD              = flags added to the compile command
+# CDEFINITIONSADD        = definitions added to the compile command
+# LIBRARIES              = libraries added to link command
+# ADD_CORE_APP_LIBRARIES = libraries added to be linked to the core app
+# LIBDIRS                = additional link directories
+# INCDIRS                = additional include directories
+# ADDSRC                 = additional source files
+# INSTALLDATA            = directories that will be installed into the openflipper data directory
 #
 # TRANSLATION_LANGUAGES = language codes for translation
 # TRANSLATION_ADDFILES  = additional files that should be included into the translation files
@@ -67,7 +69,8 @@ endmacro ()
 # parse plugin macro parameter
 macro (_get_plugin_parameters _prefix)
     set (_current_var _foo)
-    set (_supported_var DIRS DEPS OPTDEPS LDFLAGSADD CFLAGSADD CDEFINITIONSADD LIBRARIES LIBDIRS INCDIRS ADDSRC INSTALLDATA TRANSLATION_LANGUAGES TRANSLATION_ADDFILES)
+    set (_supported_var DIRS DEPS OPTDEPS LDFLAGSADD CFLAGSADD CDEFINITIONSADD
+      LIBRARIES ADD_CORE_APP_LIBRARIES LIBDIRS INCDIRS ADDSRC INSTALLDATA TRANSLATION_LANGUAGES TRANSLATION_ADDFILES)
     set (_supported_flags LICENSEMANAGER)
     foreach (_val ${_supported_var})
         set (${_prefix}_${_val})
@@ -104,6 +107,7 @@ endmacro ()
 # _optional : if we are currently pars
 macro (_check_plugin_deps _prefix _optional )
 
+
     set (${_prefix}_HAS_DEPS TRUE)
 
     # This will contain the final list of all dependencies
@@ -400,7 +404,18 @@ function (_build_openflipper_plugin plugin)
   acg_unset (_${_PLUGIN}_MISSING_DEPS)
   set (${_PLUGIN}_HAS_DEPS)
   _check_plugin_deps (${_PLUGIN} FALSE ${${_PLUGIN}_DEPS})
-  
+
+  #============================================================================================
+  # Additional libraries to be linked to the core app
+  #============================================================================================
+
+  get_property( global_core_app_libraries GLOBAL PROPERTY GLOBAL_CORE_APP_LIBRARIES)
+  foreach (_val ${${_PLUGIN}_ADD_CORE_APP_LIBRARIES})
+    list(APPEND global_core_app_libraries ${_val})
+    list(REMOVE_DUPLICATES global_core_app_libraries)
+  endforeach ()
+  set_property( GLOBAL PROPERTY GLOBAL_CORE_APP_LIBRARIES ${global_core_app_libraries} )
+
 
   #============================================================================================
   # Remember Lib dirs for bundle generation
-- 
GitLab