# Out-of-tree uORB message definitions

**URL:** <https://discuss.px4.io/t/out-of-tree-uorb-message-definitions/6001>\
**Category:** Uncategorized\
**Created:** [March 13, 2018, 8:56am UTC](https://discuss.px4.io/t/out-of-tree-uorb-message-definitions/6001 "2018-03-13T08:56:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ksschwabe](https://discuss.px4.io/letter_avatar_proxy/v4/letter/k/b782af/32.png) [@ksschwabe](https://discuss.px4.io/u/ksschwabe)\
**Post date:** [March 13, 2018, 8:56am UTC](https://discuss.px4.io/t/out-of-tree-uorb-message-definitions/6001/1 "2018-03-13T08:56:51Z")

</div>

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’:

```auto
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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Nicolas](https://discuss.px4.io/user_avatar/discuss.px4.io/nicolas/32/4467_2.png) [@Nicolas](https://discuss.px4.io/u/Nicolas)\
**Post date:** [March 13, 2018, 9:14am UTC](https://discuss.px4.io/t/out-of-tree-uorb-message-definitions/6001/2 "2018-03-13T09:14:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ksschwabe](https://discuss.px4.io/letter_avatar_proxy/v4/letter/k/b782af/32.png) [@ksschwabe](https://discuss.px4.io/u/ksschwabe)\
**Post date:** [March 13, 2018, 11:08pm UTC](https://discuss.px4.io/t/out-of-tree-uorb-message-definitions/6001/3 "2018-03-13T23:08:06Z")

</div>

I have created a [PR](https://github.com/PX4/Firmware/pull/9073) 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:

```auto
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/`.

---

<div class="post-metadata">

**Author:** ![Nicolas](https://discuss.px4.io/user_avatar/discuss.px4.io/nicolas/32/4467_2.png) [@Nicolas](https://discuss.px4.io/u/Nicolas)\
**Post date:** [March 14, 2018, 7:56am UTC](https://discuss.px4.io/t/out-of-tree-uorb-message-definitions/6001/4 "2018-03-14T07:56:29Z")

</div>

Very nice! Thanks a lot.
