Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 81 additions & 65 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,90 @@ project(proton_vendor)
# Find ROS 2 dependencies
find_package(ament_cmake REQUIRED)

include(ExternalProject)

set(PROTON_EXTERNAL_PROJECT_NAME proton_external_project)
set(PROTON_GIT_REPOSITORY "https://github.com/clearpathrobotics/proton.git")
set(PROTON_GIT_TAG "1.0.0")

set(EXTERNAL_PROJECT_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/proton_external_build)
set(EXTERNAL_PROJECT_SOURCE_DIR ${EXTERNAL_PROJECT_PREFIX}/src/proton)
set(EXTERNAL_PROJECT_BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build/proton)
set(EXTERNAL_PROJECT_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}) # Proton library should install its files (libraries, headers) into proton_vendor package install space.

# Use sequential build for ExternalProject to avoid file descriptor issues
set(EXTERNAL_PROJECT_BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --parallel 1)

ExternalProject_Add(${PROTON_EXTERNAL_PROJECT_NAME}
# download step
GIT_REPOSITORY ${PROTON_GIT_REPOSITORY}
GIT_TAG ${PROTON_GIT_TAG}

# directiories config
PREFIX ${EXTERNAL_PROJECT_PREFIX}
SOURCE_DIR ${EXTERNAL_PROJECT_SOURCE_DIR}
BINARY_DIR ${EXTERNAL_PROJECT_BINARY_DIR}
INSTALL_DIR ${EXTERNAL_PROJECT_INSTALL_DIR}

# after initial download, don't re-fetch source on subsequent CMake runs
UPDATE_COMMAND ""

# configure step
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S <SOURCE_DIR> -B <BINARY_DIR>
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CROSSCOMPILING=OFF
-DBUILD_SHARED_LIBS=ON
-DPROTON_BUILD_PROTONC=ON
-DPROTON_BUILD_PROTONCPP=ON
-DPROTON_BUILD_EXAMPLES=OFF
-DPROTON_BUILD_TESTS=OFF
-DPROTON_INSTALL=ON

# build step
BUILD_COMMAND ${EXTERNAL_PROJECT_BUILD_COMMAND}

# install step
INSTALL_COMMAND ""

# logging
LOG_CONFIGURE YES
LOG_BUILD YES
LOG_INSTALL YES
)

# ros buildfarm fix: separate ExternalProject install step from the clone/build steps.
# Reference: https://github.com/ros-industrial/ros2_canopen/blob/master/lely_core_libraries/CMakeLists.txt
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} --install ${EXTERNAL_PROJECT_BINARY_DIR})")

add_library(proton_vendor INTERFACE)
add_library(proton_vendor::proton_vendor ALIAS proton_vendor)

target_include_directories(proton_vendor
INTERFACE
$<INSTALL_INTERFACE:include>
)
target_link_libraries(proton_vendor
INTERFACE
${CMAKE_INSTALL_PREFIX}/lib/libprotonc.so
${CMAKE_INSTALL_PREFIX}/lib/libprotoncpp.so
)
# Option to use local proton instead of downloading from GitHub
option(PROTON_VENDOR_USE_LOCAL "Use local proton instead of downloading from GitHub" OFF)

if(PROTON_VENDOR_USE_LOCAL)
# Use local proton from workspace
find_package(proton REQUIRED)

target_link_libraries(proton_vendor
INTERFACE
proton::protonc
proton::protoncpp
)

else()
# Download and build proton from GitHub
include(ExternalProject)

set(PROTON_EXTERNAL_PROJECT_NAME proton_external_project)
set(PROTON_GIT_REPOSITORY "https://github.com/clearpathrobotics/proton.git")
set(PROTON_GIT_TAG "1.0.0")

set(EXTERNAL_PROJECT_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/proton_external_build)
set(EXTERNAL_PROJECT_SOURCE_DIR ${EXTERNAL_PROJECT_PREFIX}/src/proton)
set(EXTERNAL_PROJECT_BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build/proton)
set(EXTERNAL_PROJECT_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}) # Proton library should install its files (libraries, headers) into proton_vendor package install space.

# Use sequential build for ExternalProject to avoid file descriptor issues
set(EXTERNAL_PROJECT_BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --parallel 1)

ExternalProject_Add(${PROTON_EXTERNAL_PROJECT_NAME}
# download step
GIT_REPOSITORY ${PROTON_GIT_REPOSITORY}
GIT_TAG ${PROTON_GIT_TAG}

# directiories config
PREFIX ${EXTERNAL_PROJECT_PREFIX}
SOURCE_DIR ${EXTERNAL_PROJECT_SOURCE_DIR}
BINARY_DIR ${EXTERNAL_PROJECT_BINARY_DIR}
INSTALL_DIR ${EXTERNAL_PROJECT_INSTALL_DIR}

# after initial download, don't re-fetch source on subsequent CMake runs
UPDATE_COMMAND ""

# configure step
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S <SOURCE_DIR> -B <BINARY_DIR>
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CROSSCOMPILING=OFF
-DBUILD_SHARED_LIBS=ON
-DPROTON_BUILD_PROTONC=ON
-DPROTON_BUILD_PROTONCPP=ON
-DPROTON_BUILD_EXAMPLES=OFF
-DPROTON_BUILD_TESTS=OFF
-DPROTON_INSTALL=ON

# build step
BUILD_COMMAND ${EXTERNAL_PROJECT_BUILD_COMMAND}

# install step
INSTALL_COMMAND ""

# logging
LOG_CONFIGURE YES
LOG_BUILD YES
LOG_INSTALL YES
)

# ros buildfarm fix: separate ExternalProject install step from the clone/build steps.
# Reference: https://github.com/ros-industrial/ros2_canopen/blob/master/lely_core_libraries/CMakeLists.txt
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} --install ${EXTERNAL_PROJECT_BINARY_DIR})")

target_include_directories(proton_vendor
INTERFACE
$<INSTALL_INTERFACE:include>
)
target_link_libraries(proton_vendor
INTERFACE
${CMAKE_INSTALL_PREFIX}/lib/libprotonc.so
${CMAKE_INSTALL_PREFIX}/lib/libprotoncpp.so
)
endif()

install(
TARGETS proton_vendor
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# proton_vendor

Proton Vendor package that is used to package [Proton](https://github.com/clearpathrobotics/proton) as a ROS 2 package.

## Building

By default, this package downloads and builds Proton from GitHub. For development with local Proton changes, you can use Proton from the same workspace:

```
colcon build --cmake-args -DPROTON_VENDOR_USE_LOCAL=ON --symlink-install
```

Ensure Proton is cloned in the same workspace when using this option.
6 changes: 4 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>proton_vendor</name>
<version>0.0.0</version>
<version>1.0.0</version>
<description>Proton vendor package</description>
<maintainer email="rkreinin@clearpathrobotics.com">rkreinin</maintainer>
<maintainer email="thomas.wallis@rockwellautomation.com">Tom Wallis</maintainer>
<license>Apache 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>git</buildtool_depend>

<depend>proton</depend>

<depend>asio</depend>
<depend>protobuf-dev</depend>
<depend>python3-protobuf</depend>
Expand Down
Loading