Generating a .msg file dynamically at build time
I have a non-ROS type definition file and a tool that translates these definitions to .msg files. I would catkin
to first run the translation to produce the .msgs, and then add them to the package.
My attempt looked something like this:
set(GENERATED_MSGS_DIR "${CMAKE_CURRENT_BINARY_DIR}/msg")
add_custom_command(
OUTPUT ${GENERATED_MSGS_DIR}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/translate.py
-o ${GENERATED_MSGS_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/types.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
file(GLOB_RECURSE GENERATED_MSG_FILES RELATIVE ${GENERATED_MSGS_DIR} *.msg)
add_message_files(FILES ${GENERATED_MSG_FILES})
generate_messages()
However this doesn't quite work. CMake will only run the custom command if an output file is needed by a target that gets built. In this case, I don't know the name of the .msg files that will come out of the translator, just the directory they'll be added to. And add_message_files
also doesn't seem to like getting files outside of the package's msg
directory.
As an alternative I could have the translate script produce a complete ROS package, if there's a way to dynamically add that package directory as a dependency.