Say I have two catkin packages, foo
and foo_msgs
, in my workspace. Here‘s how I currently have them set up:
project(foo_msgs) find_package(catkin REQUIRED COMPONENTS message_generation) add_message_files( DIRECTORY msg FILES foomsg.msg ) generate_messages() catkin_package(CATKIN_DEPENDS message_runtime)
project(foo) find_package(catkin REQUIRED COMPONENTS foo_msgs) catkin_package() include_directories(include ${catkin_INCLUDE_DIRS}) add_executable(foo foo.cpp)
I find that if I catkin_make foo
, the message isn‘t generated. Indeed,
catkin_make foo_msgs
is a no-op. catkin_make foo_msgs_gencpp
works, however. In order to get
foo
to build correctly, I must add the following line to its CMakeLists.txt
:
add_dependencies(foo foo_msgs_gencpp)
Is this by design? I‘d expect that building the package foo_msgs
would automatically generate all its messages. Is there a way to make that happen?
Edit: I‘ve approved WilliamWoodall‘s answer, although KruseT‘s was just as useful. (I also added the
include_directories()
line to foo
‘s CMakeLists.txt
, which I initially forgot.)
It turns out my solution is correct; the foo_msgs_gencpp
auto-target should be added as a dependency of the
foo
target. Note that there is some disagreement about whether a different solution should be supported by catkin; KruseT started a discussion on the topic
here.
Since this type of explicit dependency auto-target (_gencpp
and
_genpy
) is necessary for using ROS messages/actions/services in any executable, library, or script, I think it should be better documented (I found no reference to it in
catkin/migrating_from_rosbuild). KruseT opened a related rosdistro issue
here.