Skip to content

[Feature Request] CMakeLists.txt improvements for better Project integration and maintenance of portable(s) #558

Closed
@phelter

Description

@phelter

Problem:

The method of using FREERTOS_CONFIG_FILE_DIRECTORY limits the integration and what is included in the FreeRTOSConfig.h file.

With this method a user of FreeRTOS-Kernel cannot include or link other libraries into the FreeRTOSConfig.h file:

One example would be to include a local file for the project:

// FreeRTOSConfig.h file
#include "project_settings.h"  # This is in a different directory.

Solution:
Suggest using an assumed name for a target eg : FreeRTOS::config that is included in all of the freertos_* libs etc.

An example integration with the project would be - where all of the FreeRTOS based config files would reside: project_config
The project_config target would provide location to where where FreeRTOSConfig.h and all other FreeRTOS submodule config files reside.

# Toplevel or Project CMakeLists.txt
add_library(project_config INTERFACE)

target_include_directories( project_config
  INTERFACE
    include
)

And the only thing you would need to have defined in your project is something like:

# Add this line to the target that publicizes the FreeRTOS configuration files.
add_library(FreeRTOS::config ALIAS project_config)

And in all of the libraries that are in the CMakeLists.txt - these would have eg: here for freertos_kernel

target_link_libraries(freertos_kernel 
  PUBLIC
    FreeRTOS::config
    freertos_kernel_port
)

And remove the use of FREERTOS_CONFIG_FILE_DIRECTORY in the target_include_directories

Alternatives:
Alternative solution:
I currently copy the CMakeLists.txt into a separate directory under my project directory, modify them with the above changes and then use

config_file(<local cmake file>  <Dir with FreeRTOS code and CMakeLists.txt> COPYONLY)

To overwrite the existing CMakeLists.txt inside the FreeRTOS directory, but this is only to workaround the limitation of defining a FreeRTOS::config target.

How many devices will this feature impact?
N/A - used for compile.

What are your project timelines?
N/A - using Alternative workaround for now.

Additional context
None.

Would also suggest doing this for the portable freertos_kernel_port target as well.
Per portable/* directory have a CMakeLists.txt file and partition the monolithic portable/CMakeLists.txt into their own directories - so they are unique to each of those. This would also simplify the portable.

An example CMakeLists.txt file for the portable directories:

# portable/GCC/ARM_CA9/CMakeLists.txt

add_library(freertos_kernel_port_GCC_ARM_CA9 STATIC EXCLUDE_FROM_ALL)

target_sources(freertos_kernel_port_GCC_ARM_CA9
  PRIVATE
      port.c
      portASM.S
      portmacro.h
)

target_include_directories(freertos_kernel_port_GCC_ARM_CA9
  PUBLIC
     .
)

target_link_libraries(freertos_kernel_port_GCC_ARM_CA9
  PRIVATE
     freertos_kernel
)

And then in the portable/CMakeLists.txt
This just includes all of the port directories - they won't compile unless they are used due to the EXCLUDE_FROM_ALL option.
If you still want tosupport FREERTOS_PORT - then you can have a single large case statement

if(NOT TARGET freertos_kernel_port)
    add_library(freertos_kernel_port ALIAS
            $<$<STREQUAL:${FREERTOS_PORT},BCC_16BIT_DOS_FLSH186>:freertos_kernel_port_BCC_16BIT_DOS_FLSH186>
            #...
            $<$<STREQUAL:${FREERTOS_PORT},GCC_ARM_CA9>:freertos_kernel_port_GCC_ARM_CA9>
            #...
           $<$<STREQUAL:${FREERTOS_PORT},WIZC_PIC18>:freertos_kernel_port_WIZC_PIC18>
     )
else()
    message(STATUS "freertos_kernel_port already defined - using that.")
endif()

For the FreeRTOS-Kernel/CMakeLists.txt check for FREERTOS_PORT this changes to:

if(NOT TARGET freertos_kernel_port)
    message(FATAL_ERROR " `freertos_kernel_port library alias is not defined. Please specify it from top-level CMake file (example):\n"
        "  add_library(freertos_kernel_port ALIAS freertos_kernel_port_GCC_ARM_CM4F)\n"
        " or from CMake command line option:\n"
        "  -DFREERTOS_PORT=GCC_ARM_CM4F\n"
        " \n"
        " Available port options:\n"
          #...)
endif()

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions