LocalAvrGcc.cmake 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_AR
  68. "${BINUTILS_PATH}/${TOOLCHAIN_PREFIX}gcc-ar${EXECUTABLE_SUFFIX}"
  69. CACHE FILEPATH "ar" FORCE
  70. )
  71. set(CMAKE_RANLIB
  72. "${BINUTILS_PATH}/${TOOLCHAIN_PREFIX}gcc-ranlib${EXECUTABLE_SUFFIX}"
  73. CACHE FILEPATH "ranlib" FORCE
  74. )
  75. set(CMAKE_OBJCOPY
  76. "${BINUTILS_PATH}/${TOOLCHAIN_PREFIX}objcopy${EXECUTABLE_SUFFIX}"
  77. CACHE INTERNAL "objcopy tool"
  78. )
  79. set(CMAKE_OBJDUMP
  80. "${BINUTILS_PATH}/${TOOLCHAIN_PREFIX}objdump${EXECUTABLE_SUFFIX}"
  81. CACHE INTERNAL "objdump tool"
  82. )
  83. set(CMAKE_SIZE_UTIL
  84. "${BINUTILS_PATH}/${TOOLCHAIN_PREFIX}size${EXECUTABLE_SUFFIX}"
  85. CACHE INTERNAL "size tool"
  86. )
  87. set(CMAKE_FIND_ROOT_PATH "${AVR_TOOLCHAIN_DIR}")
  88. set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  89. set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  90. set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)