arm-none-eabi-gcc.cmake 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. if (__TOOLCHAIN_LOADED)
  18. return()
  19. endif()
  20. set(__TOOLCHAIN_LOADED TRUE)
  21. set(CMAKE_SYSTEM_NAME Generic)
  22. set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
  23. set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
  24. set(CMAKE_SYSTEM_PROCESSOR "cortex-m55" CACHE STRING "Select Arm(R) Cortex(R)-M architecture. (cortex-m0, cortex-m3, cortex-m33, cortex-m4, cortex-m55, cortex-m7, etc)")
  25. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  26. SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  27. SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  28. SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  29. set(CMAKE_C_STANDARD 99)
  30. set(CMAKE_CXX_STANDARD 14)
  31. # The system processor could for example be set to cortex-m33+nodsp+nofp.
  32. set(__CPU_COMPILE_TARGET ${CMAKE_SYSTEM_PROCESSOR})
  33. string(REPLACE "+" ";" __CPU_FEATURES ${__CPU_COMPILE_TARGET})
  34. list(POP_FRONT __CPU_FEATURES CMAKE_SYSTEM_PROCESSOR)
  35. string(FIND ${__CPU_COMPILE_TARGET} "+" __OFFSET)
  36. if(__OFFSET GREATER_EQUAL 0)
  37. string(SUBSTRING ${__CPU_COMPILE_TARGET} ${__OFFSET} -1 CPU_FEATURES)
  38. endif()
  39. # Add -mcpu to the compile options to override the -mcpu the CMake toolchain adds
  40. add_compile_options(-mcpu=${__CPU_COMPILE_TARGET})
  41. # Set floating point unit
  42. if("${__CPU_COMPILE_TARGET}" MATCHES "\\+fp")
  43. set(FLOAT hard)
  44. elseif("${__CPU_COMPILE_TARGET}" MATCHES "\\+nofp")
  45. set(FLOAT soft)
  46. elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m33" OR
  47. "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "cortex-m55")
  48. set(FLOAT hard)
  49. else()
  50. set(FLOAT soft)
  51. endif()
  52. add_compile_options(-mfloat-abi=${FLOAT})
  53. add_link_options(-mfloat-abi=${FLOAT})
  54. # Link target
  55. add_link_options(-mcpu=${__CPU_COMPILE_TARGET})
  56. add_link_options(-Xlinker -Map=output.map)
  57. #
  58. # Compile options
  59. #
  60. set(cxx_flags "-fno-unwind-tables;-fno-rtti;-fno-exceptions")
  61. add_compile_options("-Wall;-Wextra;-Wsign-compare;-Wunused;-Wswitch-default;\
  62. -Wdouble-promotion;-Wredundant-decls;-Wshadow;-Wnull-dereference;\
  63. -Wno-format-extra-args;-Wno-unused-function;-Wno-unused-label;\
  64. -Wno-missing-field-initializers;-Wno-return-type;-Wno-format;-Wno-int-conversion"
  65. "$<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>"
  66. )