LocalAvrGcc.cmake 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. get_filename_component(PROJECT_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
  2. include("${PROJECT_CMAKE_DIR}/Utilities.cmake")
  3. set(CMAKE_SYSTEM_NAME Generic)
  4. set(CMAKE_SYSTEM_PROCESSOR avr)
  5. set(CMAKE_CROSSCOMPILING 1)
  6. get_dependency_directory("avr-gcc" AVR_TOOLCHAIN_DIR)
  7. message( "tc dir is ${AVR_TOOLCHAIN_DIR}")
  8. #
  9. # Utilities
  10. if(MINGW
  11. OR CYGWIN
  12. OR WIN32
  13. )
  14. set(UTIL_SEARCH_CMD where)
  15. set(EXECUTABLE_SUFFIX ".exe")
  16. elseif(UNIX OR APPLE)
  17. set(UTIL_SEARCH_CMD which)
  18. set(EXECUTABLE_SUFFIX "")
  19. endif()
  20. set(TOOLCHAIN_PREFIX avr-)
  21. #
  22. # Looking up the toolchain
  23. #
  24. if(AVR_TOOLCHAIN_DIR)
  25. # using toolchain set by AvrGcc.cmake (locked version)
  26. set(BINUTILS_PATH "${AVR_TOOLCHAIN_DIR}/bin")
  27. else()
  28. # search for ANY avr-gcc toolchain
  29. execute_process(
  30. COMMAND ${UTIL_SEARCH_CMD} ${TOOLCHAIN_PREFIX}gcc
  31. OUTPUT_VARIABLE AVR_GCC_PATH
  32. OUTPUT_STRIP_TRAILING_WHITESPACE
  33. RESULT_VARIABLE FIND_RESULT
  34. )
  35. # found?
  36. if(NOT "${FIND_RESULT}" STREQUAL "0")
  37. message(FATAL_ERROR "avr-gcc not found")
  38. endif()
  39. get_filename_component(BINUTILS_PATH "${AVR_GCC_PATH}" DIRECTORY)
  40. get_filename_component(AVR_TOOLCHAIN_DIR ${BINUTILS_PATH} DIRECTORY)
  41. endif()
  42. #
  43. # Setup CMake
  44. #
  45. # Without that flag CMake is not able to pass test compilation check
  46. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  47. set(CMAKE_C_COMPILER
  48. "${BINUTILS_PATH}/${TOOLCHAIN_PREFIX}gcc${EXECUTABLE_SUFFIX}"
  49. CACHE FILEPATH "" FORCE
  50. )
  51. set(CMAKE_ASM_COMPILER
  52. "${BINUTILS_PATH}/${TOOLCHAIN_PREFIX}gcc${EXECUTABLE_SUFFIX}"
  53. CACHE FILEPATH "" FORCE
  54. )
  55. set(CMAKE_CXX_COMPILER
  56. "${BINUTILS_PATH}/${TOOLCHAIN_PREFIX}g++${EXECUTABLE_SUFFIX}"
  57. CACHE FILEPATH "" FORCE
  58. )
  59. set(CMAKE_EXE_LINKER_FLAGS_INIT
  60. ""
  61. CACHE STRING "" FORCE
  62. )
  63. set(CMAKE_ASM_COMPILE_OBJECT
  64. "<CMAKE_ASM_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>"
  65. CACHE STRING "" FORCE
  66. )
  67. set(CMAKE_OBJCOPY
  68. "${BINUTILS_PATH}/${TOOLCHAIN_PREFIX}objcopy${EXECUTABLE_SUFFIX}"
  69. CACHE INTERNAL "objcopy tool"
  70. )
  71. set(CMAKE_OBJDUMP
  72. "${BINUTILS_PATH}/${TOOLCHAIN_PREFIX}objdump${EXECUTABLE_SUFFIX}"
  73. CACHE INTERNAL "objdump tool"
  74. )
  75. set(CMAKE_SIZE_UTIL
  76. "${BINUTILS_PATH}/${TOOLCHAIN_PREFIX}size${EXECUTABLE_SUFFIX}"
  77. CACHE INTERNAL "size tool"
  78. )
  79. set(CMAKE_FIND_ROOT_PATH "${AVR_TOOLCHAIN_DIR}")
  80. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  81. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  82. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)