Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10547


Ignore:
Timestamp:
Aug 23, 2015, 11:57:53 AM (9 years ago)
Author:
landauf
Message:

added support for plugins in the buildsystem. plugins are like modules, but can be loaded/unloaded at runtime

Location:
code/branches/core7
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/CMakeLists.txt

    r9550 r10547  
    6565SET(DEFAULT_ARCHIVE_PATH lib/static)
    6666SET(DEFAULT_MODULE_PATH  lib/modules)
     67SET(DEFAULT_PLUGIN_PATH  lib/plugins)
    6768SET(DEFAULT_DOC_PATH     doc)
    6869SET(DEFAULT_DATA_PATH    data)
     
    7677SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${DEFAULT_ARCHIVE_PATH})
    7778SET(CMAKE_MODULE_OUTPUT_DIRECTORY  ${CMAKE_BINARY_DIR}/${DEFAULT_MODULE_PATH})
     79SET(CMAKE_PLUGIN_OUTPUT_DIRECTORY  ${CMAKE_BINARY_DIR}/${DEFAULT_PLUGIN_PATH})
    7880SET(CMAKE_DOC_OUTPUT_DIRECTORY     ${CMAKE_BINARY_DIR}/${DEFAULT_DOC_PATH})
    7981# Data directories are only inputs, no delclaration here
     
    8385# Set the extension of the dynamic modules
    8486SET(ORXONOX_MODULE_EXTENSION ".module")
     87SET(ORXONOX_PLUGIN_EXTENSION ".plugin")
    8588
    8689# Sets where to find the external libraries like OgreMain.dll at runtime
  • code/branches/core7/cmake/InstallConfig.cmake

    r8405 r10547  
    4949SET(ARCHIVE_INSTALL_DIRECTORY ${DEFAULT_ARCHIVE_PATH})
    5050SET(MODULE_INSTALL_DIRECTORY  ${DEFAULT_MODULE_PATH})
     51SET(PLUGIN_INSTALL_DIRECTORY  ${DEFAULT_PLUGIN_PATH})
    5152SET(DOC_INSTALL_DIRECTORY     ${DEFAULT_DOC_PATH})
    5253SET(DATA_INSTALL_DIRECTORY    ${DEFAULT_DATA_PATH})
     
    6162    SET(ARCHIVE_INSTALL_DIRECTORY lib/games/orxonox/static)
    6263    SET(MODULE_INSTALL_DIRECTORY  lib/games/orxonox/modules)
     64    SET(PLUGIN_INSTALL_DIRECTORY  lib/games/orxonox/plugins)
    6365    SET(DOC_INSTALL_DIRECTORY     share/doc/orxonox)
    6466    SET(DATA_INSTALL_DIRECTORY    share/games/orxonox)
     
    8587# The RPATH to be used when installing
    8688IF(INSTALL_COPYABLE)
    87   # Get relative paths from run to lib and from module to lib directory.
     89  # Get relative paths from run to lib and from module/plugin to lib directory.
    8890  FILE(RELATIVE_PATH _runtime_rpath "/${RUNTIME_INSTALL_DIRECTORY}" "/${LIBRARY_INSTALL_DIRECTORY}")
    8991  FILE(RELATIVE_PATH _module_rpath  "/${MODULE_INSTALL_DIRECTORY}" "/${LIBRARY_INSTALL_DIRECTORY}")
     92  FILE(RELATIVE_PATH _plugin_rpath  "/${PLUGIN_INSTALL_DIRECTORY}" "/${LIBRARY_INSTALL_DIRECTORY}")
    9093  # $ORIGIN (with $ escaped) refers to the actual location of the library
    9194  # The UNIX loader recognises this special variable
     
    9396  SET(LIBRARY_RPATH "\$ORIGIN")
    9497  SET(MODULE_RPATH  "\$ORIGIN:\$ORIGIN/${_module_rpath}")
     98  SET(PLUGIN_RPATH  "\$ORIGIN:\$ORIGIN/${_plugin_rpath}")
    9599ELSE()
    96100  SET(RUNTIME_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_DIRECTORY}")
    97101  SET(LIBRARY_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_DIRECTORY}")
    98102  SET(MODULE_RPATH  "${LIBRARY_RPATH}:${CMAKE_INSTALL_PREFIX}/${MODULE_INSTALL_DIRECTORY}")
     103  SET(PLUGIN_RPATH  "${LIBRARY_RPATH}:${CMAKE_INSTALL_PREFIX}/${PLUGIN_INSTALL_DIRECTORY}")
    99104ENDIF()
    100105
  • code/branches/core7/cmake/tools/TargetUtilities.cmake

    r10267 r10547  
    3535 #      NO_SOURCE_GROUPS:  Don't create msvc source groups
    3636 #      MODULE:            For dynamic module libraries (libraries only)
     37 #      PLUGIN:            For dynamic plugin libraries (libraries only)
     38 #                         Plugins are a special kind of modules that can be
     39 #                         loaded and unloaded during runtime on demand
    3740 #      WIN32:             Inherited from ADD_EXECUTABLE (executables only)
    3841 #      PCH_NO_DEFAULT:    Do not make precompiled header files default if
     
    7780
    7881MACRO(ORXONOX_ADD_LIBRARY _target_name)
    79   TU_ADD_TARGET(${_target_name} LIBRARY "MODULE" ${ARGN})
     82  SET(_additional_switches MODULE PLUGIN)
     83  TU_ADD_TARGET(${_target_name} LIBRARY "${_additional_switches}" ${ARGN})
    8084ENDMACRO(ORXONOX_ADD_LIBRARY)
    8185
    8286MACRO(ORXONOX_ADD_EXECUTABLE _target_name)
    83   TU_ADD_TARGET(${_target_name} EXECUTABLE "WIN32" ${ARGN})
     87  SET(_additional_switches WIN32)
     88  TU_ADD_TARGET(${_target_name} EXECUTABLE "${_additional_switches}" ${ARGN})
    8489 
    8590  # When using Visual Studio we want to use the output directory as working
     
    329334      LIBRARY_OUTPUT_DIRECTORY ${CMAKE_MODULE_OUTPUT_DIRECTORY} # Unix
    330335    )
    331     ADD_MODULE(${_target_name})
     336    ADD_MODULE_OR_PLUGIN(${_target_name} ${CMAKE_MODULE_OUTPUT_DIRECTORY} ${MODULE_INSTALL_DIRECTORY} ${ORXONOX_MODULE_EXTENSION})
    332337    # Ensure that the main program depends on the module
    333338    SET(ORXONOX_MODULES ${ORXONOX_MODULES} ${_target_name} CACHE INTERNAL "")
     339  ENDIF()
     340
     341  # Configure plugins
     342  IF (_arg_PLUGIN)
     343    SET_TARGET_PROPERTIES(${_target_name} PROPERTIES
     344      RUNTIME_OUTPUT_DIRECTORY ${CMAKE_PLUGIN_OUTPUT_DIRECTORY} # Windows
     345      LIBRARY_OUTPUT_DIRECTORY ${CMAKE_PLUGIN_OUTPUT_DIRECTORY} # Unix
     346    )
     347    ADD_MODULE_OR_PLUGIN(${_target_name} ${CMAKE_PLUGIN_OUTPUT_DIRECTORY} ${PLUGIN_INSTALL_DIRECTORY} ${ORXONOX_PLUGIN_EXTENSION})
    334348  ENDIF()
    335349
     
    372386    IF(_arg_MODULE)
    373387      SET(_rpath "${MODULE_RPATH}")
     388    ELSEIF(_arg_PLUGIN)
     389      SET(_rpath "${PLUGIN_RPATH}")
    374390    ELSE()
    375391      SET(_rpath "${LIBRARY_RPATH}")
     
    411427        RUNTIME DESTINATION ${MODULE_INSTALL_DIRECTORY}
    412428        LIBRARY DESTINATION ${MODULE_INSTALL_DIRECTORY}
     429      )
     430    ELSEIF(_arg_PLUGIN)
     431      INSTALL(TARGETS ${_target_name}
     432        RUNTIME DESTINATION ${PLUGIN_INSTALL_DIRECTORY}
     433        LIBRARY DESTINATION ${PLUGIN_INSTALL_DIRECTORY}
    413434      )
    414435    ELSE()
     
    428449            CONFIGURATIONS ${_config}
    429450          )
     451        ELSEIF(_arg_PLUGIN)
     452          INSTALL(FILES ${_location_we}.pdb
     453            DESTINATION ${PLUGIN_INSTALL_DIRECTORY}
     454            CONFIGURATIONS ${_config}
     455          )
    430456        ELSE()
    431457          INSTALL(FILES ${_location_we}.pdb
     
    441467
    442468
    443 # Creates a helper file with name <name_of_the_library>${ORXONOX_MODULE_EXTENSION}
    444 # This helps finding dynamically loadable modules at runtime
    445 
    446 FUNCTION(ADD_MODULE _target)
     469# Creates a helper file with name <name_of_the_library>.<extension>
     470# This helps finding dynamically loadable modules or plugins at runtime
     471
     472FUNCTION(ADD_MODULE_OR_PLUGIN _target _output_dir _install_dir _extension)
    447473  # We use the properties to get the name because the librarys name may differ from
    448474  # the target name (for example orxonox <-> liborxonox)
     
    459485  IF(CMAKE_CONFIGURATION_TYPES)
    460486    FOREACH(_config ${CMAKE_CONFIGURATION_TYPES})
    461       SET(_module_filename ${CMAKE_MODULE_OUTPUT_DIRECTORY}/${_config}/${_target_name}${ORXONOX_MODULE_EXTENSION})
    462 
    463       FILE(WRITE ${_module_filename})
     487      SET(_helper_filename ${_output_dir}/${_config}/${_target_name}${_extension})
     488
     489      FILE(WRITE ${_helper_filename})
    464490
    465491      INSTALL(
    466         FILES ${_module_filename}
    467         DESTINATION ${MODULE_INSTALL_DIRECTORY}
     492        FILES ${_helper_filename}
     493        DESTINATION ${_install_dir}
    468494        CONFIGURATIONS ${_config}
    469495      )
    470496    ENDFOREACH()
    471497  ELSE()
    472     SET(_module_filename ${CMAKE_MODULE_OUTPUT_DIRECTORY}/${_target_name}${ORXONOX_MODULE_EXTENSION})
    473 
    474     FILE(WRITE ${_module_filename})
     498    SET(_helper_filename ${_output_dir}/${_target_name}${_extension})
     499
     500    FILE(WRITE ${_helper_filename})
    475501
    476502    INSTALL(
    477       FILES ${_module_filename}
    478       DESTINATION ${MODULE_INSTALL_DIRECTORY}
     503      FILES ${_helper_filename}
     504      DESTINATION ${_install_dir}
    479505    )
    480506  ENDIF()
    481 ENDFUNCTION(ADD_MODULE)
     507ENDFUNCTION(ADD_MODULE_OR_PLUGIN)
  • code/branches/core7/src/CMakeLists.txt

    r10268 r10547  
    3939ADD_SUBDIRECTORY(orxonox)
    4040SET(ORXONOX_MODULES CACHE INTERNAL "")
     41SET(ORXONOX_PLUGINS CACHE INTERNAL "")
    4142ADD_SUBDIRECTORY(modules)
    4243
     
    7273  OUTPUT_NAME orxonox
    7374)
    74 # Main executable should depend on all modules
     75# Main executable should depend on all modules (but not on plugins)
    7576ADD_DEPENDENCIES(orxonox-main ${ORXONOX_MODULES})
    7677
  • code/branches/core7/src/SpecialConfig.h.in

    r8351 r10547  
    6060    const char defaultArchivePath[] = "@DEFAULT_ARCHIVE_PATH@";
    6161    const char defaultModulePath[]  = "@DEFAULT_MODULE_PATH@";
     62    const char defaultPluginPath[]  = "@DEFAULT_PLUGIN_PATH@";
    6263    const char defaultDocPath[]     = "@DEFAULT_DOC_PATH@";
    6364    const char defaultDataPath[]    = "@DEFAULT_DATA_PATH@";
     
    6970    const char dataInstallDirectory[]       = "@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIRECTORY@";
    7071    const char moduleInstallDirectory[]     = "@CMAKE_INSTALL_PREFIX@/@MODULE_INSTALL_DIRECTORY@";
     72    const char pluginInstallDirectory[]     = "@CMAKE_INSTALL_PREFIX@/@PLUGIN_INSTALL_DIRECTORY@";
    7173#endif
    7274
     
    7678#ifdef CMAKE_CONFIGURATION_TYPES
    7779    const char moduleDevDirectory[]         = "@CMAKE_MODULE_OUTPUT_DIRECTORY@/" CMAKE_INTDIR;
     80    const char pluginDevDirectory[]         = "@CMAKE_PLUGIN_OUTPUT_DIRECTORY@/" CMAKE_INTDIR;
    7881    const char configDevDirectory[]         = "@CMAKE_CONFIG_OUTPUT_DIRECTORY@/" CMAKE_INTDIR;
    7982    const char logDevDirectory[]            = "@CMAKE_LOG_OUTPUT_DIRECTORY@/"    CMAKE_INTDIR;
    8083#else
    8184    const char moduleDevDirectory[]         = "@CMAKE_MODULE_OUTPUT_DIRECTORY@";
     85    const char pluginDevDirectory[]         = "@CMAKE_PLUGIN_OUTPUT_DIRECTORY@";
    8286    const char configDevDirectory[]         = "@CMAKE_CONFIG_OUTPUT_DIRECTORY@";
    8387    const char logDevDirectory[]            = "@CMAKE_LOG_OUTPUT_DIRECTORY@";
     
    8892#endif
    8993
    90     // Module extension
     94    // Module and plugin extension
    9195    const char moduleExtension[] = "@ORXONOX_MODULE_EXTENSION@";
     96    const char pluginExtension[] = "@ORXONOX_PLUGIN_EXTENSION@";
    9297
    9398    // OGRE PLUGINS
  • code/branches/core7/src/libraries/core/ApplicationPaths.cc

    r10509 r10547  
    7474        , executablePath_(*(new bf::path()))
    7575        , modulePath_(*(new bf::path()))
     76        , pluginPath_(*(new bf::path()))
    7677        , bBuildDirectoryRun_(false)
    7778    {
     
    121122        executablePath_ = bf::path(buffer).branch_path();
    122123
    123         /////////////////////
    124         // SET MODULE PATH //
    125         /////////////////////
     124        /////////////////////////////////
     125        // SET MODULE AND PLUGIN PATHS //
     126        /////////////////////////////////
    126127
    127128        if (bf::exists(executablePath_ / "orxonox_dev_build.keep_me"))
     
    130131            ApplicationPaths::bBuildDirectoryRun_ = true;
    131132            modulePath_ = specialConfig::moduleDevDirectory;
     133            pluginPath_ = specialConfig::pluginDevDirectory;
    132134        }
    133135        else
     
    144146                ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
    145147
    146             // Module path is fixed as well
     148            // Module and plugin paths are fixed as well
    147149            modulePath_ = rootPath_ / specialConfig::defaultModulePath;
     150            pluginPath_ = rootPath_ / specialConfig::defaultPluginPath;
    148151
    149152#else
    150153
    151154            // There is no root path, so don't set it at all
    152             // Module path is fixed as well
     155            // Module and plugin paths are fixed as well
    153156            modulePath_ = specialConfig::moduleInstallDirectory;
     157            pluginPath_ = specialConfig::pluginInstallDirectory;
    154158
    155159#endif
     
    162166        delete &executablePath_;
    163167        delete &modulePath_;
     168        delete &pluginPath_;
    164169    }
    165170
    166171    std::vector<std::string> ApplicationPaths::getModulePaths()
    167172    {
    168         std::vector<std::string> modulePaths;
     173        return this->getModuleOrPluginPaths(modulePath_, specialConfig::moduleExtension);
     174    }
     175
     176    std::vector<std::string> ApplicationPaths::getPluginPaths()
     177    {
     178        return this->getModuleOrPluginPaths(pluginPath_, specialConfig::pluginExtension);
     179    }
     180
     181    std::vector<std::string> ApplicationPaths::getModuleOrPluginPaths(boost::filesystem::path& directory, const std::string& extension)
     182    {
     183        std::vector<std::string> paths;
    169184
    170185        // We search for helper files with the following extension
    171         const std::string& moduleextension = specialConfig::moduleExtension;
    172         size_t moduleextensionlength = moduleextension.size();
    173 
    174         // Make sure the path exists, otherwise don't load modules
    175         if (!boost::filesystem::exists(modulePath_))
    176             return modulePaths;
    177 
    178         boost::filesystem::directory_iterator file(modulePath_);
     186        size_t extensionlength = extension.size();
     187
     188        // Make sure the path exists, otherwise don't load modules/plugins
     189        if (!boost::filesystem::exists(directory))
     190            return paths;
     191
     192        boost::filesystem::directory_iterator file(directory);
    179193        boost::filesystem::directory_iterator end;
    180194
     
    185199
    186200            // Check if the file ends with the extension in question
    187             if (filename.size() > moduleextensionlength)
     201            if (filename.size() > extensionlength)
    188202            {
    189                 if (filename.substr(filename.size() - moduleextensionlength) == moduleextension)
     203                if (filename.substr(filename.size() - extensionlength) == extension)
    190204                {
    191205                    // We've found a helper file
    192                     const std::string& library = filename.substr(0, filename.size() - moduleextensionlength);
    193                     modulePaths.push_back(getModulePathString() + library);
     206                    const std::string& library = filename.substr(0, filename.size() - extensionlength);
     207                    paths.push_back(directory.BF_GENERIC_STRING() + '/' + library);
    194208                }
    195209            }
     
    197211        }
    198212
    199         return modulePaths;
     213        return paths;
    200214    }
    201215
     
    214228        return getInstance().modulePath_.BF_GENERIC_STRING() + '/';
    215229    }
     230
     231    /*static*/ std::string ApplicationPaths::getPluginPathString()
     232    {
     233        return getInstance().pluginPath_.BF_GENERIC_STRING() + '/';
     234    }
    216235}
  • code/branches/core7/src/libraries/core/ApplicationPaths.h

    r10509 r10547  
    4949        The ApplicationPaths class is a singleton which provides static paths of the application.
    5050    @details
    51         The class provides information about the executable, root and module path.
     51        The class provides information about the executable, root and module/plugin path.
    5252        It determines those by the use of platform specific functions.
    5353    @remarks
     
    6363            /**
    6464            @brief
    65                 Retrieves the executable path and sets all hard coded fixed paths (currently only the module path)
     65                Retrieves the executable path and sets all hard coded fixed paths (currently only the module and the plugin paths)
    6666                Also checks for "orxonox_dev_build.keep_me" in the executable directory.
    6767                If found it means that this is not an installed run, hence we
     
    8282            static const boost::filesystem::path& getModulePath()
    8383                { return getInstance().modulePath_; }
     84            //! Returns the path to the plugins as boost::filesystem::path
     85            static const boost::filesystem::path& getPluginPath()
     86                { return getInstance().pluginPath_; }
    8487
    8588            //! Returns the path to the root folder as std::string
     
    8992            //! Returns the path to the modules as std::string
    9093            static std::string getModulePathString();
     94            //! Returns the path to the plugins as std::string
     95            static std::string getPluginPathString();
    9196
    9297            //! Return true for runs in the build directory (not installed)
     
    95100            //! Returns a list with all modules declared by a *.module file in the module folder.
    96101            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();
    97104
    98105        private:
    99106            ApplicationPaths(const ApplicationPaths&); //!< Don't use (undefined symbol)
     107
     108            std::vector<std::string> getModuleOrPluginPaths(boost::filesystem::path& directory, const std::string& extension);
    100109
    101110            //! Path to the parent directory of the ones above if program was installed with relative paths
     
    103112            boost::filesystem::path& executablePath_;        //!< Path to the executable
    104113            boost::filesystem::path& modulePath_;            //!< Path to the modules
     114            boost::filesystem::path& pluginPath_;            //!< Path to the plugins
    105115
    106116            bool                     bBuildDirectoryRun_;    //!< True for runs in the build directory (not installed)
  • code/branches/core7/src/libraries/core/Core.cc

    r10544 r10547  
    142142        orxout(internal_info) << "Executable path: " << ApplicationPaths::getExecutablePathString() << endl;
    143143        orxout(internal_info) << "Modules path:    " << ApplicationPaths::getModulePathString() << endl;
     144        orxout(internal_info) << "Plugins path:    " << ApplicationPaths::getPluginPathString() << endl;
    144145
    145146        orxout(internal_info) << "Data path:       " << ConfigurablePaths::getDataPathString() << endl;
Note: See TracChangeset for help on using the changeset viewer.