Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to ROS 2 #209

Open
wants to merge 8 commits into
base: ros2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 43 additions & 57 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,80 +1,66 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.5)
project(serial)

# Find catkin
find_package(catkin REQUIRED)
find_package(ament_cmake REQUIRED)

if(APPLE)
find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation)
endif()

if(UNIX AND NOT APPLE)
# If Linux, add rt and pthread
set(rt_LIBRARIES rt)
set(pthread_LIBRARIES pthread)
catkin_package(
LIBRARIES ${PROJECT_NAME}
INCLUDE_DIRS include
DEPENDS rt pthread
)
else()
# Otherwise normal call
catkin_package(
LIBRARIES ${PROJECT_NAME}
INCLUDE_DIRS include
)
endif()
ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})

## Sources
set(serial_SRCS
## Add serial library
add_library(${PROJECT_NAME}
src/serial.cc
include/serial/serial.h
include/serial/v8stdint.h
)
if(APPLE)
# If OSX
list(APPEND serial_SRCS src/impl/unix.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
elseif(UNIX)
# If unix
list(APPEND serial_SRCS src/impl/unix.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_linux.cc)
else()
# If windows
list(APPEND serial_SRCS src/impl/win.cc)
list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
endif()

## Add serial library
add_library(${PROJECT_NAME} ${serial_SRCS})
if(APPLE)
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
target_link_libraries(${PROJECT_NAME} rt pthread)
else()
target_link_libraries(${PROJECT_NAME} setupapi)
if(APPLE) # macOS
find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation)
target_sources(${PROJECT_NAME} PRIVATE
src/impl/unix.cc
src/impl/list_ports/list_ports_osx.cc
)
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX) # .*nix
target_sources(${PROJECT_NAME} PRIVATE
src/impl/unix.cc
src/impl/list_ports/list_ports_linux.cc
)
target_link_libraries(${PROJECT_NAME} rt pthread)
elseif(WIN32) # Windows
target_sources(${PROJECT_NAME} PRIVATE
src/impl/win.cc
src/impl/list_ports/list_ports_win.cc
)
target_link_libraries(${PROJECT_NAME} setupapi)
ament_export_libraries(setupapi)
endif()

## Uncomment for example
add_executable(serial_example examples/serial_example.cc)
add_dependencies(serial_example ${PROJECT_NAME})
target_link_libraries(serial_example ${PROJECT_NAME})

## Include headers
include_directories(include)
target_include_directories(${PROJECT_NAME} PRIVATE include)

## Uncomment for example
# add_executable(serial_example examples/serial_example.cc)
# add_dependencies(serial_example ${PROJECT_NAME})
# target_link_libraries(serial_example ${PROJECT_NAME})


## Install executable
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)

## Install headers
install(FILES include/serial/serial.h include/serial/v8stdint.h
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial)
DESTINATION include/serial
)

## Tests
if(CATKIN_ENABLE_TESTING)
add_subdirectory(tests)
endif()
#if(BUILD_TESTING)
# add_subdirectory(tests)
#endif()

ament_package()
6 changes: 5 additions & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
<author email="[email protected]">William Woodall</author>
<author email="[email protected]">John Harrison</author>

<buildtool_depend>catkin</buildtool_depend>
<buildtool_depend>ament_cmake</buildtool_depend>

<test_depend>boost</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>

</package>