Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing parts to the CMakeLists.txt code. #400

Merged
merged 7 commits into from
Nov 3, 2023
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
7 changes: 5 additions & 2 deletions examples/generating_custom_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ project(generating_custom_messages VERSION 1.0.0)
find_package(gz-cmake3 REQUIRED)

find_package(gz-msgs10 REQUIRED)
# Define a variable 'GZ_MSGS_VER' holding the version number
set(GZ_MSGS_VER ${gz-msgs10_VERSION_MAJOR})

# Example of custom messages that depend on gz.msgs
# Define a variable 'MSGS_PROTOS' listing the .proto files
set(MSGS_PROTOS
${CMAKE_CURRENT_SOURCE_DIR}/proto/gz/custom_msgs/foo.proto
${CMAKE_CURRENT_SOURCE_DIR}/proto/gz/custom_msgs/bar.proto
${CMAKE_CURRENT_SOURCE_DIR}/proto/gz/custom_msgs/baz.proto
)

# Call 'gz_msgs_generate_messages()' to process the .proto files
gz_msgs_generate_messages(
# The cmake target to be generated for libraries/executables to link
TARGET msgs
Expand All @@ -28,8 +30,9 @@ gz_msgs_generate_messages(
# The path to the base directory of the proto files
# All import paths should be relative to this (eg gz/custom_msgs/vector3d.proto)
MSGS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/proto
# List of proto files to generate
# List of proto files to process
MSGS_PROTOS ${MSGS_PROTOS}
# Depenency on gz-msgs
DEPENDENCIES gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER}
)

Expand Down
34 changes: 30 additions & 4 deletions tutorials/message_generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ For the collection, `gz_msgs_factory` generates:
Now that we understand the components of the message generation pipeline,
we can use them in our own custom package.

The code for this example can be found in the `gz-msgs` [repository](https://github.com/gazebosim/gz-msgs/tree/gz-msgs10), in the [`examples/generating_custom_msgs`](https://github.com/gazebosim/gz-msgs/tree/gz-msgs10/examples/generating_custom_msgs) folder.



The `cmake` functionality is exported from the `gz-msgs` library, via the `gz-cmake` [`extras` functionality](https://github.com/gazebosim/gz-cmake/pull/345).
To make the functions available, simply `find_package(gz-msgs10)` in your `CMakeLists.txt`:

Expand All @@ -129,6 +133,7 @@ find_package(gz-cmake3 REQUIRED)
find_package(gz-msgs10 REQUIRED)
```


Next, create a directory for your custom message definitions:

```sh
Expand Down Expand Up @@ -189,9 +194,17 @@ message BazStamped
```


Then, back in the `CMakeLists.txt` file, generate the message library.
Then, back in the `CMakeLists.txt` file, add following lines to generate the message library:

```cmake
# Define a variable 'MSGS_PROTOS' listing the .proto files
set(MSGS_PROTOS
${CMAKE_CURRENT_SOURCE_DIR}/proto/gz/custom_msgs/foo.proto
${CMAKE_CURRENT_SOURCE_DIR}/proto/gz/custom_msgs/bar.proto
${CMAKE_CURRENT_SOURCE_DIR}/proto/gz/custom_msgs/baz.proto
)

# Call 'gz_msgs_generate_messages()' to process the .proto files
gz_msgs_generate_messages(
# The cmake target to be generated for libraries/executables to link
TARGET msgs
Expand All @@ -200,12 +213,25 @@ gz_msgs_generate_messages(
# The path to the base directory of the proto files
# All import paths should be relative to this (eg gz/custom_msgs/vector3d.proto)
MSGS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/proto
# List of proto files to generate
# List of proto files to process
MSGS_PROTOS ${MSGS_PROTOS}
DEPENDENCIES gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER}
# Depenency on gz-msgs
DEPENDENCIES gz-msgs10::gz-msgs10
)
```

In order to reduce the amount of edits needed upon a version change of `gz-msgs`, it is common to:

- Define a variable `GZ_MSGS_VER`, holding the version number:
```cmake
find_package(gz-msgs10 REQUIRED)
set(GZ_MSGS_VER ${gz-msgs10_VERSION_MAJOR})
```
- And change the dependency line in above code block to:
```cmake
DEPENDENCIES gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER}
```

### Using Custom messages

There are two primary ways that Gazebo messages are used as part of an application.
Expand Down Expand Up @@ -270,7 +296,7 @@ $ cd build/
$ export GZ_DESCRIPTOR_PATH=`pwd`

$ gz msg -l | grep "custom_msgs" | wc -l
6
4

$ gz msg --info gz.custom_msgs.Foo
Name: gz.custom_msgs.Foo
Expand Down