Adding custom actions to rosbuild

I've got a package defining messages for rosserial. After changing a message, I need to deploy (copy) the changes to a folder containing generated messages for an Arduino board. Is there a (clean) way to add custom actions to the rosbuild system? For now I'm assuming I could modify Makefile in my message-defining-package adding the actions I need after the call:

include $(shell rospack find mk)/cmake.mk

but won't it get overwritten in some case and is it the right way to do it? I've got a deploy script and would like to call it from somewhere.

Comments

Note that `execute_process()` will run in-place when the CMakeLists.txt file is parsed, before the build happens. If you would rather arrange for the command to run later, during/after the build, see my answer on using `add_custom_target()`.

Actually I just tested it again to make sure and executing make on my message-package causes correct behaviour, ie. all generated messages get copied after being built. I added my deploy script at the end of CMakeLists.txt.

# Declare a custom target that will do the copy when the 'all' target fires
add_custom_target(deploy ALL
COMMAND cp $(CMAKE_SOURCE_DIR)/undeployed /tmp/deployed)
# Declare a dependency on the 'rosbuild_precompile' target, to ensure
# that message generation happens before we copy.
add_dependencies(deploy rosbuild_precompile)