From 2008ccc79e21962ffb5e327c2aba4ea7c8da76a1 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 2 Jul 2009 08:45:10 +0200 Subject: =?UTF-8?q?Module=20k=C3=B6nnen=20wieder=20statisch=20gelinkt=20we?= =?UTF-8?q?rden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/CMakeLists.txt | 47 ++++++++++++++++++++++++- src/modules/FileLogger/CMakeLists.txt | 2 +- src/modules/SystemBackendPosix/CMakeLists.txt | 2 +- src/modules/SystemBackendProc/CMakeLists.txt | 2 +- src/modules/UserBackendMysql/CMakeLists.txt | 4 +-- src/modules/modules.cpp.in | 50 +++++++++++++++++++++++++++ src/modules/modules.h | 39 +++++++++++++++++++++ 7 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 src/modules/modules.cpp.in create mode 100644 src/modules/modules.h (limited to 'src/modules') diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index ea05a95..4c86688 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -1,5 +1,35 @@ +include_directories(${INCLUDES}) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${MAD_BINARY_DIR}/src/modules) -set(CMAKE_SHARED_MODULE_PREFIX "") + +set(STATIC_MODULES "") + +macro(mad_module name) + string(TOUPPER ${name} upper_name) + + set(WITH_${upper_name} ON CACHE BOOL "Enable module '${name}'") + + mark_as_advanced(WITH_STATIC_${upper_name}) + set(WITH_STATIC_${upper_name} OFF CACHE BOOL "Link module '${name}' statically") + + if(WITH_${upper_name}) + if(WITH_STATIC_${upper_name}) + add_library(${name} STATIC ${ARGN}) + set(STATIC_MODULES ${STATIC_MODULES} ${name} PARENT_SCOPE) + else(WITH_STATIC_${upper_name}) + add_library(${name} MODULE ${ARGN}) + set_property(TARGET ${name} PROPERTY PREFIX "") + endif(WITH_STATIC_${upper_name}) + endif(WITH_${upper_name}) +endmacro(mad_module) + +macro(mad_module_libraries name) + string(TOUPPER ${name} upper_name) + + if(WITH_${upper_name}) + target_link_libraries(${name} ${ARGN}) + endif(WITH_${upper_name}) +endmacro(mad_module_libraries) add_subdirectory(FileLogger) add_subdirectory(SystemBackendPosix) @@ -8,3 +38,18 @@ add_subdirectory(SystemBackendProc) if(MYSQL_FOUND) add_subdirectory(UserBackendMysql) endif(MYSQL_FOUND) + +SET(STATIC_MODULE_LOADERS "") +SET(STATIC_MODULE_LIST "") + +foreach(module ${STATIC_MODULES}) + SET(STATIC_MODULE_LOADERS "${STATIC_MODULE_LOADERS}Mad::Common::Module* ${module}_create(Mad::Common::Application *application);\n") + SET(STATIC_MODULE_LIST "${STATIC_MODULE_LIST}std::make_pair(\"${module}\", &${module}_create),\n") +endforeach(module ${STATIC_MODULES}) + +configure_file(modules.cpp.in ${MAD_BINARY_DIR}/src/modules/modules.cpp) + +add_library(modules STATIC + modules.cpp modules.h +) +target_link_libraries(modules ${STATIC_MODULES}) diff --git a/src/modules/FileLogger/CMakeLists.txt b/src/modules/FileLogger/CMakeLists.txt index 555425d..2f654e8 100644 --- a/src/modules/FileLogger/CMakeLists.txt +++ b/src/modules/FileLogger/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories(${INCLUDES}) -add_library(FileLogger MODULE +mad_module(FileLogger FileLogger.h Module.cpp Module.h ) diff --git a/src/modules/SystemBackendPosix/CMakeLists.txt b/src/modules/SystemBackendPosix/CMakeLists.txt index 83e8ea1..0cd493d 100644 --- a/src/modules/SystemBackendPosix/CMakeLists.txt +++ b/src/modules/SystemBackendPosix/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories(${INCLUDES}) -add_library(SystemBackendPosix MODULE +mad_module(SystemBackendPosix Module.cpp Module.h SystemBackendPosix.cpp SystemBackendPosix.h ) diff --git a/src/modules/SystemBackendProc/CMakeLists.txt b/src/modules/SystemBackendProc/CMakeLists.txt index 42f7431..5341f89 100644 --- a/src/modules/SystemBackendProc/CMakeLists.txt +++ b/src/modules/SystemBackendProc/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories(${INCLUDES}) -add_library(SystemBackendProc MODULE +mad_module(SystemBackendProc Module.cpp Module.h SystemBackendProc.cpp SystemBackendProc.h ) diff --git a/src/modules/UserBackendMysql/CMakeLists.txt b/src/modules/UserBackendMysql/CMakeLists.txt index 5f32d9c..1c71816 100644 --- a/src/modules/UserBackendMysql/CMakeLists.txt +++ b/src/modules/UserBackendMysql/CMakeLists.txt @@ -1,8 +1,8 @@ include_directories(${INCLUDES} ${MYSQL_INCLUDE_DIR}) -add_library(UserBackendMysql MODULE +mad_module(UserBackendMysql Module.cpp Module.h UserBackendMysql.cpp UserBackendMysql.h ) -target_link_libraries(UserBackendMysql ${MYSQL_LIBRARIES}) \ No newline at end of file +mad_module_libraries(UserBackendMysql ${MYSQL_LIBRARIES}) \ No newline at end of file diff --git a/src/modules/modules.cpp.in b/src/modules/modules.cpp.in new file mode 100644 index 0000000..e3feba1 --- /dev/null +++ b/src/modules/modules.cpp.in @@ -0,0 +1,50 @@ +/* + * modules.cpp.in + * + * Copyright (C) 2009 Matthias Schiffer + * + * 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 3 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, see . + */ + +#include "modules.h" + +#include + +extern "C" { +@STATIC_MODULE_LOADERS@ +} + +namespace Mad { +namespace Modules { + +typedef Common::Module *(*ModuleLoadFunc)(Common::Application*); + +static const std::pair modules[] = { +@STATIC_MODULE_LIST@ +}; + +static const std::map moduleMap(modules, modules+sizeof(modules)); + +Common::Module* loadStaticModule(Common::Application *application, const std::string &name) { + std::map::const_iterator it = moduleMap.find(name); + + if(it == moduleMap.end()) + return 0; + + else + return it->second(application); +} + +} +} diff --git a/src/modules/modules.h b/src/modules/modules.h new file mode 100644 index 0000000..e992b2d --- /dev/null +++ b/src/modules/modules.h @@ -0,0 +1,39 @@ +/* + * modules.h + * + * Copyright (C) 2009 Matthias Schiffer + * + * 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 3 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, see . + */ + +#ifndef MAD_MODULES_H_ +#define MAD_MODULES_H_ + +#include + +namespace Mad { + +namespace Common { +class Application; +class Module; +} + +namespace Modules { + +Common::Module* loadStaticModule(Common::Application *application, const std::string &name); + +} +} + +#endif /* MAD_MODULES_H_ */ -- cgit v1.2.3