Skip to content

Commit

Permalink
Merge pull request #63 from jontje/plain_cmake
Browse files Browse the repository at this point in the history
Plain cmake
  • Loading branch information
jontje authored Jan 22, 2020
2 parents 142f5a5 + 3ad2428 commit fc647bd
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 81 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
sudo: required
language: generic
dist: trusty
services:
- docker

env:
matrix:
- ROS_DISTRO="kinetic" ROS_REPO=ros NOT_TEST_INSTALL=true CATKIN_LINT=true
- ROS_DISTRO="kinetic" ROS_REPO=ros CATKIN_LINT=true
- ROS_DISTRO="dashing" ROS_REPO=ros

install:
- git clone --depth=1 https://github.com/ros-industrial/industrial_ci.git .ci_config
- git clone --depth=1 -b master https://github.com/ros-industrial/industrial_ci.git .ci_config

script:
- .ci_config/travis.sh
171 changes: 124 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,52 +1,70 @@
cmake_minimum_required(VERSION 2.8.12)
project(abb_libegm)
cmake_minimum_required(VERSION 3.5)

find_package(catkin REQUIRED)
# Read version from the package.xml file.
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/package.xml package_xml_str)
if(NOT package_xml_str MATCHES "<version>([0-9]+.[0-9]+.[0-9]+)</version>")
message(FATAL_ERROR "Could not parse project version from package.xml. Aborting.")
endif()

# At this point we either have a proper version string, or we've errored
# out with a FATAL_ERROR above. So assume CMAKE_MATCH_1 contains our
# package's version.
project(abb_libegm VERSION ${CMAKE_MATCH_1} LANGUAGES CXX)

include(GNUInstallDirs)

if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

find_package(Boost REQUIRED COMPONENTS system thread)
#########################
## Boost C++ Libraries ##
#########################
find_package(Boost REQUIRED COMPONENTS regex system thread)

#############################
## Google Protocol Buffers ##
#############################
find_package(Protobuf REQUIRED)

# work around Protobuf exporting 'lpthread' as a library: we
# export the dependency on pthread using the CFG_EXTRAS files
list (REMOVE_ITEM PROTOBUF_LIBRARIES "-lpthread")
if(WIN32)
# For a Chocolatey-based ROS/ROS2 installation, then it appears that the protobuf compiler is
# by default installed at ${_CMAKE_INSTALL_DIR}/tools/protobuf, and find_package() doesn't
# always seem to find the compiler without specifying a hint.
find_package(Protobuf REQUIRED HINTS ${_CMAKE_INSTALL_DIR}/tools/protobuf)
else()
find_package(Protobuf REQUIRED)
endif()

# Make sure protoc is present, as apparently the above find_package() doesn't check that.
find_program(Protobuf_PROTOC_LOC NAMES protoc)
if (NOT Protobuf_PROTOC_LOC)
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
message(FATAL_ERROR "Cannot find required 'protoc', cannot process Protobuf files without it. Aborting.")
endif()

# Generate C++ for protocol classes (headers and sources get written to the CMAKE_CURRENT_BINARY_DIR location).
# Generate C++ for protocol classes (headers and sources
# get written to the CMAKE_CURRENT_BINARY_DIR location).
set(EgmProtoFiles proto/egm.proto proto/egm_wrapper.proto proto/egm_wrapper_trajectory.proto)
if (NOT QUIET)
if(NOT QUIET)
message(STATUS "Generating protobuf C++ for: ${EgmProtoFiles}")
endif()
protobuf_generate_cpp(EgmProtoSources EgmProtoHeaders ${EgmProtoFiles})

###################################
## catkin specific configuration ##
###################################
catkin_package(
INCLUDE_DIRS
include
LIBRARIES
${PROJECT_NAME}
CFG_EXTRAS
# this exports pthread dependency for us
abb_libegm-extras.cmake
DEPENDS
Boost
PROTOBUF
)
#############
## Threads ##
#############
find_package(Threads REQUIRED)

# Work around Protobuf exporting 'lpthread' as a library: we let the
# previous find_package(...) determine the system's thread library.
list(REMOVE_ITEM PROTOBUF_LIBRARIES "-lpthread")

###########
## Build ##
###########
set(SRC_FILES
if(NOT DEFINED BUILD_SHARED_LIBS)
option(BUILD_SHARED_LIBS "Build dynamically-linked binaries" ON)
endif()

set(
SRC_FILES
src/egm_base_interface.cpp
src/egm_common.cpp
src/egm_common_auxiliary.cpp
Expand All @@ -55,30 +73,89 @@ set(SRC_FILES
src/egm_logger.cpp
src/egm_udp_server.cpp
src/egm_trajectory_interface.cpp
${EgmProtoSources})

include_directories(include
${CMAKE_CURRENT_BINARY_DIR} # Contains protobuf generated sources
${Boost_INCLUDE_DIRS}
${PROTOBUF_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS})
${EgmProtoSources}
)

add_library(${PROJECT_NAME} ${SRC_FILES})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES} ${PROTOBUF_LIBRARIES} ${catkin_LIBRARIES})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

include(GenerateExportHeader)
generate_export_header(${PROJECT_NAME})

