From 0a8f9806af7b22f0ebe62b0d33b1a4ea03878dbe Mon Sep 17 00:00:00 2001 From: Thomas Moulard <thomas.moulard@gmail.com> Date: Mon, 14 Nov 2011 16:18:42 +0100 Subject: [PATCH] Share node handle between modules. --- CMakeLists.txt | 48 +++++++++++++++++----------------------------- src/ros_export.cpp | 12 +----------- src/ros_import.cpp | 12 +----------- 3 files changed, 20 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4047ae5..b60760d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,71 +3,59 @@ include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake) include(FindPkgConfig) -# Set the build type. Options are: -# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage -# Debug : w/ debug symbols, w/o optimization -# Release : w/o debug symbols, w/ optimization -# RelWithDebInfo : w/ debug symbols, w/ optimization -# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries -#set(ROS_BUILD_TYPE RelWithDebInfo) +set(ROS_BUILD_TYPE RelWithDebInfo) rosbuild_init() -#set the default path for built executables to the "bin" directory set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) -#set the default path for built libraries to the "lib" directory set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) -#uncomment if you have defined messages rosbuild_genmsg() -#uncomment if you have defined services -#rosbuild_gensrv() rosbuild_add_boost_directories() -#common commands for building c++ executables and libraries -#rosbuild_add_library(${PROJECT_NAME} src/example.cpp) -#target_link_libraries(${PROJECT_NAME} another_library) -#rosbuild_add_boost_directories() -#rosbuild_link_boost(${PROJECT_NAME} thread) -#rosbuild_add_executable(example examples/example.cpp) -#target_link_libraries(example ${PROJECT_NAME}) - pkg_check_modules(JRL_MAL REQUIRED jrl-mal) pkg_check_modules(DYNAMIC_GRAPH REQUIRED dynamic-graph) pkg_check_modules(SOT_CORE REQUIRED sot-core) -rosbuild_add_library(ros_import - src/sot_to_ros.cpp - src/ros_import.cpp src/ros_import.hh src/converter.hh src/sot_to_ros.hh) +rosbuild_add_library(ros_bridge + src/converter.hh + src/ros_init.hh src/ros_init.cpp + src/sot_to_ros.hh src/sot_to_ros.cpp + ) + +rosbuild_add_library(ros_import src/ros_import.cpp src/ros_import.hh) rosbuild_add_compile_flags(ros_import ${JRL_MAL_CFLAGS} ${DYNAMIC_GRAPH_CFLAGS} ${SOT_CORE_CFLAGS}) rosbuild_add_link_flags(ros_import ${JRL_MAL_LDFLAGS} ${DYNAMIC_GRAPH_LDFLAGS} ${SOT_CORE_LDFLAGS}) +target_link_libraries(ros_import ros_bridge) target_link_libraries(ros_import ${JRL_MAL_LIBRARIES} ${DYNAMIC_GRAPH_LIBRARIES} ${SOT_CORE_LIBRARIES}) -rosbuild_add_library(ros_export - src/sot_to_ros.cpp - src/ros_export.cpp src/ros_export.hh src/converter.hh src/sot_to_ros.hh) +rosbuild_add_library(ros_export src/ros_export.cpp src/ros_export.hh) rosbuild_add_compile_flags(ros_export ${JRL_MAL_CFLAGS} ${DYNAMIC_GRAPH_CFLAGS} ${SOT_CORE_CFLAGS}) rosbuild_add_link_flags(ros_export ${JRL_MAL_LDFLAGS} ${DYNAMIC_GRAPH_LDFLAGS} ${SOT_CORE_LDFLAGS}) +target_link_libraries(ros_export ros_bridge) target_link_libraries(ros_export ${JRL_MAL_LIBRARIES} ${DYNAMIC_GRAPH_LIBRARIES} ${SOT_CORE_LIBRARIES}) rosbuild_add_library(ros_joint_state - src/ros_joint_state.cpp src/ros_joint_state.hh src/converter.hh src/sot_to_ros.hh) -rosbuild_add_compile_flags(ros_joint_state ${JRL_MAL_CFLAGS} ${DYNAMIC_GRAPH_CFLAGS} + src/ros_joint_state.cpp src/ros_joint_state) +rosbuild_add_compile_flags(ros_joint_state + ${JRL_MAL_CFLAGS} ${DYNAMIC_GRAPH_CFLAGS} ${SOT_CORE_CFLAGS}) -rosbuild_add_link_flags(ros_joint_state ${JRL_MAL_LDFLAGS} ${DYNAMIC_GRAPH_LDFLAGS} - ${SOT_CORE_LDFLAGS}) +rosbuild_add_link_flags(ros_joint_state ${JRL_MAL_LDFLAGS} + ${DYNAMIC_GRAPH_LDFLAGS} ${SOT_CORE_LDFLAGS}) +target_link_libraries(ros_joint_state ros_bridge) target_link_libraries(ros_joint_state ${JRL_MAL_LIBRARIES} ${DYNAMIC_GRAPH_LIBRARIES} ${SOT_CORE_LIBRARIES}) +INSTALL(TARGETS ros_bridge DESTINATION lib) INSTALL(TARGETS ros_import DESTINATION lib) INSTALL(TARGETS ros_export DESTINATION lib) INSTALL(TARGETS ros_joint_state DESTINATION lib) diff --git a/src/ros_export.cpp b/src/ros_export.cpp index f5f6e53..3f86275 100644 --- a/src/ros_export.cpp +++ b/src/ros_export.cpp @@ -9,6 +9,7 @@ #include <dynamic-graph/factory.h> +#include "ros_init.hh" #include "ros_export.hh" namespace dynamicgraph @@ -112,17 +113,6 @@ namespace dynamicgraph } // end of errorEstimator. } // end of namespace command. - - const char* rosInit() - { - int argc = 1; - char* arg0 = strdup("ros_export"); - char* argv[] = {arg0, 0}; - ros::init(argc, argv, "ros_export"); - free (arg0); - return "dynamic_graph"; - } - RosExport::RosExport (const std::string& n) : dynamicgraph::Entity(n), nh_ (rosInit ()), diff --git a/src/ros_import.cpp b/src/ros_import.cpp index 556c69c..1a8af28 100644 --- a/src/ros_import.cpp +++ b/src/ros_import.cpp @@ -13,6 +13,7 @@ #include <dynamic-graph/factory.h> #include <dynamic-graph/command.h> +#include "ros_init.hh" #include "ros_import.hh" namespace dynamicgraph @@ -115,17 +116,6 @@ namespace dynamicgraph } // end of errorEstimator. } // end of namespace command. - - const char* rosInit() - { - int argc = 1; - char* arg0 = strdup("ros_import"); - char* argv[] = {arg0, 0}; - ros::init(argc, argv, "ros_import"); - free (arg0); - return "dynamic_graph"; - } - RosImport::RosImport (const std::string& n) : dynamicgraph::Entity(n), nh_ (rosInit ()), -- GitLab