Skip to content

Commit

Permalink
Merge pull request #436 from gergondet/topic/ImproveAutoload
Browse files Browse the repository at this point in the history
Autoload improvments
  • Loading branch information
gergondet authored Feb 27, 2024
2 parents d1464f6 + 44a9e1b commit 4c0c47b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
18 changes: 15 additions & 3 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
#

macro(add_plugin plugin)
option(AUTOLOAD_${plugin}_PLUGIN "Automatically load ${plugin} plugin" ON)
cmake_parse_arguments(ADD_PLUGIN "AUTOLOAD" "" "" ${ARGN})
option(AUTOLOAD_${plugin}_PLUGIN "Automatically load ${plugin} plugin"
${ADD_PLUGIN_AUTOLOAD}
)
if(MC_RTC_BUILD_STATIC)
target_sources(mc_control PRIVATE ${ARGN})
target_sources(mc_control PRIVATE ${ADD_PLUGIN_UNPARSED_ARGUMENTS})
else()
add_library(${plugin} SHARED ${ARGN})
add_library(${plugin} SHARED ${ADD_PLUGIN_UNPARSED_ARGUMENTS})
set_target_properties(${plugin} PROPERTIES PREFIX "")
target_link_libraries(${plugin} PUBLIC mc_rtc::mc_control)
install(
Expand All @@ -28,6 +31,15 @@ macro(add_plugin plugin)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/stage/autoload/${plugin}.yaml"
DESTINATION "${MC_PLUGINS_RUNTIME_INSTALL_PREFIX}/autoload/"
)
else()
set(AUTOLOAD_DESTINATION "${AUTOLOAD_DESTINATION}/${plugin}.yaml")
install(
CODE "
if(EXISTS \"${AUTOLOAD_DESTINATION}\")
message(STATUS \"Removing: ${AUTOLOAD_DESTINATION}\")
file(REMOVE \"${AUTOLOAD_DESTINATION}\")
endif()"
)
endif()
endmacro()

Expand Down
2 changes: 1 addition & 1 deletion plugins/ROS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ set(plugin_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/plugin/ROS.cpp"
set(plugin_HDR "${CMAKE_CURRENT_SOURCE_DIR}/src/plugin/ROS.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/plugin/Services.h"
)
add_plugin(ROS "${plugin_SRC}" "${plugin_HDR}")
add_plugin(ROS AUTOLOAD ${plugin_SRC} ${plugin_HDR})
set_target_properties(ROS PROPERTIES COMPILE_FLAGS "-DMC_RTC_ROS_PLUGIN_EXPORTS")
target_link_libraries(ROS PUBLIC mc_rtc_ros mc_tasks_ros)
install(FILES etc/ROS.yaml DESTINATION "${MC_PLUGINS_RUNTIME_INSTALL_PREFIX}/etc")
10 changes: 8 additions & 2 deletions src/mc_control/mc_global_controller_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,16 @@ MCGlobalController::GlobalConfiguration::GlobalConfiguration(const std::string &
std::ifstream ifs(p.string());
std::stringstream ss;
ss << ifs.rdbuf();
auto plugin = ss.str();
auto plugin = [&ss]()
{
auto out = ss.str();
out.erase(std::find_if(out.rbegin(), out.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(),
out.end());
return out;
}();
if(std::find(global_plugins.begin(), global_plugins.end(), plugin) == global_plugins.end())
{
global_plugins.push_back(ss.str());
global_plugins.push_back(plugin);
global_plugins_autoload.push_back(global_plugins.back());
}
}
Expand Down
17 changes: 15 additions & 2 deletions src/mc_rtcMacros.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,11 @@ endmacro()
mc_rtc_set_prefix(PLUGINS mc_plugins)

macro(add_plugin plugin)
option(AUTOLOAD_${plugin}_PLUGIN "Automatically load ${plugin} plugin" ON)
add_library(${plugin} SHARED ${ARGN})
cmake_parse_arguments(ADD_PLUGIN "AUTOLOAD" "" "" ${ARGN})
option(AUTOLOAD_${plugin}_PLUGIN "Automatically load ${plugin} plugin"
${ADD_PLUGIN_AUTOLOAD}
)
add_library(${plugin} SHARED ${ADD_PLUGIN_UNPARSED_ARGUMENTS})
set_target_properties(${plugin} PROPERTIES PREFIX "")
target_link_libraries(${plugin} PUBLIC mc_rtc::mc_control)
install(
Expand All @@ -273,10 +276,20 @@ macro(add_plugin plugin)
)
set(plugin_CFG "${CMAKE_CURRENT_SOURCE_DIR}/etc/${plugin}.yaml")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/stage/autoload/${plugin}.yaml" "${plugin}")
set(AUTOLOAD_DESTINATION "${MC_PLUGINS_RUNTIME_INSTALL_PREFIX}/autoload/")
if(AUTOLOAD_${plugin}_PLUGIN)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/stage/autoload/${plugin}.yaml"
DESTINATION "${MC_PLUGINS_RUNTIME_INSTALL_PREFIX}/autoload/"
)
else()
set(AUTOLOAD_DESTINATION "${AUTOLOAD_DESTINATION}/${plugin}.yaml")
install(
CODE "
if(EXISTS \"${AUTOLOAD_DESTINATION}\")
message(STATUS \"Removing: ${AUTOLOAD_DESTINATION}\")
file(REMOVE \"${AUTOLOAD_DESTINATION}\")
endif()"
)
endif()
endmacro()

Expand Down

0 comments on commit 4c0c47b

Please sign in to comment.