mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 19:54:57 +08:00
Adding support to build as a ROS unary stack or as a standalone library.
This commit is contained in:
parent
30df56e4a0
commit
93b8dfe27b
127
CMakeLists.txt
127
CMakeLists.txt
@ -1,120 +1,11 @@
|
|||||||
## Project Setup
|
|
||||||
cmake_minimum_required(VERSION 2.4.6)
|
cmake_minimum_required(VERSION 2.4.6)
|
||||||
|
|
||||||
if(COMMAND cmake_policy)
|
if(DEFINED $ENV{ROS_ROOT})
|
||||||
cmake_policy(SET CMP0003 NEW)
|
# Build with ROS
|
||||||
endif(COMMAND cmake_policy)
|
include(serial_ros.cmake)
|
||||||
|
build_serial()
|
||||||
project(Serial)
|
else(DEFINED $ENV{ROS_ROOT})
|
||||||
|
# Build normally
|
||||||
## Configurations
|
include(serial.cmake)
|
||||||
|
build_serial()
|
||||||
option(SERIAL_BUILD_TESTS "Build all of the Serial tests." OFF)
|
endif(DEFINED $ENV{ROS_ROOT})
|
||||||
option(SERIAL_BUILD_EXAMPLES "Build all of the Serial examples." OFF)
|
|
||||||
|
|
||||||
# Allow for building shared libs override
|
|
||||||
IF(NOT BUILD_SHARED_LIBS)
|
|
||||||
set(BUILD_SHARED_LIBS OFF)
|
|
||||||
ENDIF(NOT BUILD_SHARED_LIBS)
|
|
||||||
|
|
||||||
# Set the default path for built executables to the "bin" directory
|
|
||||||
IF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH))
|
|
||||||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
|
|
||||||
ENDIF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH))
|
|
||||||
# set the default path for built libraries to the "lib" directory
|
|
||||||
IF(NOT DEFINED(LIBRARY_OUTPUT_PATH))
|
|
||||||
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
|
|
||||||
ENDIF(NOT DEFINED(LIBRARY_OUTPUT_PATH))
|
|
||||||
|
|
||||||
## Configure the build system
|
|
||||||
|
|
||||||
# Add the include folder to the include path
|
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
|
||||||
|
|
||||||
# Add default source files
|
|
||||||
set(SERIAL_SRCS src/serial.cpp)
|
|
||||||
# Add default header files
|
|
||||||
set(SERIAL_HEADERS include/serial.h)
|
|
||||||
|
|
||||||
# Find Boost, if it hasn't already been found
|
|
||||||
IF(NOT Boost_FOUND OR NOT Boost_SYSTEM_FOUND OR NOT Boost_FILESYSTEM_FOUND OR NOT Boost_THREAD_FOUND)
|
|
||||||
find_package(Boost COMPONENTS system filesystem thread REQUIRED)
|
|
||||||
ENDIF(NOT Boost_FOUND OR NOT Boost_SYSTEM_FOUND OR NOT Boost_FILESYSTEM_FOUND OR NOT Boost_THREAD_FOUND)
|
|
||||||
|
|
||||||
link_directories(${Boost_LIBRARY_DIRS})
|
|
||||||
include_directories(${Boost_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
set(SERIAL_LINK_LIBS ${Boost_SYSTEM_LIBRARY}
|
|
||||||
${Boost_FILESYSTEM_LIBRARY}
|
|
||||||
${Boost_THREAD_LIBRARY})
|
|
||||||
|
|
||||||
## Build the Serial Library
|
|
||||||
|
|
||||||
# Compile the Library
|
|
||||||
add_library(serial ${SERIAL_SRCS} ${SERIAL_HEADERS})
|
|
||||||
target_link_libraries(serial ${SERIAL_LINK_LIBS})
|
|
||||||
IF( WIN32 )
|
|
||||||
target_link_libraries(serial wsock32)
|
|
||||||
ENDIF( )
|
|
||||||
|
|
||||||
# Check for OS X and if so disable kqueue support in asio
|
|
||||||
IF(CMAKE_SYSTEM_NAME MATCHES Darwin)
|
|
||||||
add_definitions(-DBOOST_ASIO_DISABLE_KQUEUE)
|
|
||||||
ENDIF(CMAKE_SYSTEM_NAME MATCHES Darwin)
|
|
||||||
|
|
||||||
## Build Examples
|
|
||||||
|
|
||||||
# If asked to
|
|
||||||
IF(SERIAL_BUILD_EXAMPLES)
|
|
||||||
# Compile the Test program
|
|
||||||
add_executable(serial_example examples/serial_example.cpp)
|
|
||||||
# Link the Test program to the Serial library
|
|
||||||
target_link_libraries(serial_example serial)
|
|
||||||
ENDIF(SERIAL_BUILD_EXAMPLES)
|
|
||||||
|
|
||||||
## Build tests
|
|
||||||
|
|
||||||
# If asked to
|
|
||||||
IF(SERIAL_BUILD_TESTS)
|
|
||||||
# none yet...
|
|
||||||
ENDIF(SERIAL_BUILD_TESTS)
|
|
||||||
|
|
||||||
## Setup install and uninstall
|
|
||||||
|
|
||||||
# Unless asked not to...
|
|
||||||
IF(NOT SERIAL_DONT_CONFIGURE_INSTALL)
|
|
||||||
# Configure make install
|
|
||||||
IF(NOT CMAKE_INSTALL_PREFIX)
|
|
||||||
SET(CMAKE_INSTALL_PREFIX /usr/local)
|
|
||||||
ENDIF(NOT CMAKE_INSTALL_PREFIX)
|
|
||||||
|
|
||||||
INSTALL(TARGETS serial
|
|
||||||
RUNTIME DESTINATION bin
|
|
||||||
LIBRARY DESTINATION lib
|
|
||||||
ARCHIVE DESTINATION lib
|
|
||||||
)
|
|
||||||
|
|
||||||
INSTALL(FILES include/serial.h DESTINATION include)
|
|
||||||
|
|
||||||
IF(NOT CMAKE_FIND_INSTALL_PATH)
|
|
||||||
set(CMAKE_FIND_INSTALL_PATH ${CMAKE_ROOT})
|
|
||||||
ENDIF(NOT CMAKE_FIND_INSTALL_PATH)
|
|
||||||
|
|
||||||
INSTALL(FILES Findserial.cmake DESTINATION ${CMAKE_FIND_INSTALL_PATH}/Modules/)
|
|
||||||
|
|
||||||
ADD_CUSTOM_TARGET(uninstall @echo uninstall package)
|
|
||||||
|
|
||||||
IF (UNIX)
|
|
||||||
ADD_CUSTOM_COMMAND(
|
|
||||||
COMMENT "uninstall package"
|
|
||||||
COMMAND xargs ARGS rm < install_manifest.txt
|
|
||||||
|
|
||||||
TARGET uninstall
|
|
||||||
)
|
|
||||||
ELSE(UNIX)
|
|
||||||
ADD_CUSTOM_COMMAND(
|
|
||||||
COMMENT "uninstall only implemented in unix"
|
|
||||||
TARGET uninstall
|
|
||||||
)
|
|
||||||
ENDIF(UNIX)
|
|
||||||
ENDIF(NOT SERIAL_DONT_CONFIGURE_INSTALL)
|
|
||||||
34
Makefile
34
Makefile
@ -1,33 +1,5 @@
|
|||||||
all: serial
|
ifdef ROS_ROOT
|
||||||
|
include $(shell rospack find mk)/cmake.mk
|
||||||
install:
|
|
||||||
cd build && make install
|
|
||||||
|
|
||||||
uninstall:
|
|
||||||
cd build && make uninstall
|
|
||||||
|
|
||||||
serial:
|
|
||||||
@mkdir -p build
|
|
||||||
-mkdir -p bin
|
|
||||||
cd build && cmake $(CMAKE_FLAGS) ..
|
|
||||||
ifneq ($(MAKE),)
|
|
||||||
cd build && $(MAKE)
|
|
||||||
else
|
else
|
||||||
cd build && make
|
include serial.mk
|
||||||
endif
|
endif
|
||||||
|
|
||||||
clean:
|
|
||||||
-cd build && make clean
|
|
||||||
rm -rf build bin lib
|
|
||||||
|
|
||||||
.PHONY: test
|
|
||||||
test:
|
|
||||||
@mkdir -p build
|
|
||||||
@mkdir -p bin
|
|
||||||
cd build && cmake $(CMAKE_FLAGS) -DSERIAL_BUILD_TESTS=1 -DSERIAL_BUILD_EXAMPLES=1 ..
|
|
||||||
ifneq ($(MAKE),)
|
|
||||||
cd build && $(MAKE)
|
|
||||||
else
|
|
||||||
cd build && make
|
|
||||||
endif
|
|
||||||
# cd bin && ./serial_tests
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "serial.h"
|
#include "serial/serial.h"
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|||||||
26
mainpage.dox
Normal file
26
mainpage.dox
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
\mainpage
|
||||||
|
\htmlinclude manifest.html
|
||||||
|
|
||||||
|
\b serial is ...
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Provide an overview of your package.
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
\section codeapi Code API
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Provide links to specific auto-generated API documentation within your
|
||||||
|
package that is of particular interest to a reader. Doxygen will
|
||||||
|
document pretty much every part of your code, so do your best here to
|
||||||
|
point the reader to the actual API.
|
||||||
|
|
||||||
|
If your codebase is fairly large or has different sets of APIs, you
|
||||||
|
should use the doxygen 'group' tag to keep these APIs together. For
|
||||||
|
example, the roscpp documentation has 'libros' group.
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
14
manifest.xml
Normal file
14
manifest.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<package>
|
||||||
|
<description brief="serial">
|
||||||
|
|
||||||
|
serial
|
||||||
|
|
||||||
|
</description>
|
||||||
|
<author>William Woodall</author>
|
||||||
|
<license>BSD</license>
|
||||||
|
<review status="unreviewed" notes=""/>
|
||||||
|
<url>http://ros.org/wiki/serial</url>
|
||||||
|
|
||||||
|
</package>
|
||||||
|
|
||||||
|
|
||||||
122
serial.cmake
Normal file
122
serial.cmake
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
macro(build_serial)
|
||||||
|
## Project Setup
|
||||||
|
cmake_minimum_required(VERSION 2.4.6)
|
||||||
|
|
||||||
|
if(COMMAND cmake_policy)
|
||||||
|
cmake_policy(SET CMP0003 NEW)
|
||||||
|
endif(COMMAND cmake_policy)
|
||||||
|
|
||||||
|
project(Serial)
|
||||||
|
|
||||||
|
## Configurations
|
||||||
|
|
||||||
|
option(SERIAL_BUILD_TESTS "Build all of the Serial tests." OFF)
|
||||||
|
option(SERIAL_BUILD_EXAMPLES "Build all of the Serial examples." OFF)
|
||||||
|
|
||||||
|
# Allow for building shared libs override
|
||||||
|
IF(NOT BUILD_SHARED_LIBS)
|
||||||
|
set(BUILD_SHARED_LIBS OFF)
|
||||||
|
ENDIF(NOT BUILD_SHARED_LIBS)
|
||||||
|
|
||||||
|
# Set the default path for built executables to the "bin" directory
|
||||||
|
IF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH))
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
|
||||||
|
ENDIF(NOT DEFINED(EXECUTABLE_OUTPUT_PATH))
|
||||||
|
# set the default path for built libraries to the "lib" directory
|
||||||
|
IF(NOT DEFINED(LIBRARY_OUTPUT_PATH))
|
||||||
|
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
|
||||||
|
ENDIF(NOT DEFINED(LIBRARY_OUTPUT_PATH))
|
||||||
|
|
||||||
|
## Configure the build system
|
||||||
|
|
||||||
|
# Add the include folder to the include path
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
|
# Add default source files
|
||||||
|
set(SERIAL_SRCS src/serial.cpp)
|
||||||
|
# Add default header files
|
||||||
|
set(SERIAL_HEADERS include/serial/serial.h)
|
||||||
|
|
||||||
|
# Find Boost, if it hasn't already been found
|
||||||
|
IF(NOT Boost_FOUND OR NOT Boost_SYSTEM_FOUND OR NOT Boost_FILESYSTEM_FOUND OR NOT Boost_THREAD_FOUND)
|
||||||
|
find_package(Boost COMPONENTS system filesystem thread REQUIRED)
|
||||||
|
ENDIF(NOT Boost_FOUND OR NOT Boost_SYSTEM_FOUND OR NOT Boost_FILESYSTEM_FOUND OR NOT Boost_THREAD_FOUND)
|
||||||
|
|
||||||
|
link_directories(${Boost_LIBRARY_DIRS})
|
||||||
|
include_directories(${Boost_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
set(SERIAL_LINK_LIBS ${Boost_SYSTEM_LIBRARY}
|
||||||
|
${Boost_FILESYSTEM_LIBRARY}
|
||||||
|
${Boost_THREAD_LIBRARY})
|
||||||
|
|
||||||
|
## Build the Serial Library
|
||||||
|
|
||||||
|
# Compile the Library
|
||||||
|
add_library(serial ${SERIAL_SRCS} ${SERIAL_HEADERS})
|
||||||
|
target_link_libraries(serial ${SERIAL_LINK_LIBS})
|
||||||
|
IF( WIN32 )
|
||||||
|
target_link_libraries(serial wsock32)
|
||||||
|
ENDIF( )
|
||||||
|
|
||||||
|
# Check for OS X and if so disable kqueue support in asio
|
||||||
|
IF(CMAKE_SYSTEM_NAME MATCHES Darwin)
|
||||||
|
add_definitions(-DBOOST_ASIO_DISABLE_KQUEUE)
|
||||||
|
ENDIF(CMAKE_SYSTEM_NAME MATCHES Darwin)
|
||||||
|
|
||||||
|
## Build Examples
|
||||||
|
|
||||||
|
# If asked to
|
||||||
|
IF(SERIAL_BUILD_EXAMPLES)
|
||||||
|
# Compile the Test program
|
||||||
|
add_executable(serial_example examples/serial_example.cpp)
|
||||||
|
# Link the Test program to the Serial library
|
||||||
|
target_link_libraries(serial_example serial)
|
||||||
|
ENDIF(SERIAL_BUILD_EXAMPLES)
|
||||||
|
|
||||||
|
## Build tests
|
||||||
|
|
||||||
|
# If asked to
|
||||||
|
IF(SERIAL_BUILD_TESTS)
|
||||||
|
# none yet...
|
||||||
|
ENDIF(SERIAL_BUILD_TESTS)
|
||||||
|
|
||||||
|
## Setup install and uninstall
|
||||||
|
|
||||||
|
# Unless asked not to...
|
||||||
|
IF(NOT SERIAL_DONT_CONFIGURE_INSTALL)
|
||||||
|
# Configure make install
|
||||||
|
IF(NOT CMAKE_INSTALL_PREFIX)
|
||||||
|
SET(CMAKE_INSTALL_PREFIX /usr/local)
|
||||||
|
ENDIF(NOT CMAKE_INSTALL_PREFIX)
|
||||||
|
|
||||||
|
INSTALL(TARGETS serial
|
||||||
|
RUNTIME DESTINATION bin
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
ARCHIVE DESTINATION lib
|
||||||
|
)
|
||||||
|
|
||||||
|
INSTALL(FILES include/serial.h DESTINATION include)
|
||||||
|
|
||||||
|
IF(NOT CMAKE_FIND_INSTALL_PATH)
|
||||||
|
set(CMAKE_FIND_INSTALL_PATH ${CMAKE_ROOT})
|
||||||
|
ENDIF(NOT CMAKE_FIND_INSTALL_PATH)
|
||||||
|
|
||||||
|
INSTALL(FILES Findserial.cmake DESTINATION ${CMAKE_FIND_INSTALL_PATH}/Modules/)
|
||||||
|
|
||||||
|
ADD_CUSTOM_TARGET(uninstall @echo uninstall package)
|
||||||
|
|
||||||
|
IF (UNIX)
|
||||||
|
ADD_CUSTOM_COMMAND(
|
||||||
|
COMMENT "uninstall package"
|
||||||
|
COMMAND xargs ARGS rm < install_manifest.txt
|
||||||
|
|
||||||
|
TARGET uninstall
|
||||||
|
)
|
||||||
|
ELSE(UNIX)
|
||||||
|
ADD_CUSTOM_COMMAND(
|
||||||
|
COMMENT "uninstall only implemented in unix"
|
||||||
|
TARGET uninstall
|
||||||
|
)
|
||||||
|
ENDIF(UNIX)
|
||||||
|
ENDIF(NOT SERIAL_DONT_CONFIGURE_INSTALL)
|
||||||
|
endmacro(build_serial)
|
||||||
33
serial.mk
Normal file
33
serial.mk
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
all: serial
|
||||||
|
|
||||||
|
install:
|
||||||
|
cd build && make install
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
cd build && make uninstall
|
||||||
|
|
||||||
|
serial:
|
||||||
|
@mkdir -p build
|
||||||
|
-mkdir -p bin
|
||||||
|
cd build && cmake $(CMAKE_FLAGS) ..
|
||||||
|
ifneq ($(MAKE),)
|
||||||
|
cd build && $(MAKE)
|
||||||
|
else
|
||||||
|
cd build && make
|
||||||
|
endif
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-cd build && make clean
|
||||||
|
rm -rf build bin lib
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
@mkdir -p build
|
||||||
|
@mkdir -p bin
|
||||||
|
cd build && cmake $(CMAKE_FLAGS) -DSERIAL_BUILD_TESTS=1 -DSERIAL_BUILD_EXAMPLES=1 ..
|
||||||
|
ifneq ($(MAKE),)
|
||||||
|
cd build && $(MAKE)
|
||||||
|
else
|
||||||
|
cd build && make
|
||||||
|
endif
|
||||||
|
# cd bin && ./serial_tests
|
||||||
35
serial_ros.cmake
Normal file
35
serial_ros.cmake
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
macro(build_serial)
|
||||||
|
cmake_minimum_required(VERSION 2.4.6)
|
||||||
|
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
|
||||||
|
|
||||||
|
# Set the build type. Options are:
|
||||||
|
# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
|
||||||
|
# Debug : w/ debug symbols, w/o optimization
|
||||||
|
# Release : w/o debug symbols, w/ optimization
|
||||||
|
# RelWithDebInfo : w/ debug symbols, w/ optimization
|
||||||
|
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
|
||||||
|
set(ROS_BUILD_TYPE RelWithDebInfo)
|
||||||
|
|
||||||
|
rosbuild_init()
|
||||||
|
|
||||||
|
#set the default path for built executables to the "bin" directory
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
|
||||||
|
#set the default path for built libraries to the "lib" directory
|
||||||
|
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
|
||||||
|
|
||||||
|
# Check for OS X and if so disable kqueue support in asio
|
||||||
|
IF(CMAKE_SYSTEM_NAME MATCHES Darwin)
|
||||||
|
add_definitions(-DBOOST_ASIO_DISABLE_KQUEUE)
|
||||||
|
ENDIF(CMAKE_SYSTEM_NAME MATCHES Darwin)
|
||||||
|
|
||||||
|
# Build the serial library
|
||||||
|
rosbuild_add_library(${PROJECT_NAME} src/serial.cpp include/serial/serial.h)
|
||||||
|
|
||||||
|
# Add boost dependencies
|
||||||
|
rosbuild_add_boost_directories()
|
||||||
|
rosbuild_link_boost(${PROJECT_NAME} system filesystem thread)
|
||||||
|
|
||||||
|
# Build example
|
||||||
|
rosbuild_add_executable(serial_example examples/serial_example.cpp)
|
||||||
|
target_link_libraries(serial_example ${PROJECT_NAME})
|
||||||
|
endmacro(build_serial)
|
||||||
@ -1,4 +1,4 @@
|
|||||||
#include "serial.h"
|
#include "serial/serial.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace serial;
|
using namespace serial;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user