Out-of-tree uORB message definitions

Is it possible to have an out-of-tree msg directory that is also compiled in with the normal Firmware/msg directory?

In order to still keep rebasing “easy” when I rebase on the PX4/Firmware repo, I don’t want to make unnecessary changes within the Firmware files to get my stuff to compile. In the same way as one can add out-of-tree modules to the compilation, is it possible to add out-of-tree uORB message definitions?

What I have done until now is modified the Firmware/msg/CMakeLists.txt file and added the following line in order to allow me to somewhat achieve my goal, but it still feels a bit ‘hacked’:

add_subdirectory(<path_to_out_of_tree_msg_directory> ${CMAKE_CURRENT_BINARY_DIR}/<out_of_tree_msg/directory>)

And then in my out-of-tree msg directory I simply append to the msg_files variable that was set in Firmware/msg.CMakeLists. Contents of the out-of-tree msg CMakeLists

set(additional_msg_files
  message1.msg
  message2.msg
  message3.msg
)
  
# Add each of the external message files to the global msg_files list
foreach(additional_msg_file ${additional_msg_files})
	list(APPEND msg_files ${CMAKE_CURRENT_SOURCE_DIR}/${additional_msg_file})
endforeach()

# Set the msg_files variable in the parent scope to new msg_files list
set(msg_files ${msg_files} PARENT_SCOPE)

The rest of the compilation of the uORB headers and sources is then handled by the normal Firmware/msg/CMakeLists.txt file and the compiled messages appear in the /uORB/topics/ directory.

I’m also interested in better out-of-tree support (also for airframes, startup scripts etc).

What you did seems like it’s pretty much what’s needed.
What happens if the directory does not exist?

For out-of-tree modules, PX4 looks at an environment variable. Could you change your solution to work that way?

If so it would be great if you could create a pull request with those changes.

I have created a PR that makes use of the EXTERNAL_MODULES_LOCATION variable to find the out-of-tree message definitions. It assumes
that the message definition files are in $EXTERNAL_MODULES_LOCATION/msg.

The CMakeLists in the $EXTERNAL_MODULES_LOCATION /msg/ directory must have the following format:

set(config_msg_list_external
  <message1>.msg
  <message2>.msg
  <message3>.msg
  ...
  PARENT_SCOPE
  )

The uORB message headers are compiled in the usual <build_dir>/uORB/topics/ directory and the sources are generated in <build_dir>/msg/topics_sources/.

Very nice! Thanks a lot.