Skip to content
tcies edited this page Nov 10, 2014 · 5 revisions

This page assumes that you are using catkin_simple.

Exporting proto definitions to other catkin packages

Exporting package

We use the PROTOBUF_EXPORT_PATH global cmake variable to pass include directories for the proto compiler. Thus, add a cmake-extras file to your catkin package as follows:

Create a file cmake/<package name>-extras.cmake.in with:

list(APPEND PROTOBUF_EXPORT_PATH @CMAKE_CURRENT_SOURCE_DIR@/proto/)

To export this, you need to complete the cs_export command in your CMakeLists.txt:

cs_export(INCLUDE_DIRS include ${CMAKE_CURRENT_BINARY_DIR}
          CFG_EXTRAS multiagent_mapping_common-extras.cmake)

Don't forget to compile the proto file in the exporting package:

set(PROTO_DEFNS proto/<your file>.proto)
PROTOBUF_CATKIN_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${PROTO_DEFNS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

Importing package

In the depending package, you can import the proto definitions by adding

import "your-exported-proto-file.proto";

in the proto file. If you defined a namespace in your exporter proto file, e.g.:

package common.proto;

you need to use this namespace when referring to the message types, i.e.:

optional common.proto.YourMessageType position = 2;
Clone this wiki locally