set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR Cortex-M7)
set(TOOLCHAIN_PREFIX arm-none-eabi-)

set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_AR ${TOOLCHAIN_PREFIX}ar)
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy)
set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}objdump)
set(CMAKE_SIZE_UTIL ${TOOLCHAIN_PREFIX}size)

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)


set(LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/STM32H743ZITx_FLASH.ld)


set(ARM_OPTIONS
        -mcpu=cortex-m7
        -mfloat-abi=hard
        -mfpu=fpv5-d16
        -mthumb
        -mthumb-interwork
        --specs=nano.specs)

add_compile_options(
        ${ARM_OPTIONS}
        -fmessage-length=0
        -funsigned-char
        -ffunction-sections
        -fdata-sections
        -fno-common
        -MMD
        -MP)

# use these options to verify the linker can create an ELF file

add_link_options(${ARM_OPTIONS}
        -specs=nosys.specs
        -lnosys
        -lc
        -lm
        LINKER:--gc-sections
        LINKER:--build-id
        LINKER:--print-memory-usage)
