Skip to content

Commit

Permalink
G3P-7233: Convert library to Interface target for new build configura…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
ellie-dojofive committed Oct 31, 2024
1 parent 834e8ab commit 9ec86b6
Show file tree
Hide file tree
Showing 5 changed files with 581 additions and 497 deletions.
28 changes: 21 additions & 7 deletions CMSIS/RTOS2/FreeRTOS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
# defines library FW3_CMSIS_TARGET

add_library(FW3_CMSIS_TARGET)
function(generate_freertos_cmsis
SUFFIX)

add_library(CMSIS_RTOS2_FreeRTOS-${SUFFIX} INTERFACE)

add_library(ThirdParty::ARM::RTOS2::FreeRTOS::${SUFFIX} ALIAS CMSIS_RTOS2_FreeRTOS-${SUFFIX})

target_sources(
FW3_CMSIS_TARGET
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Source/cmsis_os2.c
${CMAKE_CURRENT_SOURCE_DIR}/Source/freertos_evr.c
${CMAKE_CURRENT_SOURCE_DIR}/Source/os_systick.c
${CMAKE_CURRENT_SOURCE_DIR}/Source/ARM/clib_arm.c)
CMSIS_RTOS2_FreeRTOS-${SUFFIX}
INTERFACE ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Source/cmsis_os2.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Source/freertos_evr.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Source/os_systick.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Source/ARM/clib_arm.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Source/cmsis_os1.c)

set_source_files_properties(${FW3_CMSIS_DIR}/Source/cmsis_os1.c
target_include_directories(CMSIS_RTOS2_FreeRTOS-${SUFFIX} INTERFACE
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Include
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Include1
)

set_source_files_properties(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Source/cmsis_os1.c
PROPERTIES COMPILE_OPTIONS -Wno-switch-enum)

endfunction()
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.30)

function(generate_freertos_libs
SUFFIX
FREERTOS_CONFIG_LIBRARY
FREERTOS_PORT)

add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/Source ${CMAKE_CURRENT_BINARY_DIR}/${SUFFIX}/FreeRtosSource)
add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/CMSIS/RTOS2/FreeRTOS
${CMAKE_CURRENT_BINARY_DIR}/${SUFFIX}/FreeRtosCmsis)

generate_freertos_cmsis(${SUFFIX})
generate_freertos_kernel(${SUFFIX} ${FREERTOS_CONFIG_LIBRARY} ${FREERTOS_PORT})

target_link_libraries(CMSIS_RTOS2_FreeRTOS-${SUFFIX} INTERFACE freertos_kernel-${SUFFIX})

endfunction()


83 changes: 53 additions & 30 deletions Source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
cmake_minimum_required(VERSION 3.15)
cmake_minimum_required(VERSION 3.20)

# User is responsible to set two mandatory options:
# FREERTOS_CONFIG_FILE_DIRECTORY
# FREERTOS_PORT
function(generate_freertos_kernel
SUFFIX
FREERTOS_CONFIG_LIBRARY
FREERTOS_PORT)
# User is responsible to one mandatory option:
# FREERTOS_PORT, if not specified and native port detected, uses the native compile.
#
# User is responsible for one library target:
# ${FREERTOS_CONFIG_LIBRARY} ,typcially an INTERFACE library
#
# DEPRECATED: FREERTOS_CONFIG_FILE_DIRECTORY - but still supported if no ${FREERTOS_CONFIG_LIBRARY} defined for now.
# May be removed at some point in the future.
# User can choose which heap implementation to use (either the implementations
# included with FreeRTOS [1..5] or a custom implementation ) by providing the
# option FREERTOS_HEAP. If the option is not set, the cmake will default to
Expand All @@ -12,17 +20,28 @@ cmake_minimum_required(VERSION 3.15)
# Absolute path to FreeRTOS config file directory
#set(FREERTOS_CONFIG_FILE_DIRECTORY "" CACHE STRING "Absolute path to the directory with FreeRTOSConfig.h")

