diff --git a/CMakeLists.txt b/CMakeLists.txt index ea5e467..3ec72e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,28 @@ -cmake_minimum_required(VERSION 2.8.3) -project(libcreate) +# After installation this project can be found by 'find_package(... CONFIG)' command: +# +# find_package(libcreate CONFIG REQUIRED) +# target_link_libraries(... libcreate::create) +# +# Reference for this file: +# https://github.com/forexample/package-example/blob/cf2ea1d6a209fb9eca2ab83fdd0ac15fe4d3e807/Foo/CMakeLists.txt + +cmake_minimum_required(VERSION 3.0) +project(libcreate VERSION 1.2.0) find_package(Boost REQUIRED system thread) find_package(Threads REQUIRED) -## Specify additional locations of header files +######### +# Build # +######### + +# Specify locations of header files include_directories( include ) -## Declare cpp library -add_library(create +# Declare cpp library +add_library(create SHARED src/create.cpp src/serial.cpp src/serial_stream.cpp @@ -20,6 +32,15 @@ add_library(create src/types.cpp ) +# Global includes. Used by all targets +# * header can be included by C++ code `#include ` +target_include_directories( + create PUBLIC + "$" + "$" +) + +# Manually link to thread library for build on ARM if(THREADS_HAVE_PTHREAD_ARG) set_property(TARGET create PROPERTY COMPILE_OPTIONS "-pthread") set_property(TARGET create PROPERTY INTERFACE_COMPILE_OPTIONS "-pthread") @@ -29,16 +50,17 @@ if(CMAKE_THREAD_LIBS_INIT) target_link_libraries(create "${CMAKE_THREAD_LIBS_INIT}") endif() +# Link to Boost target_link_libraries(create ${Boost_LIBRARIES} ) -## Declare example executables +# Declare example executables add_executable(create_demo examples/create_demo.cpp) add_executable(bumper_example examples/bumper_example.cpp) add_executable(odom_example examples/odom_example.cpp) -## Specify libraries to link a library or executable target against +# Specify libraries to link executable targets against target_link_libraries(create_demo ${Boost_LIBRARIES} create @@ -52,13 +74,78 @@ target_link_libraries(odom_example create ) -## Install -install(TARGETS create DESTINATION lib) -install(FILES - include/create/create.h - include/create/serial.h - include/create/types.h - include/create/data.h - include/create/packet.h - include/create/util.h - DESTINATION include/create) +########### +# Install # +########### + +# Layout. This works for all platforms: +# * /lib/cmake/ +# * /lib/ +# * /include/ +set(config_install_dir "lib/cmake/${PROJECT_NAME}") +set(include_install_dir "include") + +set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") + +# Configuration +set(version_config "${generated_dir}/${PROJECT_NAME}-config-version.cmake") +set(project_config "${generated_dir}/${PROJECT_NAME}-config.cmake") +set(targets_export_name "${PROJECT_NAME}-targets") +set(namespace "${PROJECT_NAME}::") + +# Include module with function 'write_basic_package_version_file' +include(CMakePackageConfigHelpers) + +# Configure '-config-version.cmake' +write_basic_package_version_file( + "${version_config}" + COMPATIBILITY SameMajorVersion +) + +# Configure '-config.cmake' +# Use variables: +# * targets_export_name +# * PROJECT_NAME +configure_package_config_file( + "config.cmake.in" + "${project_config}" + INSTALL_DESTINATION "${config_install_dir}" +) + +# Install targets +install( + TARGETS create + EXPORT "${targets_export_name}" + ARCHIVE DESTINATION "lib" + LIBRARY DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "${include_install_dir}" +) + +# Install headers +install(DIRECTORY include/create + DESTINATION include + FILES_MATCHING PATTERN "*.h" + PATTERN ".svn" EXCLUDE +) + +# Install config +# * /lib/cmake/libcreate/libcreate-config.cmake +# * /lib/cmake/libcreate/libcreate-config-version.cmake +install( + FILES "${project_config}" "${version_config}" + DESTINATION "${config_install_dir}" +) + +# Install config +# * /lib/cmake/libcreate/libcreate-targets.cmake +install( + EXPORT "${targets_export_name}" + NAMESPACE "${namespace}" + DESTINATION "${config_install_dir}" +) + +# Install package.xml (for catkin) +install(FILES package.xml + DESTINATION share/${PROJECT_NAME} +) diff --git a/README.md b/README.md index 22cc852..eea48b5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# libcreate +# libcreate # -C++ library for interfacing with iRobot's [Create 1 and 2](http://www.irobot.com/About-iRobot/STEM/Create-2.aspx) as well as most models of Roombas. This library forms the basis of the ROS driver in [create_autonomy](https://github.com/autonomylab/create_autonomy). +C++ library for interfacing with iRobot's [Create 1 and 2](http://www.irobot.com/About-iRobot/STEM/Create-2.aspx) as well as most models of Roomba. [create_autonomy](http://wiki.ros.org/create_autonomy) is a [ROS](http://www.ros.org/) wrapper for this library. * Documentation: TODO * Code API: TODO @@ -11,28 +11,28 @@ C++ library for interfacing with iRobot's [Create 1 and 2](http://www.irobot.com * Author: [Jacob Perron](http://jacobperron.ca) ([Autonomy Lab](http://autonomylab.org), [Simon Fraser University](http://www.sfu.ca)) * Contributors: [Mani Monajjemi](http:mani.im), [Ben Wolsieffer](https://github.com/lopsided98) -## Dependencies +## Dependencies ## * [Boost System Library](http://www.boost.org/doc/libs/1_59_0/libs/system/doc/index.html) * [Boost Thread Library](http://www.boost.org/doc/libs/1_59_0/doc/html/thread.html) -## Install +## Install ## * `cmake CMakeLists.txt` * `make` * `sudo make install` -## Example +## Example ## See source for examples. - + Example compile line: `g++ create_demo.cpp -lcreate -lboost_system -lboost_thread` -## Bugs +## Known issues ## -* _Clock_ and _Schedule_ button presses are not detected. This is a known problem to the developers at iRobot. +* _Clock_ and _Schedule_ buttons are not functional. This is a known bug related to the firmware. * Inaccurate odometry angle for Create 1 ([#22](https://github.com/AutonomyLab/libcreate/issues/22)) -## Build Status +## Build Status ## ![Build Status](https://api.travis-ci.org/AutonomyLab/libcreate.svg?branch=master) diff --git a/config.cmake.in b/config.cmake.in new file mode 100644 index 0000000..9b4c9ee --- /dev/null +++ b/config.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..9a31e9c --- /dev/null +++ b/package.xml @@ -0,0 +1,25 @@ + + + libcreate + 1.2.0 + C++ library for interfacing with iRobot's Create 1 and Create 2 + + Jacob Perron + + BSD + + http://wiki.ros.org/libcreate + + Jacob Perron + + cmake + + boost + + boost + catkin + + + cmake + +