mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-23 04:04:54 +08:00
Merge ad3897cc8f648c00edebfaefde8f76320be91112 into 683e12d2f6a26c80bfa07f276845be618237ae5b
This commit is contained in:
commit
1c156829ea
119
CMakeLists.txt
119
CMakeLists.txt
@ -1,8 +1,22 @@
|
||||
cmake_minimum_required(VERSION 2.8.3)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(serial)
|
||||
|
||||
# Find catkin
|
||||
find_package(catkin REQUIRED)
|
||||
# Default to C99
|
||||
if(NOT CMAKE_C_STANDARD)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
endif()
|
||||
|
||||
# Add support for C++11
|
||||
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 -Werror)
|
||||
endif()
|
||||
|
||||
# find dependencies
|
||||
find_package(ament_cmake REQUIRED)
|
||||
|
||||
if(APPLE)
|
||||
find_library(IOKIT_LIBRARY IOKit)
|
||||
@ -10,44 +24,27 @@ 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
|
||||
)
|
||||
set(RT_LIBRARIES rt)
|
||||
set(PTHREAD_LIBRARIES pthread)
|
||||
endif()
|
||||
|
||||
## Sources
|
||||
set(serial_SRCS
|
||||
src/serial.cc
|
||||
include/serial/serial.h
|
||||
include/serial/v8stdint.h
|
||||
)
|
||||
set(SERIAL_SRCS
|
||||
src/serial.cc)
|
||||
|
||||
if(APPLE)
|
||||
# If OSX
|
||||
list(APPEND serial_SRCS src/impl/unix.cc)
|
||||
list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
|
||||
list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_osx.cc)
|
||||
list(APPEND SERIAL_SRCS src/impl/unix.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)
|
||||
list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_linux.cc)
|
||||
list(APPEND SERIAL_SRCS src/impl/unix.cc)
|
||||
else()
|
||||
# If windows
|
||||
list(APPEND serial_SRCS src/impl/win.cc)
|
||||
list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
|
||||
list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_win.cc)
|
||||
list(APPEND SERIAL_SRCS src/impl/win.cc)
|
||||
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)
|
||||
@ -56,25 +53,45 @@ else()
|
||||
target_link_libraries(${PROJECT_NAME} 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})
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
|
||||
## Include headers
|
||||
include_directories(include)
|
||||
install(
|
||||
DIRECTORY include/
|
||||
DESTINATION include)
|
||||
|
||||
## Install executable
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
||||
)
|
||||
install(
|
||||
TARGETS ${PROJECT_NAME}
|
||||
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)
|
||||
ament_export_include_directories(include)
|
||||
ament_export_libraries(${PROJECT_NAME})
|
||||
|
||||
## Tests
|
||||
if(CATKIN_ENABLE_TESTING)
|
||||
add_subdirectory(tests)
|
||||
if(BUILD_TESTING)
|
||||
find_package(ament_cmake_gmock REQUIRED)
|
||||
|
||||
if(UNIX)
|
||||
ament_add_gmock(${PROJECT_NAME}-test
|
||||
tests/unix_serial_tests.cc)
|
||||
|
||||
if(TARGET ${PROJECT_NAME}-test)
|
||||
target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} ${Boost_LIBRARIES})
|
||||
|
||||
if(NOT APPLE)
|
||||
target_link_libraries(${PROJECT_NAME}-test util)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT APPLE) # these tests are unreliable on macOS
|
||||
ament_add_gmock(${PROJECT_NAME}-test-timer
|
||||
tests/unit/unix_timer_tests.cc)
|
||||
target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
ament_package()
|
||||
|
||||
11
package.xml
11
package.xml
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0"?>
|
||||
<package>
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<package format="3">
|
||||
<name>serial</name>
|
||||
<version>1.2.1</version>
|
||||
<description>
|
||||
@ -19,8 +19,11 @@
|
||||
<author email="wjwwood@gmail.com">William Woodall</author>
|
||||
<author email="ash.gti@gmail.com">John Harrison</author>
|
||||
|
||||
<buildtool_depend>catkin</buildtool_depend>
|
||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||
|
||||
<test_depend>boost</test_depend>
|
||||
<test_depend>ament_cmake_gmock</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_cmake</build_type>
|
||||
</export>
|
||||
</package>
|
||||
|
||||
@ -54,16 +54,16 @@ glob(const vector<string>& patterns)
|
||||
|
||||
glob_t glob_results;
|
||||
|
||||
int glob_retval = glob(patterns[0].c_str(), 0, NULL, &glob_results);
|
||||
glob(patterns[0].c_str(), 0, NULL, &glob_results);
|
||||
|
||||
vector<string>::const_iterator iter = patterns.begin();
|
||||
|
||||
while(++iter != patterns.end())
|
||||
{
|
||||
glob_retval = glob(iter->c_str(), GLOB_APPEND, NULL, &glob_results);
|
||||
glob(iter->c_str(), GLOB_APPEND, NULL, &glob_results);
|
||||
}
|
||||
|
||||
for(int path_index = 0; path_index < glob_results.gl_pathc; path_index++)
|
||||
for(unsigned int path_index = 0; path_index < glob_results.gl_pathc; path_index++)
|
||||
{
|
||||
paths_found.push_back(glob_results.gl_pathv[path_index]);
|
||||
}
|
||||
@ -243,7 +243,7 @@ format(const char* format, ...)
|
||||
{
|
||||
done = true;
|
||||
}
|
||||
else if( return_value >= buffer_size_bytes )
|
||||
else if(static_cast<unsigned int>(return_value) >= buffer_size_bytes)
|
||||
{
|
||||
// Realloc and try again.
|
||||
|
||||
|
||||
@ -1,12 +0,0 @@
|
||||
if(UNIX)
|
||||
catkin_add_gtest(${PROJECT_NAME}-test unix_serial_tests.cc)
|
||||
target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME} ${Boost_LIBRARIES})
|
||||
if(NOT APPLE)
|
||||
target_link_libraries(${PROJECT_NAME}-test util)
|
||||
endif()
|
||||
|
||||
if(NOT APPLE) # these tests are unreliable on macOS
|
||||
catkin_add_gtest(${PROJECT_NAME}-test-timer unit/unix_timer_tests.cc)
|
||||
target_link_libraries(${PROJECT_NAME}-test-timer ${PROJECT_NAME})
|
||||
endif()
|
||||
endif()
|
||||
@ -20,8 +20,6 @@ void loop()
|
||||
#include <string>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
// Use FRIEND_TEST... its not as nasty, thats what friends are for
|
||||
// // OMG this is so nasty...
|
||||
// #define private public
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user