AnyAvrGcc.cmake 2.6 KB

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