#THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE!
cmake_minimum_required(VERSION 3.23)


#/////////////////////////////////////////////PLEASE CHOOSE THIS OPTIONS BY YOURSELF
set(MCU "STM32G070xx")
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32G070CBTX_FLASH.ld)
set(FREERTOS_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/main_prog/Core/Inc/FreeRTOSConfig.h")
#/////////////////////////////////////////////

string (SUBSTRING "${MCU" 0 7 MCU_SERIES)
string(APPEND MCU_SERIES "XX")
if(${MCU_SERIES} MATCHES  "STM32F4|STM32F3|STM32WB|STM32WL|STM32L4|STM32WB|STM32WL|STM32G4")
    set(CORTEX-M "4")
    set(HARDWARE_FLOAT 1)
elseif(${MCU_SERIES}  MATCHES  "STM32F2|STM32F1")
    set(CORTEX-M "3")
    set(HARDWARE_FLOAT 0)
elseif(${MCU_SERIES}  MATCHES  "STM32F0|STM32C0|STM32G0|STM32L0" )
    set(CORTEX-M "0")
    set(HARDWARE_FLOAT 0)
else()
    message(FATAL_ERROR "${MCU_SERIES} is not supported")
endif()


add_subdirectory(Cmake_templates)
if(GTEST)
add_subdirectory(libs/Drivers/CMSIS)
add_subdirectory(libs/Drivers/${MCU_SERIES}_HAL_Driver)
add_subdirectory(gtests)
else()
    set(CMAKE_SYSTEM_NAME Generic)
    set(CMAKE_OBJECT_PATH_MAX 300)
    set(CMAKE_C_COMPILER arm-none-eabi-gcc)
    set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
    set(CMAKE_ASM_COMPILER  arm-none-eabi-gcc)
    set(CMAKE_AR arm-none-eabi-ar)
    set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
    set(CMAKE_OBJDUMP arm-none-eabi-objdump)
    set(SIZE arm-none-eabi-size)
    set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
    project(myProject C CXX)
    #//////////////////////////////////////////////////////THIS IS USER CODE PART
    add_subdirectory(cmake_func)
    SET(FW_VERSION "0.7.2")
    if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND NOT BOOT)
        set(MEM_MAP_FILE_DEBUG "memory_map_debug.inc")
        FUNC_CREATE_MEMORY_MAP("${MEM_MAP_FILE_DEBUG}" "128" "0" "4")
    else()
        set(MEM_MAP_FILE "memory_map.inc")
        FUNC_CREATE_MEMORY_MAP("${MEM_MAP_FILE}" "128" "8" "4" )
    endif()
    #//////////////////////////////////////////////////////END USER CODE PART


    set(CMAKE_AR arm-none-eabi-ar)
    set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
    set(CMAKE_OBJDUMP arm-none-eabi-objdump)
    set(SIZE arm-none-eabi-size)
    set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)


    set(COMPILE_OPTIONS
            -mcpu=cortex-m${CORTEX-M}
            -mthumb -mthumb-interwork
            -ffunction-sections
            -fdata-sections
            -fno-common
            -fmessage-length=0
            $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
            $<$<COMPILE_LANGUAGE:CXX>:-fpermissive>

            )
    set(LINK_OPTIONS
            -Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map
            -mcpu=cortex-m${CORTEX-M}
            -mthumb
            -mthumb-interwork
            -T ${LINKER_SCRIPT}
            )

    set(COMPILE_DEF
            USE_HAL_DRIVER
            USE_FULL_LL_DRIVER
            ${ENV_MCU}
            #//////////////////////////USER DEFINITIONS
            MBEDTLS_CONFIG_FILE="mbedtls_config.h"
            #/////////////////////////////////////////
            FW_VERSION="${FW_VERSION}"
            )

    set(LINK_OPTIONS "${LINK_OPTIONS}")


    add_link_options(${LINK_OPTIONS})
    if (${CORTEX-M} EQUAL 4)
        if (${HARDWARE_FLOAT} EQUAL 1)
            add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
            add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
            add_compile_definitions(ARM_MATH_CM4 ARM_MATH_MATRIX_CHECK ARM_MATH_ROUNDING)
        elseif(${HARDWARE_FLOAT} EQUAL 0 AND $})
            string(PREPEND COMPILE_OPTIONS " -mfloat-abi=soft")
        endif ()
        endif()
    add_subdirectory(libs)
    add_subdirectory(main_prog)



#//////////////////////////////////////////////////////THIS IS USER CODE PART

#//////////////////////////////////////////////////////END USER CODE PART
endif()