Skip to content

Commit

Permalink
Add compatibility for ROS2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarath18 committed Sep 2, 2019
1 parent ef16fa5 commit 625f35b
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 26 deletions.
98 changes: 74 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

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}
)
)

ament_export_interfaces(
export_${PROJECT_NAME}
)

ament_export_libraries(
${PROJECT_NAME}
)

ament_package()

endif()

14 changes: 12 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<package format="2">
<package format="3">
<name>socket_can</name>
<version>0.0.0</version>
<description>The socket_can package</description>
Expand All @@ -8,5 +8,15 @@

<license>MIT</license>

<buildtool_depend>catkin</buildtool_depend>
<!-- ROS1 -->
<buildtool_depend condition="$ROS_VERSION == 1">catkin</buildtool_depend>

<!-- ROS2 -->
<buildtool_depend condition="$ROS_VERSION == 2">ament_cmake</buildtool_depend>

<export>
<build_type condition="$ROS_VERSION == 1">catkin</build_type>
<build_type condition="$ROS_VERSION == 2">ament_cmake</build_type>
</export>

</package>

0 comments on commit 625f35b

Please sign in to comment.