xref: /Kernel-v10.6.2/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake (revision 01820d3ed93c735e5e8460a282971a7725fae44c)
1# This is a copy of <FREERTOS_KERNEL_PATH>/portable/ThirdParty/GCC/RP2040/FREERTOS_KERNEL_import.cmake
2
3# This can be dropped into an external project to help locate the FreeRTOS kernel
4# It should be include()ed prior to project(). Alternatively this file may
5# or the CMakeLists.txt in this directory may be included or added via add_subdirectory
6# respectively.
7
8if (DEFINED ENV{FREERTOS_KERNEL_PATH} AND (NOT FREERTOS_KERNEL_PATH))
9    set(FREERTOS_KERNEL_PATH $ENV{FREERTOS_KERNEL_PATH})
10    message("Using FREERTOS_KERNEL_PATH from environment ('${FREERTOS_KERNEL_PATH}')")
11endif ()
12
13set(FREERTOS_KERNEL_RP2040_RELATIVE_PATH "portable/ThirdParty/GCC/RP2040")
14# undo the above
15set(FREERTOS_KERNEL_RP2040_BACK_PATH "../../../..")
16
17if (NOT FREERTOS_KERNEL_PATH)
18    # check if we are inside the FreeRTOS kernel tree (i.e. this file has been included directly)
19    get_filename_component(_ACTUAL_PATH ${CMAKE_CURRENT_LIST_DIR} REALPATH)
20    get_filename_component(_POSSIBLE_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH} REALPATH)
21    if (_ACTUAL_PATH STREQUAL _POSSIBLE_PATH)
22        get_filename_component(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH} REALPATH)
23    endif()
24    if (_ACTUAL_PATH STREQUAL _POSSIBLE_PATH)
25        get_filename_component(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH} REALPATH)
26        message("Setting FREERTOS_KERNEL_PATH to ${FREERTOS_KERNEL_PATH} based on location of FreeRTOS-Kernel-import.cmake")
27    elseif (PICO_SDK_PATH AND EXISTS "${PICO_SDK_PATH}/../FreeRTOS-Kernel")
28        set(FREERTOS_KERNEL_PATH ${PICO_SDK_PATH}/../FreeRTOS-Kernel)
29        message("Defaulting FREERTOS_KERNEL_PATH as sibling of PICO_SDK_PATH: ${FREERTOS_KERNEL_PATH}")
30    endif()
31endif ()
32
33if (NOT FREERTOS_KERNEL_PATH)
34    foreach(POSSIBLE_SUFFIX Source FreeRTOS-Kernel FreeRTOS/Source)
35        # check if FreeRTOS-Kernel exists under directory that included us
36        set(SEARCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
37        get_filename_component(_POSSIBLE_PATH ${SEARCH_ROOT}/${POSSIBLE_SUFFIX} REALPATH)
38        if (EXISTS ${_POSSIBLE_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/CMakeLists.txt)
39            get_filename_component(FREERTOS_KERNEL_PATH ${_POSSIBLE_PATH} REALPATH)
40            message("Setting FREERTOS_KERNEL_PATH to '${FREERTOS_KERNEL_PATH}' found relative to enclosing project")
41            break()
42        endif()
43    endforeach()
44endif()
45
46if (NOT FREERTOS_KERNEL_PATH)
47    message(FATAL_ERROR "FreeRTOS location was not specified. Please set FREERTOS_KERNEL_PATH.")
48endif()
49
50set(FREERTOS_KERNEL_PATH "${FREERTOS_KERNEL_PATH}" CACHE PATH "Path to the FreeRTOS Kernel")
51
52get_filename_component(FREERTOS_KERNEL_PATH "${FREERTOS_KERNEL_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
53if (NOT EXISTS ${FREERTOS_KERNEL_PATH})
54    message(FATAL_ERROR "Directory '${FREERTOS_KERNEL_PATH}' not found")
55endif()
56if (NOT EXISTS ${FREERTOS_KERNEL_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}/CMakeLists.txt)
57    message(FATAL_ERROR "Directory '${FREERTOS_KERNEL_PATH}' does not contain an RP2040 port here: ${FREERTOS_KERNEL_RP2040_RELATIVE_PATH}")
58endif()
59set(FREERTOS_KERNEL_PATH ${FREERTOS_KERNEL_PATH} CACHE PATH "Path to the FreeRTOS_KERNEL" FORCE)
60
61add_subdirectory(${FREERTOS_KERNEL_PATH}/${FREERTOS_KERNEL_RP2040_RELATIVE_PATH} FREERTOS_KERNEL)
62