SET(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR armel)
set(CROSS_PREFIX arm-none-eabi-)
if(NOT CROSS_TOOLCHAIN_PATH)
set(CROSS_TOOLCHAIN_PATH /opt/local/src/nrf52/gcc-arm-none-eabi-6-2017-q2-update)
endif()

set(CMAKE_CROSSCOMPILING TRUE)

# specify the cross-toolchain (compiler, header and library directories)
set(CMAKE_SYSTEM_NAME freertos)
set(CMAKE_SYSTEM_PROCESSOR armel)
set(CMAKE_C_COMPILER ${CROSS_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${CROSS_PREFIX}g++)

set(CMAKE_ASM_COMPILER ${CROSS_PREFIX}gcc)
set(CMAKE_RANLIB ${CROSS_PREFIX}ranlib)
set(CMAKE_AR ${CROSS_PREFIX}ar CACHE INTERNAL "")
set(CMAKE_LINKER ${CROSS_PREFIX}gcc CACHE INTERNAL "")

set(CMAKE_C_COMPILER_TARGET ${CMAKE_C_COMPILER})

# message("abc": ${CMAKE_CXX_COMPILER_TARGET})

set(CMAKE_INCLUDE_PATH ${CROSS_TOOLCHAIN_PATH}/include)
set(CMAKE_LIBRARY_PATH ${CROSS_TOOLCHAIN_PATH}/lib)
set(CMAKE_INSTALL_PREFIX ${CROSS_TOOLCHAIN_PATH}/)

# Set tools
set(OBJSIZE ${CROSS_PREFIX}size)
set(OBJCOPY ${CROSS_PREFIX}objcopy)
set(OBJDUMP ${CROSS_PREFIX}objdump)
set(DEBUGGER ${CROSS_PREFIX}gdb)

#set(CMAKE_FIND_ROOT_PATH ${ARMADEUS_ROOT_CTC} ${CMAKE_INCLUDE_PATH})

# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH ${CROSS_TOOLCHAIN_PATH})

# for libraries and headers in the target directories

#set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)


# no test

set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)


#set(CMAKE_C_OUTPUT_EXTENSION .o)


# Remove preset linker flags
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") 
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") 
set(CMAKE_SHARED_LIBRARY_LINK_ASM_FLAGS "")

# Removes invalid (default) flags on OSX
SET(CMAKE_C_LINK_FLAGS "")
SET(CMAKE_CXX_LINK_FLAGS "")

# Set library options
set(SHARED_LIBS OFF)
set(STATIC_LIBS ON)

