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
129
CMakeLists.txt
129
CMakeLists.txt
@ -1,80 +1,97 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.3)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
project(serial)
|
project(serial)
|
||||||
|
|
||||||
# Find catkin
|
# Default to C99
|
||||||
find_package(catkin REQUIRED)
|
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)
|
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(UNIX AND NOT APPLE)
|
||||||
# If Linux, add rt and pthread
|
set(RT_LIBRARIES rt)
|
||||||
set(rt_LIBRARIES rt)
|
set(PTHREAD_LIBRARIES pthread)
|
||||||
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()
|
endif()
|
||||||
|
|
||||||
## Sources
|
set(SERIAL_SRCS
|
||||||
set(serial_SRCS
|
src/serial.cc)
|
||||||
src/serial.cc
|
|
||||||
include/serial/serial.h
|
|
||||||
include/serial/v8stdint.h
|
|
||||||
)
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
# If OSX
|
list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_osx.cc)
|
||||||
list(APPEND serial_SRCS src/impl/unix.cc)
|
list(APPEND SERIAL_SRCS src/impl/unix.cc)
|
||||||
list(APPEND serial_SRCS src/impl/list_ports/list_ports_osx.cc)
|
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
# If unix
|
list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_linux.cc)
|
||||||
list(APPEND serial_SRCS src/impl/unix.cc)
|
list(APPEND SERIAL_SRCS src/impl/unix.cc)
|
||||||
list(APPEND serial_SRCS src/impl/list_ports/list_ports_linux.cc)
|
|
||||||
else()
|
else()
|
||||||
# If windows
|
list(APPEND SERIAL_SRCS src/impl/list_ports/list_ports_win.cc)
|
||||||
list(APPEND serial_SRCS src/impl/win.cc)
|
list(APPEND SERIAL_SRCS src/impl/win.cc)
|
||||||
list(APPEND serial_SRCS src/impl/list_ports/list_ports_win.cc)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
## Add serial library
|
add_library(${PROJECT_NAME} SHARED
|
||||||
add_library(${PROJECT_NAME} ${serial_SRCS})
|
${SERIAL_SRCS})
|
||||||
|
|
||||||
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)
|
||||||
target_link_libraries(${PROJECT_NAME} rt pthread)
|
target_link_libraries(${PROJECT_NAME} rt pthread)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(${PROJECT_NAME} setupapi)
|
target_link_libraries(${PROJECT_NAME} setupapi)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
## Uncomment for example
|
target_include_directories(${PROJECT_NAME}
|
||||||
add_executable(serial_example examples/serial_example.cc)
|
PUBLIC
|
||||||
add_dependencies(serial_example ${PROJECT_NAME})
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
target_link_libraries(serial_example ${PROJECT_NAME})
|
$<INSTALL_INTERFACE:include>)
|
||||||
|
|
||||||
## Include headers
|
install(
|
||||||
include_directories(include)
|
DIRECTORY include/
|
||||||
|
DESTINATION include)
|
||||||
|
|
||||||
## Install executable
|
install(
|
||||||
install(TARGETS ${PROJECT_NAME}
|
TARGETS ${PROJECT_NAME}
|
||||||
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
ARCHIVE DESTINATION lib
|
||||||
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
LIBRARY DESTINATION lib
|
||||||
)
|
RUNTIME DESTINATION bin)
|
||||||
|
|
||||||
## Install headers
|
ament_export_include_directories(include)
|
||||||
install(FILES include/serial/serial.h include/serial/v8stdint.h
|
ament_export_libraries(${PROJECT_NAME})
|
||||||
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/serial)
|
|
||||||
|
|
||||||
## Tests
|
if(BUILD_TESTING)
|
||||||
if(CATKIN_ENABLE_TESTING)
|
find_package(ament_cmake_gmock REQUIRED)
|
||||||
add_subdirectory(tests)
|
|
||||||
|
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()
|
endif()
|
||||||
|
|
||||||
|
ament_package()
|
||||||
|
|||||||
11
package.xml
11
package.xml
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
<package>
|
<package format="3">
|
||||||
<name>serial</name>
|
<name>serial</name>
|
||||||
<version>1.2.1</version>
|
<version>1.2.1</version>
|
||||||
<description>
|
<description>
|
||||||
@ -19,8 +19,11 @@
|
|||||||
<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>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>
|
</package>
|
||||||
|
|||||||
@ -54,16 +54,16 @@ glob(const vector<string>& patterns)
|
|||||||
|
|
||||||
glob_t glob_results;
|
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();
|
vector<string>::const_iterator iter = patterns.begin();
|
||||||
|
|
||||||
while(++iter != patterns.end())
|
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]);
|
paths_found.push_back(glob_results.gl_pathv[path_index]);
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ format(const char* format, ...)
|
|||||||
{
|
{
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
else if( return_value >= buffer_size_bytes )
|
else if(static_cast<unsigned int>(return_value) >= buffer_size_bytes)
|
||||||
{
|
{
|
||||||
// Realloc and try again.
|
// 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 <string>
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
|
||||||
|
|
||||||
// Use FRIEND_TEST... its not as nasty, thats what friends are for
|
// Use FRIEND_TEST... its not as nasty, thats what friends are for
|
||||||
// // OMG this is so nasty...
|
// // OMG this is so nasty...
|
||||||
// #define private public
|
// #define private public
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user