Skip to content

[Feature Request] Flexible CMake configuration #1382

@neuschwander-lmi

Description

@neuschwander-lmi

Is your feature request related to a problem? Please describe.
We have multiple CMake targets in one project, which build the same controller with different configurations.
Currently, FreeRTOS builds as a single static library with fixed configuration for each CMake invocation. This would require separate CMake build directories for different configurations.

This refers both to:

  • port selection via FREERTOS_PORT
  • configuration variables via linking to freertos_config and including FreeRTOSConfig.h

Describe the solution you'd like
Switch from STATIC and OBJECT libraries to INTERFACE libraries.
Different application configurations explicitly link against different ports or different config-INTERFACE-libraries. FreeRTOS itself does not explicitly link to port or config libraries.

Advantages:

  • Different application targets can use different freertos_config libraries
  • Different application targets can use different ports (e.g. one NS and one NTZ configuration)

Disadvantages:

  • As far as I understand, some headers are hidden from the application by not exposing their directories as target_include_dirs. This would not work when using the INTERFACE targets. However, this would remain effective when using the backwards-compatible mode.

Describe alternatives you've considered

  • Keeping local/internal patches
  • Writing own CMake code instead of using the provided one

How many devices will this feature impact?
I cannot disclose this information.

What are your project timelines?
I will implement a local/internal solution in the next few days. This issue is mostly an offer to integrate the local work upstream. Timeline for the PR would be ~1-4weeks.

Additional context
I am willing to provide a PR for this feature if the issue is accepted as a valid improvement.

Example usage:

// old:
if(CONFIG_SELECTION STREQUAL "NTZ")
        set(FREERTOS_PORT GCC_ARM_CM33_NTZ_NONSECURE)
        target_include_directories(freertos_config INTERFACE ${CMAKE_CURRENT_LIST_DIR}/config/ntz)
elseif(CONFIG_SELECTION STREQUAL "NS")
        set(FREERTOS_PORT GCC_ARM_CM33_NONSECURE)
        target_include_directories(freertos_config INTERFACE ${CMAKE_CURRENT_LIST_DIR}/config/ns)
endif()

target_link_libraries(myApp
        freertos_kernel
)

// cmake -DCONFIG_SELECTION=NTZ && cmake --build myApp
// cmake -DCONFIG_SELECTION=NS && cmake --build myApp

// new:
set(FREERTOS_PORTS GCC_ARM_CM33_NTZ_NONSECURE GCC_ARM_CM33_NONSECURE)
target_include_directories(freertos_config_ntz INTERFACE ${CMAKE_CURRENT_LIST_DIR}/config/ntz)
target_include_directories(freertos_config_ns INTERFACE ${CMAKE_CURRENT_LIST_DIR}/config/ns)

target_link_libraries(myApp_NTZ
        freertos_config_ntz
        freertos_kernel_port_GCC_ARM_CM33_NTZ_NONSECURE
)
target_link_libraries(myApp_NS
        freertos_config_ns
        freertos_kernel_port_GCC_ARM_CM33_NONSECURE
)

// cmake && cmake --build myApp_NTZ myApp_NS

Example port definition in portable/CMakeLists.txt

addPort(GCC_ARM_CM33_NTZ_NONSECURE
        WITH_MPU_WRAPPERS
        SOURCES
        GCC/ARM_CM33_NTZ/non_secure/port.c
        GCC/ARM_CM33_NTZ/non_secure/portasm.c
        GCC/ARM_CM33_NTZ/non_secure/mpu_wrappers_v2_asm.c
        INCLUDE_DIRS
        ${CMAKE_CURRENT_LIST_DIR}/GCC/ARM_CM33_NTZ/non_secure
)

CMake interface changes:

  • Add a configuration variable FREERTOS_PORTS which is a list of all ports which should be available (not all ports can be used with the same compiler). Only the ports which are linked against will actually get built.
  • For each entry in FREERTOS_PORTS, there will be a corresponding freertos_kernel_port_* INTERFACE target

Backwards compatibility:

  • If FREERTOS_PORTS is not defined, it defaults to a list with one item equal to FREERTOS_PORT to make the use of multi-ports optional.
  • add_library(freertos_kernel STATIC) links against freertos_config and freertos_kernel_port_${FREERTOS_PORT} if FREERTOS_PORT is defined to make the use of interface targets optional.

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