#THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE!

# specify cross compilers and tools
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)

#///////////////////////////////////USER CAN SET VARIABLES HERE

#///////////////////////////////////USER CAN SET VARIABLES HERE



set(INCLUDE_DIR
        Core/Inc
        #/////////////////////////////////////////////USER CAN ADD INCLUDE_DIR HERE
        ../App
        ../loader
        ../Boot/App
        ../ARMCM0_STM32G0
        #/////////////////////////////////////////////
)




#////////////////////////////////////USER CAN SET VARIABLES HERE

#//////////////////////////////////////////////////////////////






    # project settings
    project(main_prog C CXX ASM)
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_C_STANDARD 11)



    # uncomment to mitigate c++17 absolute addresses warnings
    #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register")

    if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
        message(STATUS "Maximum optimization for speed")
        add_definitions(-DRELEASE_BUILD)
        add_definitions(-DWATCHDOG_IWDG)
        add_compile_options(-Ofast)
    elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
        add_definitions(-DWATCHDOG_IWDG)
        message(STATUS "Maximum optimization for speed, debug info included")
        add_compile_options(-Ofast -g)
    elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
        message(STATUS "Maximum optimization for size")
        add_compile_options(-Os)
    else ()
        message(STATUS "Minimal optimization, debug info included")
        add_compile_options(-Og -g)
    endif ()


    # add a directory with header files to see the generated file
   # include_directories (${CMAKE_CURRENT_BINARY_DIR})
    add_compile_definitions(BLACKBOX_CACHE=1)

#//////////////////////////USER SOURCES FILES
 file( GLOB_RECURSE SOURCES  "Core/Src/*.*" "../App/*.*" "../loader/*.*")


#///////////////////END USER SOURCES FILES
set(MEM_MAP_FILE "memory_map.inc")
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()

add_link_options(-specs=nano.specs -specs=nosys.specs)
    add_executable(${PROJECT_NAME}.elf ${SOURCES})
    target_compile_options(${PROJECT_NAME}.elf PUBLIC ${COMPILE_OPTIONS})
    target_link_options(${PROJECT_NAME}.elf PUBLIC ${LINK_OPTIONS})
    target_include_directories(${PROJECT_NAME}.elf PUBLIC ${INCLUDE_DIR})
    target_link_libraries(${PROJECT_NAME}.elf PUBLIC ${MCU_SERIES}_HAL_DRIVER CMSIS )
    target_compile_definitions(${PROJECT_NAME}.elf PUBLIC ${COMPILE_DEF})
    set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
    set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
    add_custom_command(TARGET ${PROJECT_NAME}.elf PRE_BUILD
            COMMAND  ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/${MEM_MAP_FILE_DEBUG}" ${PROJECT_BINARY_DIR}/../${MEM_MAP_FILE}
            )
else()
    add_custom_command(TARGET ${PROJECT_NAME}.elf PRE_BUILD
            COMMAND  ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/${MEM_MAP_FILE}" ${PROJECT_BINARY_DIR}/../${MEM_MAP_FILE}
            )
endif()
    add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
            COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
            COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
            COMMENT "Building ${HEX_FILE}
Building ${BIN_FILE}"
            )
#///////////////////////////USER CUSTOM COMMANDS

#//////////////////////////END CUSTOM COMMANDS