From 060aa17f56af21b8eb31c711ded701b1aaea384e Mon Sep 17 00:00:00 2001 From: Brian Fjeldstad Date: Thu, 30 Nov 2017 10:32:22 -0800 Subject: [PATCH 1/3] Make message_events build for ros2 (on windows 10) --- cpp_common/CMakeLists.txt | 27 +++++---- cpp_common/package.xml | 14 ++--- cpp_common/src/header.cpp | 8 +++ roscpp_core/AMENT_IGNORE | 0 roscpp_serialization/AMENT_IGNORE | 0 roscpp_traits/CMakeLists.txt | 14 +++-- roscpp_traits/include/ros/message_event.h | 69 ++++++++++------------- roscpp_traits/package.xml | 15 +++-- rostime/CMakeLists.txt | 45 ++++++--------- rostime/package.xml | 12 ++-- 10 files changed, 97 insertions(+), 107 deletions(-) create mode 100644 roscpp_core/AMENT_IGNORE create mode 100644 roscpp_serialization/AMENT_IGNORE diff --git a/cpp_common/CMakeLists.txt b/cpp_common/CMakeLists.txt index 5e83800e..4395d3a6 100644 --- a/cpp_common/CMakeLists.txt +++ b/cpp_common/CMakeLists.txt @@ -1,19 +1,15 @@ -cmake_minimum_required(VERSION 2.8.3) +cmake_minimum_required(VERSION 3.5) project(cpp_common) -find_package(Boost REQUIRED COMPONENTS system thread) -find_package(console_bridge REQUIRED) -find_package(catkin REQUIRED) -catkin_package( - DEPENDS Boost console_bridge - INCLUDE_DIRS include - LIBRARIES ${PROJECT_NAME}) +find_package(ament_cmake REQUIRED) include(CheckIncludeFile) include(CheckFunctionExists) include(CheckCXXSourceCompiles) -include_directories(include ${Boost_INCLUDE_DIRS} ${console_bridge_INCLUDE_DIRS}) +add_definitions(-DROS2) + +include_directories(include $ENV{Boost_Root}) # execinfo.h is needed for backtrace on glibc systems CHECK_INCLUDE_FILE(execinfo.h HAVE_EXECINFO_H) @@ -32,13 +28,16 @@ if(HAVE_GLIBC_BACKTRACE) endif(HAVE_GLIBC_BACKTRACE) add_library(${PROJECT_NAME} src/debug.cpp src/header.cpp) -target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES} ${console_bridge_LIBRARIES}) +target_link_libraries(${PROJECT_NAME}) + +ament_export_include_directories(include) +ament_package() install(TARGETS ${PROJECT_NAME} - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin) install(DIRECTORY include/ - DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION} + DESTINATION include FILES_MATCHING PATTERN "*.h") diff --git a/cpp_common/package.xml b/cpp_common/package.xml index 3a828308..b7625b1d 100644 --- a/cpp_common/package.xml +++ b/cpp_common/package.xml @@ -1,4 +1,5 @@ - + + cpp_common 0.6.7 @@ -15,11 +16,8 @@ http://www.ros.org/wiki/cpp_common John Faust - catkin - - boost - libconsole-bridge-dev - - boost - libconsole-bridge-dev + ament_cmake + + ament_cmake + diff --git a/cpp_common/src/header.cpp b/cpp_common/src/header.cpp index ebd46ed1..823dbb4e 100644 --- a/cpp_common/src/header.cpp +++ b/cpp_common/src/header.cpp @@ -34,7 +34,9 @@ #include "ros/header.h" +#ifndef ROS2 #include "console_bridge/console.h" +#endif // !ROS2 #include @@ -46,6 +48,12 @@ #define SROS_DESERIALIZE_PRIMITIVE(ptr, data) { memcpy(&data, ptr, sizeof(data)); ptr += sizeof(data); } #define SROS_DESERIALIZE_BUFFER(ptr, data, data_size) { if (data_size > 0) { memcpy(data, ptr, data_size); ptr += data_size; } } +#ifdef ROS2 +#ifndef logError + #define logError(...) +#endif +#endif // ROS2 + // Remove this when no longer supporting platforms with libconsole-bridge-dev < 0.3.0, // in particular Debian Jessie: https://packages.debian.org/jessie/libconsole-bridge-dev #ifndef CONSOLE_BRIDGE_logError diff --git a/roscpp_core/AMENT_IGNORE b/roscpp_core/AMENT_IGNORE new file mode 100644 index 00000000..e69de29b diff --git a/roscpp_serialization/AMENT_IGNORE b/roscpp_serialization/AMENT_IGNORE new file mode 100644 index 00000000..e69de29b diff --git a/roscpp_traits/CMakeLists.txt b/roscpp_traits/CMakeLists.txt index b6bc5f88..1d5c109c 100644 --- a/roscpp_traits/CMakeLists.txt +++ b/roscpp_traits/CMakeLists.txt @@ -1,10 +1,12 @@ -cmake_minimum_required(VERSION 2.8.3) +cmake_minimum_required(VERSION 3.5) project(roscpp_traits) -find_package(catkin REQUIRED) -catkin_package( - INCLUDE_DIRS include - CATKIN_DEPENDS cpp_common rostime) +find_package(ament_cmake REQUIRED) +find_package(cpp_common REQUIRED) +find_package(rostime REQUIRED) + +ament_export_include_directories(include) +ament_package() install(DIRECTORY include/ - DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION} + DESTINATION include FILES_MATCHING PATTERN "*.h") diff --git a/roscpp_traits/include/ros/message_event.h b/roscpp_traits/include/ros/message_event.h index bbcafbfb..daf99335 100644 --- a/roscpp_traits/include/ros/message_event.h +++ b/roscpp_traits/include/ros/message_event.h @@ -33,14 +33,7 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include namespace ros { @@ -48,20 +41,20 @@ namespace ros template struct DefaultMessageCreator { - boost::shared_ptr operator()() + std::shared_ptr operator()() { - return boost::make_shared(); + return std::make_shared(); } }; template -ROS_DEPRECATED inline boost::shared_ptr defaultMessageCreateFunction() +ROS_DEPRECATED inline std::shared_ptr defaultMessageCreateFunction() { return DefaultMessageCreator()(); } /** - * \brief Event type for subscriptions, const ros::MessageEvent& can be used in your callback instead of const boost::shared_ptr& + * \brief Event type for subscriptions, const ros::MessageEvent& can be used in your callback instead of const std::shared_ptr& * * Useful if you need to retrieve meta-data about the message, such as the full connection header, or the publisher's node name */ @@ -69,11 +62,13 @@ template class MessageEvent { public: - typedef typename boost::add_const::type ConstMessage; - typedef typename boost::remove_const::type Message; - typedef boost::shared_ptr MessagePtr; - typedef boost::shared_ptr ConstMessagePtr; - typedef boost::function CreateFunction; + typedef typename std::add_const::type ConstMessage; + typedef typename std::remove_const::type Message; + typedef std::shared_ptr MessagePtr; + typedef std::shared_ptr ConstMessagePtr; + typedef std::function CreateFunction; + + typedef std::shared_ptr StdConstMessagePtr; MessageEvent() : nonconst_need_copy_(true) @@ -103,7 +98,7 @@ class MessageEvent MessageEvent(const MessageEvent& rhs, const CreateFunction& create) { - init(boost::const_pointer_cast(boost::static_pointer_cast(rhs.getMessage())), rhs.getConnectionHeaderPtr(), rhs.getReceiptTime(), rhs.nonConstWillCopy(), create); + init(std::const_pointer_cast(std::static_pointer_cast(rhs.getMessage())), rhs.getConnectionHeaderPtr(), rhs.getReceiptTime(), rhs.nonConstWillCopy(), create); } /** @@ -111,25 +106,25 @@ class MessageEvent */ MessageEvent(const ConstMessagePtr& message) { - init(message, boost::shared_ptr(), ros::Time::now(), true, ros::DefaultMessageCreator()); + init(message, std::shared_ptr(), ros::Time::now(), true, ros::DefaultMessageCreator()); } - MessageEvent(const ConstMessagePtr& message, const boost::shared_ptr& connection_header, ros::Time receipt_time) + MessageEvent(const ConstMessagePtr& message, const std::shared_ptr& connection_header, ros::Time receipt_time) { init(message, connection_header, receipt_time, true, ros::DefaultMessageCreator()); } MessageEvent(const ConstMessagePtr& message, ros::Time receipt_time) { - init(message, boost::shared_ptr(), receipt_time, true, ros::DefaultMessageCreator()); + init(message, std::shared_ptr(), receipt_time, true, ros::DefaultMessageCreator()); } - MessageEvent(const ConstMessagePtr& message, const boost::shared_ptr& connection_header, ros::Time receipt_time, bool nonconst_need_copy, const CreateFunction& create) + MessageEvent(const ConstMessagePtr& message, const std::shared_ptr& connection_header, ros::Time receipt_time, bool nonconst_need_copy, const CreateFunction& create) { init(message, connection_header, receipt_time, nonconst_need_copy, create); } - void init(const ConstMessagePtr& message, const boost::shared_ptr& connection_header, ros::Time receipt_time, bool nonconst_need_copy, const CreateFunction& create) + void init(const ConstMessagePtr& message, const std::shared_ptr& connection_header, ros::Time receipt_time, bool nonconst_need_copy, const CreateFunction& create) { message_ = message; connection_header_ = connection_header; @@ -140,13 +135,13 @@ class MessageEvent void operator=(const MessageEvent& rhs) { - init(boost::static_pointer_cast(rhs.getMessage()), rhs.getConnectionHeaderPtr(), rhs.getReceiptTime(), rhs.nonConstWillCopy(), rhs.getMessageFactory()); + init(std::static_pointer_cast(rhs.getMessage()), rhs.getConnectionHeaderPtr(), rhs.getReceiptTime(), rhs.nonConstWillCopy(), rhs.getMessageFactory()); message_copy_.reset(); } void operator=(const MessageEvent& rhs) { - init(boost::const_pointer_cast(boost::static_pointer_cast(rhs.getMessage())), rhs.getConnectionHeaderPtr(), rhs.getReceiptTime(), rhs.nonConstWillCopy(), rhs.getMessageFactory()); + init(std::const_pointer_cast(std::static_pointer_cast(rhs.getMessage())), rhs.getConnectionHeaderPtr(), rhs.getReceiptTime(), rhs.nonConstWillCopy(), rhs.getMessageFactory()); message_copy_.reset(); } @@ -155,7 +150,7 @@ class MessageEvent * and this event requires it, returns a copy. Note that it caches this copy for later use, so it will * only every make the copy once */ - boost::shared_ptr getMessage() const + std::shared_ptr getMessage() const { return copyMessageIfNecessary(); } @@ -163,12 +158,12 @@ class MessageEvent /** * \brief Retrieve a const version of the message */ - const boost::shared_ptr& getConstMessage() const { return message_; } + const std::shared_ptr& getConstMessage() const { return message_; } /** * \brief Retrieve the connection header */ M_string& getConnectionHeader() const { return *connection_header_; } - const boost::shared_ptr& getConnectionHeaderPtr() const { return connection_header_; } + const std::shared_ptr& getConnectionHeaderPtr() const { return connection_header_; } /** * \brief Returns the name of the node which published this message @@ -181,7 +176,7 @@ class MessageEvent ros::Time getReceiptTime() const { return receipt_time_; } bool nonConstWillCopy() const { return nonconst_need_copy_; } - bool getMessageWillCopy() const { return !boost::is_const::value && nonconst_need_copy_; } + bool getMessageWillCopy() const { return !std::is_const::value && nonconst_need_copy_; } bool operator<(const MessageEvent& rhs) { @@ -211,12 +206,12 @@ class MessageEvent const CreateFunction& getMessageFactory() const { return create_; } private: - template - typename boost::disable_if, boost::shared_ptr >::type copyMessageIfNecessary() const + template + std::shared_ptr copyMessageIfNecessary() const { - if (boost::is_const::value || !nonconst_need_copy_) + if (std::is_const::value || !nonconst_need_copy_) { - return boost::const_pointer_cast(message_); + return std::const_pointer_cast(message_); } if (message_copy_) @@ -231,16 +226,10 @@ class MessageEvent return message_copy_; } - template - typename boost::enable_if, boost::shared_ptr >::type copyMessageIfNecessary() const - { - return boost::const_pointer_cast(message_); - } - ConstMessagePtr message_; // Kind of ugly to make this mutable, but it means we can pass a const MessageEvent to a callback and not worry about other things being modified mutable MessagePtr message_copy_; - boost::shared_ptr connection_header_; + std::shared_ptr connection_header_; ros::Time receipt_time_; bool nonconst_need_copy_; CreateFunction create_; diff --git a/roscpp_traits/package.xml b/roscpp_traits/package.xml index f7454c44..ad2c9e16 100644 --- a/roscpp_traits/package.xml +++ b/roscpp_traits/package.xml @@ -1,4 +1,5 @@ - + + roscpp_traits 0.6.7 @@ -13,8 +14,12 @@ http://ros.org/wiki/roscpp_traits Josh Faust - catkin - - cpp_common - rostime + ament_cmake + cpp_common + rostime + cpp_common + rostime + + ament_cmake + diff --git a/rostime/CMakeLists.txt b/rostime/CMakeLists.txt index 8d742f82..f04531dc 100644 --- a/rostime/CMakeLists.txt +++ b/rostime/CMakeLists.txt @@ -1,44 +1,31 @@ -cmake_minimum_required(VERSION 2.8.3) +cmake_minimum_required(VERSION 3.5) project(rostime) -find_package(catkin REQUIRED COMPONENTS cpp_common) -find_package(Boost REQUIRED COMPONENTS date_time system thread) -catkin_package( - INCLUDE_DIRS include - LIBRARIES ${PROJECT_NAME} - CATKIN_DEPENDS cpp_common - DEPENDS Boost -) +find_package(ament_cmake REQUIRED) +find_package(cpp_common REQUIRED) -include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) +include_directories(include + ${cpp_common_INCLUDE_DIRS} + $ENV{Boost_Root} +) add_library(rostime src/duration.cpp src/rate.cpp src/time.cpp) -target_link_libraries(rostime ${Boost_LIBRARIES}) -if(NOT APPLE) - target_link_libraries(rostime ${RT_LIBRARY}) -endif() +target_link_libraries(rostime) + +ament_export_include_directories(include) +ament_export_libraries(rostime) +ament_package() install(TARGETS rostime - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin) install(DIRECTORY include/ - DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION} + DESTINATION include FILES_MATCHING PATTERN "*.h") -if(CATKIN_ENABLE_TESTING) - catkin_add_gtest(${PROJECT_NAME}-test_duration test/duration.cpp) - if(TARGET ${PROJECT_NAME}-test_duration) - target_link_libraries(${PROJECT_NAME}-test_duration ${catkin_LIBRARIES} rostime) - endif() - catkin_add_gtest(${PROJECT_NAME}-test_time test/time.cpp) - if(TARGET ${PROJECT_NAME}-test_time) - set_property(TARGET ${PROJECT_NAME}-test_time APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++11") - target_link_libraries(${PROJECT_NAME}-test_time ${catkin_LIBRARIES} rostime) - endif() -endif() diff --git a/rostime/package.xml b/rostime/package.xml index eb260ccd..bb79ad7c 100644 --- a/rostime/package.xml +++ b/rostime/package.xml @@ -1,4 +1,5 @@ - + + rostime 0.6.7 @@ -10,11 +11,12 @@ http://ros.org/wiki/rostime Josh Faust - catkin + ament_cmake - boost cpp_common + cpp_common - boost - cpp_common + + ament_cmake + From 9f05e7c19514d4b73503e2d85e210e52ed9e7e95 Mon Sep 17 00:00:00 2001 From: Brian Fjeldstad Date: Tue, 9 Jan 2018 11:57:28 -0800 Subject: [PATCH 2/3] use find_package to get Boost dependency and remove ROS2 #define --- cpp_common/CMakeLists.txt | 7 ++++--- cpp_common/src/header.cpp | 8 +------- rostime/CMakeLists.txt | 5 ++++- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cpp_common/CMakeLists.txt b/cpp_common/CMakeLists.txt index 4395d3a6..8e5c8907 100644 --- a/cpp_common/CMakeLists.txt +++ b/cpp_common/CMakeLists.txt @@ -3,13 +3,14 @@ project(cpp_common) find_package(ament_cmake REQUIRED) +set(Boost_USE_STATIC_LIBS ON) +find_package(Boost REQUIRED) + include(CheckIncludeFile) include(CheckFunctionExists) include(CheckCXXSourceCompiles) -add_definitions(-DROS2) - -include_directories(include $ENV{Boost_Root}) +include_directories(include ${Boost_INCLUDE_DIRS}) # execinfo.h is needed for backtrace on glibc systems CHECK_INCLUDE_FILE(execinfo.h HAVE_EXECINFO_H) diff --git a/cpp_common/src/header.cpp b/cpp_common/src/header.cpp index 823dbb4e..9757abe0 100644 --- a/cpp_common/src/header.cpp +++ b/cpp_common/src/header.cpp @@ -34,10 +34,6 @@ #include "ros/header.h" -#ifndef ROS2 -#include "console_bridge/console.h" -#endif // !ROS2 - #include #include @@ -48,11 +44,9 @@ #define SROS_DESERIALIZE_PRIMITIVE(ptr, data) { memcpy(&data, ptr, sizeof(data)); ptr += sizeof(data); } #define SROS_DESERIALIZE_BUFFER(ptr, data, data_size) { if (data_size > 0) { memcpy(data, ptr, data_size); ptr += data_size; } } -#ifdef ROS2 #ifndef logError - #define logError(...) +#define logError(...) #endif -#endif // ROS2 // Remove this when no longer supporting platforms with libconsole-bridge-dev < 0.3.0, // in particular Debian Jessie: https://packages.debian.org/jessie/libconsole-bridge-dev diff --git a/rostime/CMakeLists.txt b/rostime/CMakeLists.txt index f04531dc..ad860d5b 100644 --- a/rostime/CMakeLists.txt +++ b/rostime/CMakeLists.txt @@ -4,9 +4,12 @@ project(rostime) find_package(ament_cmake REQUIRED) find_package(cpp_common REQUIRED) +set(Boost_USE_STATIC_LIBS ON) +find_package(Boost REQUIRED) + include_directories(include ${cpp_common_INCLUDE_DIRS} - $ENV{Boost_Root} + ${Boost_INCLUDE_DIRS} ) add_library(rostime From e45910b32e767aaa0d29a6c44e1bd21cd09f1d5e Mon Sep 17 00:00:00 2001 From: Brian Fjeldstad Date: Tue, 9 Jan 2018 12:03:52 -0800 Subject: [PATCH 3/3] fix merge mistake --- cpp_common/CMakeLists.txt | 2 +- cpp_common/src/header.cpp | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cpp_common/CMakeLists.txt b/cpp_common/CMakeLists.txt index 8e5c8907..d6184add 100644 --- a/cpp_common/CMakeLists.txt +++ b/cpp_common/CMakeLists.txt @@ -4,7 +4,7 @@ project(cpp_common) find_package(ament_cmake REQUIRED) set(Boost_USE_STATIC_LIBS ON) -find_package(Boost REQUIRED) +find_package(Boost REQUIRED COMPONENTS system thread) include(CheckIncludeFile) include(CheckFunctionExists) diff --git a/cpp_common/src/header.cpp b/cpp_common/src/header.cpp index 9757abe0..d9958202 100644 --- a/cpp_common/src/header.cpp +++ b/cpp_common/src/header.cpp @@ -17,7 +17,7 @@ * * Neither the name of Willow Garage, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. - * + *90 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -48,11 +48,9 @@ #define logError(...) #endif -// Remove this when no longer supporting platforms with libconsole-bridge-dev < 0.3.0, -// in particular Debian Jessie: https://packages.debian.org/jessie/libconsole-bridge-dev +// TODO: enable console bridge #ifndef CONSOLE_BRIDGE_logError -# define CONSOLE_BRIDGE_logError(fmt, ...) \ - console_bridge::log(__FILE__, __LINE__, console_bridge::CONSOLE_BRIDGE_LOG_ERROR, fmt, ##__VA_ARGS__) + #define CONSOLE_BRIDGE_logError logError #endif using namespace std;