How to Configure FreeRTOS Includes with a "Custom Prefix"?

Hello everyone,

I’m using the FreeRTOS-Kernel in my project and managing it with FetchContent in CMake. Everything is working fine, but I’d like to configure the way I include FreeRTOS headers for clarity and to avoid potential naming conflicts with other libraries.

Currently, I include headers like this:

#include <timers.h>
#include <task.h>

However, I’d like to make it more explicit that these headers are part of FreeRTOS by including them with a prefix, like this:

e.g.

#include <freertos-kernel-src/include/timers.h>
#include <freertos-kernel-src/include/task.h>

Reasons for Doing This

  1. Prevent Naming Conflicts: To avoid clashes with similarly named headers from other libraries.
  2. Improve Readability: To make it clear in the code that these are FreeRTOS headers.

My Setup

  • I use the FreeRTOS CMakeLists.txt files directly (via FetchContent) without modifying them.
  • My project structure is standard, with FreeRTOS headers located under freertos-kernel-src/include.

My Question

How can I configure my project to achieve this header inclusion format without modifying the FreeRTOS repository or its CMake files? Ideally, I want this to be done in my own project’s CMakeLists.txt.

Has anyone faced a similar issue or found a clean solution for this?

Thanks in advance for your help!

Assuming that you are talking about including FreeRTOS header files in your application, you should be able to do the following in your application CMakeLists.txt:

target_include_directories( app
                            PRIVATE
                            $ROOT_DIR
                          )

where:

  • app is you application target.
  • ROOT_DIR is the location of freertos-kernel-src.

Does that work?

You may need your include paths to include both the path you want to include from (i.e. the directory freertos-kernel-src is in) as well as the FreeRTOS include directory directly.