toolchain.cmake 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. set(CMAKE_SYSTEM_NAME Generic)
  2. set(CMAKE_SYSTEM_PROCESSOR AVR)
  3. if(MINGW OR CYGWIN OR WIN32)
  4. set(UTIL_SEARCH_CMD where)
  5. elseif(UNIX OR APPLE)
  6. set(UTIL_SEARCH_CMD which)
  7. endif()
  8. set(TOOLCHAIN_PREFIX avr-)
  9. execute_process(
  10. COMMAND ${UTIL_SEARCH_CMD} ${TOOLCHAIN_PREFIX}gcc
  11. OUTPUT_VARIABLE BINUTILS_PATH
  12. OUTPUT_STRIP_TRAILING_WHITESPACE
  13. )
  14. get_filename_component(ARM_TOOLCHAIN_DIR ${BINUTILS_PATH} DIRECTORY)
  15. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  16. set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
  17. set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
  18. set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
  19. set(CMAKE_OBJCOPY ${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}objcopy CACHE INTERNAL "objcopy tool")
  20. set(CMAKE_SIZE_UTIL ${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}size CACHE INTERNAL "size tool")
  21. set(CMAKE_FIND_ROOT_PATH ${BINUTILS_PATH})
  22. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  23. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  24. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  25. set(MCU "atmega328p")
  26. add_compile_options("-mmcu=${MCU}" "-DF_CPU=16000000UL")
  27. add_link_options(
  28. -mmcu=${MCU}
  29. -funsigned-char # a few optimizations
  30. -funsigned-bitfields
  31. -fpack-struct
  32. -fshort-enums
  33. -ffunction-sections
  34. -fdata-sections
  35. -fno-split-wide-types
  36. -fno-tree-scev-cprop
  37. -fno-exceptions
  38. $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
  39. $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
  40. $<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>
  41. )