Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G3P-7233: Convert library to Interface target for new build configuration #13

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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)

zhixuenlai marked this conversation as resolved.
Show resolved Hide resolved
# 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}, typically 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()
5 changes: 0 additions & 5 deletions Source/include.cmake

This file was deleted.

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
Loading