Own message generator and building tests

For my C# wrapper I wrote my own message generator and implemented a rosidl_generator_cs package ( 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.

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:

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

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()