[Orxonox-commit 7075] r11692 - in code/trunk: cmake/tools src/libraries/core src/libraries/core/module
landauf at orxonox.net
landauf at orxonox.net
Wed Jan 3 01:43:20 CET 2018
Author: landauf
Date: 2018-01-03 01:43:20 +0100 (Wed, 03 Jan 2018)
New Revision: 11692
Modified:
code/trunk/cmake/tools/TargetUtilities.cmake
code/trunk/src/libraries/core/ApplicationPaths.cc
code/trunk/src/libraries/core/ApplicationPaths.h
code/trunk/src/libraries/core/Core.cc
code/trunk/src/libraries/core/module/PluginManager.cc
Log:
with the latest CMake there are a lot of warnings about the usage of CMP0026. therefore the naming and content of the module/plugin-files had to be changed:
old: <library-filename>.module with content <target-name>
new: <target-name>.module with content <library-filename>
this seems to comply better with cmake and works equally well in c++ (with some small adjustments).
reference: https://cmake.org/cmake/help/v3.0/policy/CMP0026.html
Modified: code/trunk/cmake/tools/TargetUtilities.cmake
===================================================================
--- code/trunk/cmake/tools/TargetUtilities.cmake 2018-01-03 00:05:21 UTC (rev 11691)
+++ code/trunk/cmake/tools/TargetUtilities.cmake 2018-01-03 00:43:20 UTC (rev 11692)
@@ -468,27 +468,16 @@
ENDMACRO(TU_ADD_TARGET)
-# Creates a helper file with name <name_of_the_library>.<extension>
+# Creates a helper file with name <target_name>.<extension> and content <filename_of_the_library>
# This helps finding dynamically loadable modules or plugins at runtime
FUNCTION(ADD_MODULE_OR_PLUGIN _target_name _output_dir _install_dir _extension)
- # We use the properties to get the name because the librarys name may differ from
- # the target name (for example orxonox <-> liborxonox)
- IF (POLICY CMP0026)
- CMAKE_POLICY(PUSH)
- CMAKE_POLICY(SET CMP0026 OLD) # we only use the file's name, not its actual location, so the old policy is fine
- ENDIF()
- GET_TARGET_PROPERTY(_target_loc ${_target_name} LOCATION)
- GET_FILENAME_COMPONENT(_target_filename ${_target_loc} NAME_WE)
- IF (POLICY CMP0026)
- CMAKE_POLICY(POP) # set policy back to original settings
- ENDIF()
IF(CMAKE_CONFIGURATION_TYPES)
FOREACH(_config ${CMAKE_CONFIGURATION_TYPES})
- SET(_helper_filename ${_output_dir}/${_config}/${_target_filename}${_extension})
+ SET(_helper_filename ${_output_dir}/${_config}/${_target_name}${_extension})
- FILE(WRITE ${_helper_filename} ${_target_name})
+ FILE(GENERATE OUTPUT ${_helper_filename} CONTENT $<TARGET_FILE_NAME:${_target_name}>)
INSTALL(
FILES ${_helper_filename}
@@ -497,9 +486,9 @@
)
ENDFOREACH()
ELSE()
- SET(_helper_filename ${_output_dir}/${_target_filename}${_extension})
+ SET(_helper_filename ${_output_dir}/${_target_name}${_extension})
- FILE(WRITE ${_helper_filename} ${_target_name})
+ FILE(GENERATE OUTPUT ${_helper_filename} CONTENT $<TARGET_FILE_NAME:${_target_name}>)
INSTALL(
FILES ${_helper_filename}
Modified: code/trunk/src/libraries/core/ApplicationPaths.cc
===================================================================
--- code/trunk/src/libraries/core/ApplicationPaths.cc 2018-01-03 00:05:21 UTC (rev 11691)
+++ code/trunk/src/libraries/core/ApplicationPaths.cc 2018-01-03 00:43:20 UTC (rev 11692)
@@ -31,6 +31,7 @@
#include <cassert>
#include <cstdlib>
#include <cstdio>
+#include <fstream>
#include <vector>
#include <boost/filesystem.hpp>
@@ -168,19 +169,19 @@
delete &pluginPath_;
}
- std::vector<std::string> ApplicationPaths::getModulePaths()
+ std::map<std::string, std::string> ApplicationPaths::getModulePaths()
{
return this->getModuleOrPluginPaths(modulePath_, specialConfig::moduleExtension);
}
- std::vector<std::string> ApplicationPaths::getPluginPaths()
+ std::map<std::string, std::string> ApplicationPaths::getPluginPaths()
{
return this->getModuleOrPluginPaths(pluginPath_, specialConfig::pluginExtension);
}
- std::vector<std::string> ApplicationPaths::getModuleOrPluginPaths(boost::filesystem::path& directory, const std::string& extension)
+ std::map<std::string, std::string> ApplicationPaths::getModuleOrPluginPaths(boost::filesystem::path& directory, const std::string& extension)
{
- std::vector<std::string> paths;
+ std::map<std::string, std::string> paths;
// We search for helper files with the following extension
size_t extensionlength = extension.size();
@@ -203,8 +204,20 @@
if (filename.substr(filename.size() - extensionlength) == extension)
{
// We've found a helper file
- const std::string& library = filename.substr(0, filename.size() - extensionlength);
- paths.push_back(directory.BF_GENERIC_STRING() + '/' + library);
+ const std::string& moduleName = filename.substr(0, filename.size() - extensionlength);
+
+ // Read it's content to get the library's name
+ std::ifstream infile(file->path().string().c_str());
+ std::string libraryName;
+ if (infile >> libraryName)
+ {
+ std::string libraryPath = directory.BF_GENERIC_STRING() + '/' + libraryName;
+ paths[moduleName] = libraryPath;
+ }
+ else
+ {
+ orxout(internal_warning) << "Could not file " << filename << endl;
+ }
}
}
++file;
Modified: code/trunk/src/libraries/core/ApplicationPaths.h
===================================================================
--- code/trunk/src/libraries/core/ApplicationPaths.h 2018-01-03 00:05:21 UTC (rev 11691)
+++ code/trunk/src/libraries/core/ApplicationPaths.h 2018-01-03 00:43:20 UTC (rev 11692)
@@ -97,10 +97,10 @@
//! Return true for runs in the build directory (not installed)
static bool buildDirectoryRun() { return getInstance().bBuildDirectoryRun_; }
- //! Returns a list with all modules declared by a *.module file in the module folder.
- std::vector<std::string> getModulePaths();
- //! Returns a list with all plugins declared by a *.plugin file in the plugin folder.
- std::vector<std::string> getPluginPaths();
+ //! Returns a map with all modules declared by a *.module file in the module folder; key = module-name, value = library-path (content of the file).
+ std::map<std::string, std::string> getModulePaths();
+ //! Returns a map with all plugins declared by a *.plugin file in the plugin folder; key = plugin-name, value = library-path (content of the file).
+ std::map<std::string, std::string> getPluginPaths();
private:
// non-copyable:
@@ -107,7 +107,7 @@
ApplicationPaths(const ApplicationPaths&) = delete;
ApplicationPaths& operator=(const ApplicationPaths&) = delete;
- std::vector<std::string> getModuleOrPluginPaths(boost::filesystem::path& directory, const std::string& extension);
+ std::map<std::string, std::string> getModuleOrPluginPaths(boost::filesystem::path& directory, const std::string& extension);
//! Path to the parent directory of the ones above if program was installed with relative paths
boost::filesystem::path& rootPath_;
Modified: code/trunk/src/libraries/core/Core.cc
===================================================================
--- code/trunk/src/libraries/core/Core.cc 2018-01-03 00:05:21 UTC (rev 11691)
+++ code/trunk/src/libraries/core/Core.cc 2018-01-03 00:43:20 UTC (rev 11692)
@@ -280,10 +280,10 @@
{
orxout(internal_info) << "Loading modules:" << endl;
- const std::vector<std::string>& modulePaths = ApplicationPaths::getInstance().getModulePaths();
- for (const std::string& modulePath : modulePaths)
+ const std::map<std::string, std::string>& modulePaths = ApplicationPaths::getInstance().getModulePaths();
+ for (const std::pair<std::string, std::string>& modulePath : modulePaths)
{
- ModuleInstance* module = new ModuleInstance(modulePath);
+ ModuleInstance* module = new ModuleInstance(modulePath.second);
this->loadModule(module);
this->modules_.push_back(module);
}
Modified: code/trunk/src/libraries/core/module/PluginManager.cc
===================================================================
--- code/trunk/src/libraries/core/module/PluginManager.cc 2018-01-03 00:05:21 UTC (rev 11691)
+++ code/trunk/src/libraries/core/module/PluginManager.cc 2018-01-03 00:43:20 UTC (rev 11692)
@@ -28,8 +28,6 @@
#include "PluginManager.h"
-#include <fstream>
-
#include "SpecialConfig.h"
#include "Plugin.h"
#include "PluginReference.h"
@@ -94,21 +92,14 @@
void PluginManager::findPlugins()
{
- const std::vector<std::string>& pluginPaths = ApplicationPaths::getInstance().getPluginPaths();
- for (const std::string& libraryName : pluginPaths)
+ const std::map<std::string, std::string>& pluginPaths = ApplicationPaths::getInstance().getPluginPaths();
+ for (const std::pair<std::string, std::string>& pluginPath : pluginPaths)
{
- std::string name;
- std::string filename = libraryName + + specialConfig::pluginExtension;
- std::ifstream infile(filename.c_str());
- if (infile >> name)
- {
- orxout(internal_info) << "Found plugin with name '" << name << "' in module " << libraryName << endl;
- this->plugins_[name] = new Plugin(name, libraryName);
- }
- else
- {
- orxout(internal_warning) << "Could not read plugin file " << filename << endl;
- }
+ const std::string& name = pluginPath.first;
+ const std::string& libraryName = pluginPath.second;
+
+ orxout(internal_info) << "Found plugin with name '" << name << "' in module " << libraryName << endl;
+ this->plugins_[name] = new Plugin(name, libraryName);
}
}
More information about the Orxonox-commit
mailing list