Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11692 for code/trunk


Ignore:
Timestamp:
Jan 3, 2018, 1:43:20 AM (7 years ago)
Author:
landauf
Message:

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

Location:
code/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/cmake/tools/TargetUtilities.cmake

    r10716 r11692  
    469469
    470470
    471 # Creates a helper file with name <name_of_the_library>.<extension>
     471# Creates a helper file with name <target_name>.<extension> and content <filename_of_the_library>
    472472# This helps finding dynamically loadable modules or plugins at runtime
    473473
    474474FUNCTION(ADD_MODULE_OR_PLUGIN _target_name _output_dir _install_dir _extension)
    475   # We use the properties to get the name because the librarys name may differ from
    476   # the target name (for example orxonox <-> liborxonox)
    477   IF (POLICY CMP0026)
    478     CMAKE_POLICY(PUSH)
    479     CMAKE_POLICY(SET CMP0026 OLD) # we only use the file's name, not its actual location, so the old policy is fine
    480   ENDIF()
    481   GET_TARGET_PROPERTY(_target_loc ${_target_name} LOCATION)
    482   GET_FILENAME_COMPONENT(_target_filename ${_target_loc} NAME_WE)
    483   IF (POLICY CMP0026)
    484     CMAKE_POLICY(POP) # set policy back to original settings
    485   ENDIF()
    486475
    487476  IF(CMAKE_CONFIGURATION_TYPES)
    488477    FOREACH(_config ${CMAKE_CONFIGURATION_TYPES})
    489       SET(_helper_filename ${_output_dir}/${_config}/${_target_filename}${_extension})
    490 
    491       FILE(WRITE ${_helper_filename} ${_target_name})
     478      SET(_helper_filename ${_output_dir}/${_config}/${_target_name}${_extension})
     479
     480      FILE(GENERATE OUTPUT ${_helper_filename} CONTENT $<TARGET_FILE_NAME:${_target_name}>)
    492481
    493482      INSTALL(
     
    498487    ENDFOREACH()
    499488  ELSE()
    500     SET(_helper_filename ${_output_dir}/${_target_filename}${_extension})
    501 
    502     FILE(WRITE ${_helper_filename} ${_target_name})
     489    SET(_helper_filename ${_output_dir}/${_target_name}${_extension})
     490
     491    FILE(GENERATE OUTPUT ${_helper_filename} CONTENT $<TARGET_FILE_NAME:${_target_name}>)
    503492
    504493    INSTALL(
  • code/trunk/src/libraries/core/ApplicationPaths.cc

    r11071 r11692  
    3232#include <cstdlib>
    3333#include <cstdio>
     34#include <fstream>
    3435#include <vector>
    3536#include <boost/filesystem.hpp>
     
    169170    }
    170171
    171     std::vector<std::string> ApplicationPaths::getModulePaths()
     172    std::map<std::string, std::string> ApplicationPaths::getModulePaths()
    172173    {
    173174        return this->getModuleOrPluginPaths(modulePath_, specialConfig::moduleExtension);
    174175    }
    175176
    176     std::vector<std::string> ApplicationPaths::getPluginPaths()
     177    std::map<std::string, std::string> ApplicationPaths::getPluginPaths()
    177178    {
    178179        return this->getModuleOrPluginPaths(pluginPath_, specialConfig::pluginExtension);
    179180    }
    180181
    181     std::vector<std::string> ApplicationPaths::getModuleOrPluginPaths(boost::filesystem::path& directory, const std::string& extension)
    182     {
    183         std::vector<std::string> paths;
     182    std::map<std::string, std::string> ApplicationPaths::getModuleOrPluginPaths(boost::filesystem::path& directory, const std::string& extension)
     183    {
     184        std::map<std::string, std::string> paths;
    184185
    185186        // We search for helper files with the following extension
     
    204205                {
    205206                    // We've found a helper file
    206                     const std::string& library = filename.substr(0, filename.size() - extensionlength);
    207                     paths.push_back(directory.BF_GENERIC_STRING() + '/' + library);
     207                    const std::string& moduleName = filename.substr(0, filename.size() - extensionlength);
     208
     209                    // Read it's content to get the library's name
     210                    std::ifstream infile(file->path().string().c_str());
     211                    std::string libraryName;
     212                    if (infile >> libraryName)
     213                    {
     214                        std::string libraryPath = directory.BF_GENERIC_STRING() + '/' + libraryName;
     215                        paths[moduleName] = libraryPath;
     216                    }
     217                    else
     218                    {
     219                        orxout(internal_warning) << "Could not file " << filename << endl;
     220                    }
    208221                }
    209222            }
  • code/trunk/src/libraries/core/ApplicationPaths.h

    r11071 r11692  
    9898            static bool buildDirectoryRun() { return getInstance().bBuildDirectoryRun_; }
    9999
    100             //! Returns a list with all modules declared by a *.module file in the module folder.
    101             std::vector<std::string> getModulePaths();
    102             //! Returns a list with all plugins declared by a *.plugin file in the plugin folder.
    103             std::vector<std::string> getPluginPaths();
     100            //! 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).
     101            std::map<std::string, std::string> getModulePaths();
     102            //! 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).
     103            std::map<std::string, std::string> getPluginPaths();
    104104
    105105        private:
     
    108108            ApplicationPaths& operator=(const ApplicationPaths&) = delete;
    109109
    110             std::vector<std::string> getModuleOrPluginPaths(boost::filesystem::path& directory, const std::string& extension);
     110            std::map<std::string, std::string> getModuleOrPluginPaths(boost::filesystem::path& directory, const std::string& extension);
    111111
    112112            //! Path to the parent directory of the ones above if program was installed with relative paths
  • code/trunk/src/libraries/core/Core.cc

    r11691 r11692  
    281281        orxout(internal_info) << "Loading modules:" << endl;
    282282
    283         const std::vector<std::string>& modulePaths = ApplicationPaths::getInstance().getModulePaths();
    284         for (const std::string& modulePath : modulePaths)
    285         {
    286             ModuleInstance* module = new ModuleInstance(modulePath);
     283        const std::map<std::string, std::string>& modulePaths = ApplicationPaths::getInstance().getModulePaths();
     284        for (const std::pair<std::string, std::string>& modulePath : modulePaths)
     285        {
     286            ModuleInstance* module = new ModuleInstance(modulePath.second);
    287287            this->loadModule(module);
    288288            this->modules_.push_back(module);
  • code/trunk/src/libraries/core/module/PluginManager.cc

    r11071 r11692  
    2828
    2929#include "PluginManager.h"
    30 
    31 #include <fstream>
    3230
    3331#include "SpecialConfig.h"
     
    9593    void PluginManager::findPlugins()
    9694    {
    97         const std::vector<std::string>& pluginPaths = ApplicationPaths::getInstance().getPluginPaths();
    98         for (const std::string& libraryName : pluginPaths)
     95        const std::map<std::string, std::string>& pluginPaths = ApplicationPaths::getInstance().getPluginPaths();
     96        for (const std::pair<std::string, std::string>& pluginPath : pluginPaths)
    9997        {
    100             std::string name;
    101             std::string filename = libraryName +  + specialConfig::pluginExtension;
    102             std::ifstream infile(filename.c_str());
    103             if (infile >> name)
    104             {
    105                 orxout(internal_info) << "Found plugin with name '" << name << "' in module " << libraryName << endl;
    106                 this->plugins_[name] = new Plugin(name, libraryName);
    107             }
    108             else
    109             {
    110                 orxout(internal_warning) << "Could not read plugin file " << filename << endl;
    111             }
     98            const std::string& name = pluginPath.first;
     99            const std::string& libraryName = pluginPath.second;
     100
     101            orxout(internal_info) << "Found plugin with name '" << name << "' in module " << libraryName << endl;
     102            this->plugins_[name] = new Plugin(name, libraryName);
    112103        }
    113104    }
Note: See TracChangeset for help on using the changeset viewer.