1
0
mirror of https://github.com/wjwwood/serial.git synced 2026-01-22 19:54:57 +08:00

Update CMakeList for ROS2

This commit is contained in:
JADC362 2021-04-24 12:15:15 -05:00
parent 683e12d2f6
commit 64fad1f7c9
2 changed files with 46 additions and 24 deletions

View File

@ -1,8 +1,24 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.5)
project(serial)
## C++ compiler sets
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# Find catkin
find_package(catkin REQUIRED)
find_package(ament_cmake REQUIRED)
if(APPLE)
find_library(IOKIT_LIBRARY IOKit)
@ -10,20 +26,8 @@ if(APPLE)
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
)
find_library(pthread_LIBRARY pthread)
find_library(rt_LIBRARY rt)
endif()
## Sources
@ -47,7 +51,7 @@ else()
endif()
## Add serial library
add_library(${PROJECT_NAME} ${serial_SRCS})
add_library(${PROJECT_NAME} SHARED ${serial_SRCS})
if(APPLE)
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX)
@ -58,23 +62,37 @@ endif()
## Uncomment for example
add_executable(serial_example examples/serial_example.cc)
add_dependencies(serial_example ${PROJECT_NAME})
#ament_target_dependencies(serial_example ${PROJECT_NAME})
target_link_libraries(serial_example ${PROJECT_NAME})
## Include headers
include_directories(include)
## Install executable
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
## Install headers
install(FILES include/serial/serial.h include/serial/v8stdint.h
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial)
DESTINATION share/${PROJECT_NAME})
# Install executable
install(TARGETS serial_example
RUNTIME DESTINATION lib/${PROJECT_NAME}
)
## Tests
if(CATKIN_ENABLE_TESTING)
add_subdirectory(tests)
endif()
#if(BUILD_TESTING)
# add_subdirectory(tests)
#endif()
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
ament_package()

View File

@ -23,4 +23,8 @@
<test_depend>boost</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>