# messages from subfolders

Hi, I'm writing a Package, that has to contain multiple message definitions. In order to manage the amount I divided the messages in subfolders:

/msg/test
/msg/test2

test/test_msg.msg
)

However: I still have to list every .msg in add_message_files. Is there a way to add whole folders? (Every .msg in a particular subfolder of /msg?

cheers

edit retag close merge delete

Sort by » oldest newest most voted

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

more