#
# Toolchain
#

if (CMAKE_HOST_WIN32)
	set (SUFFIX .exe)
else()
	set (SUFFIX "")
endif()

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)
set(TOOLCHAIN_PREFIX arm-none-eabi-)

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

find_program(CROSS_GCC_PATH ${TOOLCHAIN_PREFIX}gcc${SUFFIX} NO_CACHE)
get_filename_component(TOOLCHAIN ${CROSS_GCC_PATH} PATH)

set(CMAKE_C_COMPILER ${TOOLCHAIN}/${TOOLCHAIN_PREFIX}gcc${SUFFIX})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN}/${TOOLCHAIN_PREFIX}g++${SUFFIX})
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})

set(CMAKE_OBJCOPY ${TOOLCHAIN}/${TOOLCHAIN_PREFIX}objcopy${SUFFIX} CACHE INTERNAL "objcopy tool")
set(CMAKE_STRIP ${TOOLCHAIN}/${TOOLCHAIN_PREFIX}strip${SUFFIX} CACHE INTERNAL "strip tool")
set(CMAKE_SIZE_UTIL ${TOOLCHAIN}/${TOOLCHAIN_PREFIX}size${SUFFIX} CACHE INTERNAL "size tool")

set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN})
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(TOOLCHAIN armgcc)

MESSAGE(STATUS "arm.cmake loaded")
