From 625f35bb795b6d57857490714a4ae08276b55e20 Mon Sep 17 00:00:00 2001 From: Sarathkrishnan Ramesh Date: Mon, 2 Sep 2019 23:39:25 +0530 Subject: [PATCH] Add compatibility for ROS2 --- CMakeLists.txt | 98 +++++++++++++++++++++++++++++++++++++------------- package.xml | 14 ++++++-- 2 files changed, 86 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d389073..967b8cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,77 @@ -cmake_minimum_required(VERSION 3.5) -project(socket_can) +if($ENV{ROS_VERSION} EQUAL 1) + cmake_minimum_required(VERSION 3.5) + project(socket_can) -find_package(catkin REQUIRED) + find_package(catkin REQUIRED) -catkin_package( - INCLUDE_DIRS + catkin_package( + INCLUDE_DIRS + include + LIBRARIES + socket_can + ) + + include_directories( + include + ) + + add_library( + socket_can + src/socket_can.cpp + ) + + install( + TARGETS socket_can + ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + RUNTIME DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} + ) +else() + cmake_minimum_required(VERSION 3.5) + project(socket_can) + + set(CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_FLAGS}") + + add_compile_options(-std=c++14) + + find_package(ament_cmake REQUIRED) + + add_library(${PROJECT_NAME} STATIC + src/${PROJECT_NAME}.cpp + ) + + target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ + ) + + install( + DIRECTORY include/ + DESTINATION include + ) + + install( + TARGETS ${PROJECT_NAME} + EXPORT export_${PROJECT_NAME} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin + DESTINATION lib/${PROJECT_NAME} + ) + + ament_export_include_directories( include - LIBRARIES - socket_can -) - -include_directories( - include -) - -add_library( - socket_can - src/socket_can.cpp -) - -install( - TARGETS socket_can - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - RUNTIME DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} -) \ No newline at end of file + ) + + ament_export_interfaces( + export_${PROJECT_NAME} + ) + + ament_export_libraries( + ${PROJECT_NAME} + ) + + ament_package() + +endif() + diff --git a/package.xml b/package.xml index daa5fad..b0495e6 100644 --- a/package.xml +++ b/package.xml @@ -1,5 +1,5 @@ - + socket_can 0.0.0 The socket_can package @@ -8,5 +8,15 @@ MIT - catkin + + catkin + + + ament_cmake + + + catkin + ament_cmake + +