ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Looking at the docs for genmsg (where add_message_files(..) is coming from) and at the code (specifically: here) it would seem that if you only pass the DIRECTORY argument to add_message_files(..) it will search for .msg files in that directory. So that would remove the need to list all files explicitly.

I'm not sure whether it does that recursively though (most likely not), so that would require calling add_message_files(DIRECTORY ..) multiple times (once for each subdir of $pkg_dir/msg in your specific case) and I don't know whether that is supported.

Note btw that this 'auto-discovery of msg files' uses GLOB-ing, which is sort-of frowned upon in the CMake community (see on stackoverflow fi).


As an aside: making things explicit in software (engineering) is actually a good thing, as it avoids depending on implicit assumptions in your components (ie: "message my_message.msg will be there, as it is in the directory I have catkin search for messages"). If you GLOB, a missing msg file will cause an error at a much later time (while compiling any sources depending on the message) than if you explicitly listed it (existence of .msg files is checked at configuration time here) and it will also be more easily understood (ie: message file not found vs some/path/to/my_source.cpp:LINE:CHAR: fatal error: my_msgs/my_msg.h: No such file or directory which can also be caused by missing or misstated dependencies).

Looking at the docs for genmsg (where add_message_files(..) is coming from) and at the code (specifically: here) it would seem that if you only pass the DIRECTORY argument to add_message_files(..) it will search for .msg files in that directory. So that would remove the need to list all files explicitly.

I'm not sure whether it does that recursively though (most likely not), not, as GLOB_RECURSE is not used), so that would require calling add_message_files(DIRECTORY ..) multiple times (once for each subdir of $pkg_dir/msg in your specific case) and I don't know whether that is supported.

Note btw that this 'auto-discovery of msg files' uses GLOB-ing, which is sort-of frowned upon in the CMake community (see on stackoverflow fi).


As an aside: making things explicit in software (engineering) is actually a good thing, as it avoids depending on implicit assumptions in your components (ie: "message my_message.msg will be there, as it is in the directory I have catkin search for messages"). If you GLOB, a missing msg file will cause an error at a much later time (while compiling any sources depending on the message) than if you explicitly listed it (existence of .msg files is checked at configuration time here) and it will also be more easily understood (ie: message file not found vs some/path/to/my_source.cpp:LINE:CHAR: fatal error: my_msgs/my_msg.h: No such file or directory which can also be caused by missing or misstated dependencies).

Looking at the docs for genmsg (where add_message_files(..) is coming from) and at the code (specifically: here) it would seem that if you only pass the DIRECTORY argument to add_message_files(..) it will search for .msg files in that directory. So that would remove the need to list all files explicitly.

I'm not sure whether it does that recursively though (most likely not, as GLOB_RECURSE is not used), so that would require calling add_message_files(DIRECTORY ..) multiple times (once for each subdir of $pkg_dir/msg in your specific case) and I don't know whether that is supported.

Note btw that this 'auto-discovery of msg files' uses GLOB-ing, which is sort-of frowned upon in the CMake community (see Best way to specify sourcefiles in CMake on stackoverflow fi).


As an aside: making things explicit in software (engineering) is actually a good thing, as it avoids depending on implicit assumptions in your components (ie: "message my_message.msg will be there, as it is in the directory I have catkin search for messages"). If you GLOB, a missing msg file will cause an error at a much later time (while compiling any sources depending on the message) than if you explicitly listed it (existence of .msg files is checked at configuration time here) and it will also be more easily understood (ie: message file not found vs some/path/to/my_source.cpp:LINE:CHAR: fatal error: my_msgs/my_msg.h: No such file or directory which can also be caused by missing or misstated dependencies).