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

Merge f60d49d91b0b58a2427a082e3e9ef08db8d8398d into 69e0372cf0d3796e84ce9a09aff1d74496f68720

This commit is contained in:
Alex Moriarty 2023-06-16 17:12:39 -07:00 committed by GitHub
commit 470d12a783
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 33 deletions

View File

@ -1,31 +1,18 @@
cmake_minimum_required(VERSION 2.8.3) cmake_minimum_required(VERSION 3.16)
project(serial)
# Find catkin # General setup
find_package(catkin REQUIRED) project(serial
VERSION 1.2.1
LANGUAGES CXX
DESCRIPTION "Cross-platform, Serial Port library written in C++"
HOMEPAGE_URL "http://wjwwood.io/serial/"
)
if(APPLE) if(APPLE)
find_library(IOKIT_LIBRARY IOKit) find_library(IOKIT_LIBRARY IOKit)
find_library(FOUNDATION_LIBRARY Foundation) find_library(FOUNDATION_LIBRARY Foundation)
endif() 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()
## Sources ## Sources
set(serial_SRCS set(serial_SRCS
src/serial.cc src/serial.cc
@ -47,7 +34,23 @@ else()
endif() endif()
## Add serial library ## Add serial library
set(serial_HEADERS
include/serial/serial.h
include/serial/v8stdint.h
)
# Build, link and install main library
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
add_library(${PROJECT_NAME} ${serial_SRCS}) add_library(${PROJECT_NAME} ${serial_SRCS})
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
PUBLIC_HEADER "${serial_HEADERS}"
)
target_include_directories(${PROJECT_NAME} PUBLIC include)
if(APPLE) if(APPLE)
target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY}) target_link_libraries(${PROJECT_NAME} ${FOUNDATION_LIBRARY} ${IOKIT_LIBRARY})
elseif(UNIX) elseif(UNIX)
@ -66,16 +69,27 @@ include_directories(include)
## Install executable ## Install executable
install(TARGETS ${PROJECT_NAME} install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} ARCHIVE DESTINATION lib
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION lib
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}
) )
## Install headers ## Install headers
install(FILES include/serial/serial.h include/serial/v8stdint.h install(FILES include/serial/serial.h include/serial/v8stdint.h
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial) DESTINATION include/serial)
## Install CMake config
install(FILES cmake/serialConfig.cmake
DESTINATION share/serial/cmake)
## Install package.xml
install(FILES package.xml
DESTINATION share/serial)
## Tests ## Tests
if(CATKIN_ENABLE_TESTING) include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()

View File

@ -56,7 +56,7 @@ test:
@mkdir -p build @mkdir -p build
cd build && cmake $(CMAKE_FLAGS) .. cd build && cmake $(CMAKE_FLAGS) ..
ifneq ($(MAKE),) ifneq ($(MAKE),)
cd build && $(MAKE) run_tests cd build && $(MAKE) all test
else else
cd build && make run_tests cd build && make all test
endif endif

3
cmake/serialConfig.cmake Normal file
View File

@ -0,0 +1,3 @@
get_filename_component(SERIAL_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(SERIAL_INCLUDE_DIRS "${SERIAL_CMAKE_DIR}/../../../include")
find_library(SERIAL_LIBRARIES serial PATHS ${SERIAL_CMAKE_DIR}/../../../lib/serial)

View File

@ -19,6 +19,13 @@
<author email="wjwwood@gmail.com">William Woodall</author> <author email="wjwwood@gmail.com">William Woodall</author>
<author email="ash.gti@gmail.com">John Harrison</author> <author email="ash.gti@gmail.com">John Harrison</author>
<buildtool_depend>catkin</buildtool_depend> <buildtool_depend>cmake</buildtool_depend>
<!-- boost is only needed for test/proof_of_concepts which are not enabled by default -->
<!--test_depend>boost</test_depend-->
<test_depend>gtest</test_depend>
<export>
<build_type>cmake</build_type>
</export>
</package> </package>

View File

@ -1,12 +1,18 @@
if(UNIX) if(UNIX)
catkin_add_gtest(${PROJECT_NAME}-test unix_serial_tests.cc) find_package(GTest REQUIRED)
target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
add_executable(${PROJECT_NAME}-test unix_serial_tests.cc)
target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} GTest::GTest)
if(NOT APPLE) if(NOT APPLE)
target_link_libraries(${PROJECT_NAME}-test util) target_link_libraries(${PROJECT_NAME}-test util)
endif() endif()
add_test("${PROJECT_NAME}-test-gtest" ${PROJECT_NAME}-test)
if(NOT APPLE) # these tests are unreliable on macOS if(NOT APPLE) # these tests are unreliable on macOS
catkin_add_gtest(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc) add_executable(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc)
target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME}) target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME} GTest::GTest)
add_test("${PROJECT_NAME}-test-timer-gtest" ${PROJECT_NAME}-test-timer)
endif() endif()
# Boost is only required for tests/proof_of_concepts which are not enabled by default
# find_package(Boost REQUIRED)
endif() endif()