ARMClang.cmake 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. if(_ARMClang_CMAKE_LOADED)
  2. return()
  3. endif()
  4. set(_ARMClang_CMAKE_LOADED TRUE)
  5. cmake_policy(PUSH)
  6. cmake_policy(SET CMP0057 NEW) # if IN_LIST
  7. get_filename_component(_CMAKE_C_TOOLCHAIN_LOCATION "${CMAKE_C_COMPILER}" PATH)
  8. get_filename_component(_CMAKE_CXX_TOOLCHAIN_LOCATION "${CMAKE_CXX_COMPILER}" PATH)
  9. set(CMAKE_EXECUTABLE_SUFFIX ".elf")
  10. find_program(CMAKE_ARMClang_LINKER armlink HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" )
  11. find_program(CMAKE_ARMClang_AR armar HINTS "${_CMAKE_C_TOOLCHAIN_LOCATION}" "${_CMAKE_CXX_TOOLCHAIN_LOCATION}" )
  12. set(CMAKE_LINKER "${CMAKE_ARMClang_LINKER}" CACHE FILEPATH "The ARMClang linker" FORCE)
  13. mark_as_advanced(CMAKE_ARMClang_LINKER)
  14. set(CMAKE_AR "${CMAKE_ARMClang_AR}" CACHE FILEPATH "The ARMClang archiver" FORCE)
  15. mark_as_advanced(CMAKE_ARMClang_AR)
  16. # get compiler supported cpu list
  17. function(__armclang_set_processor_list lang out_var)
  18. execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" --target=${CMAKE_${lang}_COMPILER_TARGET} -mcpu=list
  19. OUTPUT_VARIABLE processor_list
  20. ERROR_VARIABLE processor_list)
  21. string(REGEX MATCHALL "-mcpu=([^ \n]*)" processor_list "${processor_list}")
  22. string(REGEX REPLACE "-mcpu=" "" processor_list "${processor_list}")
  23. set(${out_var} "${processor_list}" PARENT_SCOPE)
  24. endfunction()
  25. # check processor is in list
  26. function(__armclang_check_processor processor list out_var)
  27. string(TOLOWER "${processor}" processor)
  28. if(processor IN_LIST list)
  29. set(${out_var} TRUE PARENT_SCOPE)
  30. else()
  31. set(${out_var} FALSE PARENT_SCOPE)
  32. endif()
  33. endfunction()
  34. macro(__compiler_armclang lang)
  35. if(NOT CMAKE_${lang}_COMPILER_TARGET)
  36. set(CMAKE_${lang}_COMPILER_TARGET arm-arm-none-eabi)
  37. endif()
  38. if(NOT CMAKE_${lang}_COMPILER_PROCESSOR_LIST)
  39. __armclang_set_processor_list(${lang} CMAKE_${lang}_COMPILER_PROCESSOR_LIST)
  40. endif()
  41. if(NOT CMAKE_SYSTEM_PROCESSOR)
  42. message(FATAL_ERROR " CMAKE_SYSTEM_PROCESSOR must be set for ARMClang\n"
  43. " Supported processor: ${CMAKE_${lang}_COMPILER_PROCESSOR_LIST}\n")
  44. else()
  45. __armclang_check_processor("${CMAKE_SYSTEM_PROCESSOR}" "${CMAKE_${lang}_COMPILER_PROCESSOR_LIST}" _CMAKE_${lang}_CHECK_RESULT)
  46. if(NOT _CMAKE_${lang}_CHECK_RESULT)
  47. message(FATAL_ERROR " System processor '${CMAKE_SYSTEM_PROCESSOR}' not supported by ARMClang ${lang} compiler\n"
  48. " Supported processor: ${CMAKE_${lang}_COMPILER_PROCESSOR_LIST}\n")
  49. endif()
  50. unset(_CMAKE_${lang}_CHECK_RESULT)
  51. endif()
  52. string(APPEND CMAKE_${lang}_FLAGS_INIT "-mcpu=${CMAKE_SYSTEM_PROCESSOR}")
  53. string(APPEND CMAKE_${lang}_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
  54. set(CMAKE_${lang}_LINK_EXECUTABLE "<CMAKE_LINKER> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> <OBJECTS> -o <TARGET> --list <TARGET_BASE>.map")
  55. set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "<CMAKE_AR> --create -cr <TARGET> <LINK_FLAGS> <OBJECTS>")
  56. set(CMAKE_${lang}_ARCHIVE_CREATE "<CMAKE_AR> --create -cr <TARGET> <LINK_FLAGS> <OBJECTS>")
  57. set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "--via=")
  58. set(CMAKE_${lang}_OUTPUT_EXTENSION ".o")
  59. set(CMAKE_${lang}_OUTPUT_EXTENSION_REPLACE 1)
  60. endmacro()
  61. cmake_policy(POP)