C
Qt Quick Ultralite freertos_app_switch Example
cmake_minimum_required (VERSION 3.21.1)
project(freertos_app_switch VERSION 0.0.1 LANGUAGES C CXX ASM)
if (NOT TARGET Qul::Core)
    find_package(Qul)
endif()
if(QUL_PLATFORM STREQUAL "qt" OR QUL_PLATFORM STREQUAL "example-baremetal")
    message(STATUS "Skipping freertos_app_switch.")
elseif(NOT QUL_OS STREQUAL "FreeRTOS")
    message(STATUS "Operating system is not FreeRTOS. Skipping freertos_app_switch.")
else()
    add_library(app_switch_freertos_kernel STATIC)
    target_link_libraries(app_switch_freertos_kernel
        PRIVATE
            Qul::PlatformArchitecture
            Qul::PlatformBSPConfig
    )
    # Enforce symbols to be put in the binary, otherwise LTO will strip them
    if(NOT IAR)
        target_link_libraries(app_switch_freertos_kernel PRIVATE -Wl,-u,vTaskSwitchContext)
    endif()
    target_include_directories(app_switch_freertos_kernel PUBLIC ${QUL_PLATFORM_TARGET_DIR})
    if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/freertos/${QUL_PLATFORM}/freertos.cmake)
        include(${CMAKE_CURRENT_LIST_DIR}/freertos/${QUL_PLATFORM}/freertos.cmake)
    endif()
    target_compile_definitions(app_switch_freertos_kernel PRIVATE USE_FreeRTOS_HEAP_4)
    # Add common sources
    target_sources(app_switch_freertos_kernel PRIVATE
        ${FREERTOS_DIR}/portable/MemMang/heap_4.c
    )
endif()
if(TARGET app_switch_freertos_kernel) # FreeRTOS support implemented for this platform
    qul_add_target(freertos_app_switch
        src/main.cpp
        src/devcontrol.cpp
        QML_PROJECT
        mcu_freertos_app_switch.qmlproject
    )
    target_link_libraries(freertos_app_switch
        PRIVATE
            Qul::PlatformBSPConfig
            app_switch_freertos_kernel
    )
    include(src/${QUL_PLATFORM}/board.cmake)
endif()