if(NOT FREERTOS_CONFIG_FILE_DIRECTORY)
message(FATAL_ERROR " FreeRTOSConfig.h file directory not specified. Please specify absolute path to it from top-level CMake file:\n"
" set(FREERTOS_CONFIG_FILE_DIRECTORY <absolute path to FreeRTOSConfig.h directory> CACHE STRING \"\")\n"
" or from CMake command line option:\n"
" -DFREERTOS_CONFIG_FILE_DIRECTORY='/absolute_path/to/FreeRTOSConfig.h/directory'")
elseif(NOT EXISTS ${FREERTOS_CONFIG_FILE_DIRECTORY}/FreeRTOSConfig.h)
message(FATAL_ERROR " FreeRTOSConfig.h file not found in the directory specified (${FREERTOS_CONFIG_FILE_DIRECTORY})\n"
" Please specify absolute path to it from top-level CMake file:\n"
" set(FREERTOS_CONFIG_FILE_DIRECTORY <absolute path to FreeRTOSConfig.h directory> CACHE STRING \"\")\n"
" or from CMake command line option:\n"
" -DFREERTOS_CONFIG_FILE_DIRECTORY='/absolute_path/to/FreeRTOSConfig.h/directory'")
# `${FREERTOS_CONFIG_LIBRARY}` target defines the path to FreeRTOSConfig.h and optionally other freertos based config files
if(NOT TARGET ${FREERTOS_CONFIG_LIBRARY} )
if (NOT DEFINED FREERTOS_CONFIG_FILE_DIRECTORY )

message(FATAL_ERROR " freertos_config target not specified. Please specify a cmake target that defines the include directory for FreeRTOSConfig.h:\n"
" add_library(freertos_config INTERFACE)\n"
" target_include_directories(freertos_config SYSTEM\n"
" INTERFACE\n"
" include) # The config file directory\n"
" target_compile_definitions(freertos_config\n"
" PUBLIC\n"
" projCOVERAGE_TEST=0)\n")
else()
message(WARNING " Using deprecated 'FREERTOS_CONFIG_FILE_DIRECTORY' - please update your project CMakeLists.txt file:\n"
" add_library(freertos_config INTERFACE)\n"
" target_include_directories(freertos_config SYSTEM\n"
" INTERFACE\n"
" include) # The config file directory\n"
" target_compile_definitions(freertos_config\n"
" PUBLIC\n"
" projCOVERAGE_TEST=0)\n")
endif()
endif()

# Heap number or absolute path to custom heap implementation provided by user
Expand Down Expand Up @@ -184,25 +203,29 @@ if(NOT FREERTOS_PORT)
" WIZC_PIC18 - Compiller: WizC Target: PIC18")
endif()

add_subdirectory(portable)
add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/${SUFFIX}/FreeRtosInclude)
add_subdirectory(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/portable ${CMAKE_CURRENT_BINARY_DIR}/${SUFFIX}/FreeRtosPort)

add_library(freertos_kernel STATIC
croutine.c
event_groups.c
list.c
queue.c
stream_buffer.c
tasks.c
timers.c
add_library(freertos_kernel-${SUFFIX} INTERFACE)

target_sources(freertos_kernel-${SUFFIX} INTERFACE
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/croutine.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/event_groups.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/list.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/queue.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/stream_buffer.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/tasks.c
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/timers.c

# If FREERTOS_HEAP is digit between 1 .. 5 - it is heap number, otherwise - it is path to custom heap source file
$<IF:$<BOOL:$<FILTER:${FREERTOS_HEAP},EXCLUDE,^[1-5]$>>,${FREERTOS_HEAP},portable/MemMang/heap_${FREERTOS_HEAP}.c>
)

target_include_directories(freertos_kernel
PUBLIC
include
${FREERTOS_CONFIG_FILE_DIRECTORY}
)
generate_freertos_kernel_include(${SUFFIX} ${FREERTOS_CONFIG_LIBRARY})
generate_freertos_kernel_port(${SUFFIX} ${FREERTOS_PORT} freertos_kernel-${SUFFIX})

target_link_libraries(freertos_kernel-${SUFFIX} INTERFACE freertos_kernel_port-${SUFFIX} freertos_kernel_include-${SUFFIX})

add_library(ThirdParty::FreeRTOS::Kernel::${SUFFIX} ALIAS freertos_kernel-${SUFFIX})

target_link_libraries(freertos_kernel freertos_kernel_port)
endfunction()
21 changes: 21 additions & 0 deletions Source/include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# FreeRTOS internal cmake file. Do not use it in user top-level project

function(generate_freertos_kernel_include
SUFFIX
FREERTOS_CONFIG_LIBRARY)

add_library(freertos_kernel_include-${SUFFIX} INTERFACE)

target_include_directories(freertos_kernel_include-${SUFFIX}
INTERFACE
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
# Note: DEPRECATED but still supported, may be removed in a future release.
$<$<NOT:$<TARGET_EXISTS:${FREERTOS_CONFIG_LIBRARY}>>:${FREERTOS_CONFIG_FILE_DIRECTORY}>
)

target_link_libraries(freertos_kernel_include-${SUFFIX}
INTERFACE
$<$<TARGET_EXISTS:${FREERTOS_CONFIG_LIBRARY}>:${FREERTOS_CONFIG_LIBRARY}>
)

endfunction()
Loading

0 comments on commit 9ec86b6

Please sign in to comment.