I’m wondering if it is worth redesigning the way FreeRTOS is being consumed by CMake projects. Currently, I’m only allowed to have a single configuration for the entire project. I have to specify the config library, port, and memory management strategy before I even call add_subdirectory() in CMake. If I have a multi-target project ( various targets with different cores ) and I want them to use the same RTOS files, my only option is to reconfigure the entire project for each case… Wouldn’t it be a much more “elastic” approach if the kernel, (each)port, and memory management files were simply interface libraries so each of CMake targets will only have to link the libraries they need, and each target will define its own compile options? Are there any constraints to that?
For example, I will be able to do something like this:
Hi @eMKa94,
IMHO, the idea should work but your proposal may not work as your expectation. To build FreeRTOS files as library, you have to provide several customized files, such as port, config files, etc. Those customized files make it not possible to build single library for different targets. Instead, you still need to have multiple freertos libraries for different targets to include different customized files.
Thank you.
For example:
set( FREERTOS_KERNEL_COMMON_SOURCES
# common source files )
set( FREERTOS_KERNEL_COMMON_INCLUDE_PATH
# common include path )
# CM0
add_library( freertos_kernel_CM0 )
target_sources( freertos_kernel_CM0
${FREERTOS_KERNEL_COMMON_SOURCES}
# other files, like memory management, port files, FreeRTOS config file )
target_include_directories( freertos_kernel_CM0
${FREERTOS_KERNEL_COMMON_INCLUDE_PATH}
# other include paths
)
target_link_libraries(MY_CM0_target PRIVATE freertos_kernel_CM0 )
# CM4
add_library( freertos_kernel_CM4 )
target_sources( freertos_kernel_CM4
${FREERTOS_KERNEL_COMMON_SOURCES}
# other files, like memory management, port files, FreeRTOS config file )
target_include_directories( freertos_kernel_CM4
${FREERTOS_KERNEL_COMMON_INCLUDE_PATH}
# other include paths
)
target_link_libraries(MY_CM4_target PRIVATE freertos_kernel_CM4 )
I’m aware that i need multiple instances. The problem i wanted to solve is that with default CMake for FreeRTOS the configuration for particular port / heap is based on CMake variables which needs to be set before call to add_subdirectory(FreeRTOS). And also OBJECT library is being created so it is compiled once per configuration. In such case I cannot compile FreeRTOS sources for multiple targets in single CMake build process. I have to reconfigure whole project and build all code again for each target…
I’ve changed library type to INTERFACE for the kernel, and create a small ones for port, and heap libraries so they are not being compiled as separated libraries but become sources of target that consumes them as libraries.
As U can see now each my target is able to pick the correct heap / port sources and provide specific set of compile options. IMO much better usage then the original one.