target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include;${CMAKE_CURRENT_BINARY_DIR}>"
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
${PROTOBUF_INCLUDE_DIRS}
)

target_link_libraries(${PROJECT_NAME} PUBLIC
Boost::regex
Boost::system
Boost::thread
${PROTOBUF_LIBRARIES}
Threads::Threads
)

if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(${PROJECT_NAME} PUBLIC "ABB_LIBEGM_STATIC_DEFINE")
endif()

#############
## Install ##
#############
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION})
install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h")
install(
FILES
${EgmProtoFiles}
${EgmProtoHeaders}
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
)

install(
TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(FILES ${EgmProtoHeaders}
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
include(CMakePackageConfigHelpers)

install(FILES ${EgmProtoFiles}
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
# Create the ${PROJECT_NAME}Config.cmake.
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
"${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake" @ONLY
)

# Create the ${PROJECT_NAME}ConfigVersion.cmake.
write_basic_package_version_file(
${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
COMPATIBILITY AnyNewerVersion
)

install(
FILES
"${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
)

# Export targets.
set(export_targets ${export_targets};${PROJECT_NAME})
export(
EXPORT export_${PROJECT_NAME}
FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake"
NAMESPACE ${PROJECT_NAME}::
)

install(
EXPORT export_${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
)
10 changes: 0 additions & 10 deletions cmake/abb_libegm-extras.cmake.in

This file was deleted.

15 changes: 15 additions & 0 deletions cmake/abb_libegmConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# - Config file for the abb_libegm package
# It defines the following variable
# abb_libegm_LIBRARIES - libraries to link against

include(CMakeFindDependencyMacro)

# Find dependencies
find_dependency(Threads REQUIRED)
find_dependency(Boost REQUIRED COMPONENTS regex system thread)

# Our library dependencies (contains definitions for IMPORTED targets)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")

# These are IMPORTED targets created by @PROJECT_NAME@Targets.cmake
set(abb_libegm_LIBRARIES @PROJECT_NAME@::@PROJECT_NAME@)
20 changes: 11 additions & 9 deletions include/abb_libegm/egm_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#ifndef EGM_COMMON_H
#define EGM_COMMON_H

#include "abb_libegm_export.h"

namespace abb
{
namespace egm
Expand Down Expand Up @@ -67,13 +69,13 @@ struct Constants
/**
* \brief Constants related to the robot controller system.
*/
struct RobotController
struct ABB_LIBEGM_EXPORT RobotController
{
/**
* \brief Lowest sample time [s] used in EGM communication.
*/
static const double LOWEST_SAMPLE_TIME;

/**
* \brief Default port number assumed for EGM communication.
*/
Expand All @@ -98,7 +100,7 @@ struct Constants
/**
* \brief Constants related to the conversions between units.
*/
struct Conversion
struct ABB_LIBEGM_EXPORT Conversion
{
/**
* \brief Conversion value from radians to degrees.
Expand Down Expand Up @@ -143,14 +145,14 @@ struct BaseConfiguration
use_logging(false),
max_logging_duration(60.0)
{}

/**
* \brief Value specifying if a six or seven axes robot is used.
*
* Note: If set to a seven axes robot, then an implicit mapping of joint values is performed.
*/
RobotAxes axes;

/**
* \brief Flag indicating if demo outputs should be used.
*
Expand All @@ -165,7 +167,7 @@ struct BaseConfiguration
* Note: If set to false, then no velocity values are sent (they are optional).
*/
bool use_velocity_outputs;

/**
* \brief Flag indicating if the interface should log data.
*/
Expand Down Expand Up @@ -223,12 +225,12 @@ struct TrajectoryConfiguration
base(base_configuration),
spline_method(Quintic)
{}

/**
* \brief The base configurations.
*/
BaseConfiguration base;

/**
* \brief Value specifying which spline method to use in the interpolation.
*/
Expand All @@ -238,4 +240,4 @@ struct TrajectoryConfiguration
} // end namespace egm
} // end namespace abb

#endif // EGM_COMMON_H
#endif // EGM_COMMON_H
22 changes: 11 additions & 11 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?xml version="1.0"?>
<package>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>abb_libegm</name>
<version>1.0.0</version>
<description>The abb_libegm package for easing the use of ABB Externally Guided Motion (EGM) product</description>

<description>A C++ library for interfacing with ABB robot controllers supporting Externally Guided Motion (689-1)</description>
<maintainer email="jon.tjerngren@se.abb.com">Jon Tjerngren</maintainer>

<license>BSD 3-Clause</license>

<author email="jon.tjerngren@se.abb.com">Jon Tjerngren</author>

<url type="repository">https://github.com/ros-industrial/abb_libegm</url>
<author>Jon Tjerngren</author>

<buildtool_depend>catkin</buildtool_depend>
<buildtool_depend>cmake</buildtool_depend>

<build_depend>boost</build_depend>
<depend>boost</depend>
<build_depend>protobuf-dev</build_depend>
<build_export_depend>protobuf-dev</build_export_depend>
<exec_depend>protobuf</exec_depend>

<run_depend>boost</run_depend>
<run_depend>protobuf</run_depend>
<export>
<build_type>cmake</build_type>
</export>
</package>

0 comments on commit fc647bd

Please sign in to comment.