#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

        #/////////////////////////////////////////////
)




#////////////////////////////////////USER CAN SET VARIABLES HERE
set(FIRMWARE_UTIL ${CMAKE_SOURCE_DIR}/utils/bin/app_image_builder_windows.exe)
set(FIRMWARE_DIR ${CMAKE_SOURCE_DIR}/utils/bin/)
#//////////////////////////////////////////////////////////////






    # 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/*.*" )


#///////////////////END USER SOURCES FILES



    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)
    add_custom_command(TARGET ${PROJECT_NAME}.elf PRE_BUILD
            COMMAND  ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/${MEM_MAP_FILE}" ${PROJECT_BINARY_DIR}/memory_map.inc
            )
    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