# Own message generator and building tests

**URL:** <https://discourse.openrobotics.org/t/own-message-generator-and-building-tests/796>\
**Category:** ROS General\
**Created:** [November 7, 2016, 6:51pm UTC](https://discourse.openrobotics.org/t/own-message-generator-and-building-tests/796 "2016-11-07T18:51:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![firesurfer](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/firesurfer/32/11626_2.png) [@firesurfer](https://discourse.openrobotics.org/u/firesurfer)\
**Post date:** [November 7, 2016, 6:51pm UTC](https://discourse.openrobotics.org/t/own-message-generator-and-building-tests/796/1 "2016-11-07T18:51:00Z")

</div>

For my C# wrapper I wrote my own message generator and implemented a rosidl\_generator\_cs package ( [GitHub - firesurfer/rosidl\_generator\_cs: ROS2 Message generator for C#](https://github.com/firesurfer/rosidl_generator_cs) ).

This works fine when doing a normal build but today I tried building ros2 with the --build-tests option. With this option the build fails at the builtin\_interfaces package.

```
Scanning dependencies of target builtin_interfaces__py
Scanning dependencies of target generate_cs_messages_Time
make[2]: *** Keine Regel vorhanden, um das Ziel „/home/firesurfer/workspace/ros2_ws/src/ros2/common_interfaces/builtin_interfaces/ros2cs_message_generator“, 
benötigt von „CMakeFiles/generate_cs_messages_Duration“, zu erstellen. Schluss.
CMakeFiles/Makefile2:520: die Regel für Ziel „CMakeFiles/generate_cs_messages_Duration.dir/all“ scheiterte
make[1]: *** [CMakeFiles/generate_cs_messages_Duration.dir/all] Fehler 2
make[1]: *** Es wird auf noch nicht beendete Prozesse gewartet...
make[2]: *** Keine Regel vorhanden, um das Ziel „/home/firesurfer/workspace/ros2_ws/src/ros2/common_interfaces/builtin_interfaces/ros2cs_message_generator“, 
benötigt von „CMakeFiles/generate_cs_messages_Time“, zu erstellen. Schluss.
CMakeFiles/Makefile2:1378: die Regel für Ziel „CMakeFiles/generate_cs_messages_Time.dir/all“ scheiterte
make[1]: *** [CMakeFiles/generate_cs_messages_Time.dir/all] Fehler 2

```

Only english (sry that I’m working on a german system) the error is (translated):

```
No rule exists to create the target „/home/firesurfer/workspace/ros2_ws/src/ros2/common_interfaces/builtin_interfaces/ros2cs_message_generator“, 
needed from „CMakeFiles/generate_cs_messages_Duration“, Exit.
CMakeFiles/Makefile2:520: the rule for target „CMakeFiles/generate_cs_messages_Duration.dir/all“ failed.

```

Then it says the same for the Time message.  
I’ve got absolutely no idea why everything works fine if I’m building without tests but fails with tests enabled.

---

<div class="post-metadata">

**Author:** ![dhood](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/dhood/32/1121_2.png) [@dhood](https://discourse.openrobotics.org/u/dhood)\
**Post date:** [November 8, 2016, 3:44am UTC](https://discourse.openrobotics.org/t/own-message-generator-and-building-tests/796/2 "2016-11-08T03:44:26Z")

</div>

When you build with `--build-tests`, the `BUILD_TESTING` cmake option is set to true.

From looking at your project, I think you are only appending the target to the list of message targets if `BUILD_TESTING` is true:

> <https://github.com/firesurfer/rosidl_generator_cs/blob/d1bcce9588b0b886355b087e80ae8f48ec976e80/cmake/rosidl_generator_cs_generate_interfaces.cmake#L30>

That might explain why it’s only failing when you build with `--build-testing`

As for why it’s failing, [the documentation for `add_custom_target`](https://cmake.org/cmake/help/v3.5/command/add_custom_target.html) says that `add_dependencies()` should be used instead of `DEPENDS` if you’re looking to add a dependency on another target, which looks to be your case with `ros2cs_message_generator` - not sure if that helps

---

<div class="post-metadata">

**Author:** ![firesurfer](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/firesurfer/32/11626_2.png) [@firesurfer](https://discourse.openrobotics.org/u/firesurfer)\
**Post date:** [November 8, 2016, 11:22am UTC](https://discourse.openrobotics.org/t/own-message-generator-and-building-tests/796/3 "2016-11-08T11:22:11Z")

</div>

Thanks a lot. Sometimes it’s hard to see the most obvious things. ` add_dependencies()` has by the way the same problem as the `DEPENDS` statement.  
I had to use this rather ugly solution:

```
 if(${PROJECT_NAME} STREQUAL "rosidl_generator_cs")
   add_dependencies(${MSG_TARGET_NAME} ros2cs_message_generator)
 endif()

```
