set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(COMPILER_PREFIX "${TOOLCHAIN_DIR}/bin/arm-none-eabi-")
#set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs" CACHE INTERNAL "")


set(FLOAT_ABI "soft")
set(CPU_SPECIFIC_FLAGS
    "-march=armv7-a -mtune=${CPU_CORTEX_TYPE} -mno-unaligned-access -mfloat-abi=${FLOAT_ABI} ${FLOAT_FLAGS}"
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CPU_SPECIFIC_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPU_SPECIFIC_FLAGS}")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${CPU_SPECIFIC_FLAGS}")
set(TARGET_C_LINK_FLAGS "${TARGET_C_LINK_FLAGS} ${CPU_SPECIFIC_FLAGS}")
set(TARGET_CXX_LINK_FLAGS "${TARGET_CXX_LINK_FLAGS} ${CPU_SPECIFIC_FLAGS}")

set(CMAKE_C_COMPILER "${COMPILER_PREFIX}gcc" CACHE INTERNAL STRING)
set(CMAKE_CXX_COMPILER "${COMPILER_PREFIX}g++" CACHE INTERNAL STRING)
set(CMAKE_ASM_COMPILER "${COMPILER_PREFIX}gcc" CACHE INTERNAL STRING)
set(CMAKE_AR "${COMPILER_PREFIX}ar" CACHE INTERNAL STRING)
set(CMAKE_NM "${COMPILER_PREFIX}nm" CACHE INTERNAL STRING)
set(CMAKE_OBJDUMP "${COMPILER_PREFIX}objdump" CACHE INTERNAL STRING)
set(CMAKE_OBJDUMP_FLAGS "-S" CACHE INTERNAL STRING)
set(CMAKE_OBJCOPY "${COMPILER_PREFIX}objcopy" CACHE INTERNAL STRING)
set(CMAKE_STRIP "${COMPILER_PREFIX}strip" CACHE INTERNAL STRING)
set(CMAKE_READELF "${COMPILER_PREFIX}readelf" CACHE INTERNAL STRING)

# Used to generate assembly listings from C source files
set(C_ASSEMBLER ${COMPILER_PREFIX}gcc CACHE INTERNAL STRING)

find_program(GDB ${COMPILER_PREFIX}gdb)
set(DEBUGGER ${COMPILER_PREFIX}gdb)

set(GNU_C_COMPILER ${CMAKE_C_COMPILER} CACHE INTERNAL STRING)
set(GNU_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE INTERNAL STRING)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Werror")
