Skip to content

Commit

Permalink
Added missing lines, so copy-paste of the example leads to a working …
Browse files Browse the repository at this point in the history
…CMakeLists.txt file.

Signed-off-by: Johan Rutgeerts <[email protected]>
  • Loading branch information
jrutgeer committed Oct 13, 2023
1 parent 0622409 commit dadd27a
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions tutorials/message_generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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 +190,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 +209,30 @@ 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
)
```

</br>

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}
```

</br>


### Using Custom messages

There are two primary ways that Gazebo messages are used as part of an application.
Expand Down Expand Up @@ -270,7 +297,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

0 comments on commit dadd27a

Please sign in to comment.