When to use the dependency EXPORTED_TARGETS vs generate_messages_cpp
Let's suppose pkg1 creates new services, messages, and actions. If I want a cpp ROS node from within this pkg1 to ensure that the messages, services, and actions are all built before the cpp file is built, would I add: add_dependencies(cpp_file_target pkg1_EXPORTED_TARGETS) or add_dependencies(cpp_file_target pkg1_generate_messages_cpp)? Really, what's the difference in this case?
Additionally, if pkg2 wanted to use messages from pkg1, and find_package() included pkg1, would a dependency on ${catkin_EXPORTED_TARGETS} be sufficient? Or would pkg2 need to depend on pkg1_generate_messages_cpp?
I wasn't able to find a clear answer within the documentation and would appreciate guidance for best practices.
I seem to remember this has been discussed before. See #q286311, #q201227 and #q52744 for instance. The second Q&A links to relevant documentation. The third Q&A's accepted answer has a bunch of comments which go into some more detail, and the second answer is the preferred way of doing things "nowadays" (note: the third Q&A is from 2013).
If you could read those (and perhaps find some additional info, use Google, append
site:answers.ros.org
to your query), and things are still unclear, please update your question and explain what is unclear exactly.Let's try to avoid duplicating discussions.
Thanks for the tip. This additional discussion along with your links answered my question: