toolchain-gcc.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. # All rights reserved.
  3. #
  4. # This software is supplied "AS IS" without any warranties.
  5. # RDA assumes no responsibility or liability for the use of the software,
  6. # conveys no license or title under any patent, copyright, or mask work
  7. # right to the product. RDA reserves the right to make changes in the
  8. # software without notification. RDA also make no representation or
  9. # warranty that such application will be suitable for the specified use
  10. # without further testing or modification.
  11. # Configures CMake for using GCC
  12. set(CMAKE_SYSTEM_NAME Generic)
  13. find_program(CMAKE_C_COMPILER ${CROSS_COMPILE}gcc)
  14. find_program(CMAKE_CXX_COMPILER ${CROSS_COMPILE}g++)
  15. find_program(CMAKE_READELF ${CROSS_COMPILE}readelf)
  16. set(CMAKE_EXECUTABLE_SUFFIX_ASM .elf)
  17. set(CMAKE_EXECUTABLE_SUFFIX_C .elf)
  18. set(CMAKE_EXECUTABLE_SUFFIX_CXX .elf)
  19. if (${CMAKE_C_COMPILER} STREQUAL "CMAKE_C_COMPILER-NOTFOUND")
  20. message(FATAL_ERROR "\t\nFATAL_ERROR:\n\"${CROSS_COMPILE}gcc is not found !\"\n")
  21. endif()
  22. execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE gcc_version OUTPUT_STRIP_TRAILING_WHITESPACE)
  23. if(${gcc_version} VERSION_EQUAL 9.2.1)
  24. set(NEWLIB_VERSION newlib-3.1.0)
  25. elseif(${gcc_version} VERSION_EQUAL 10.2.1)
  26. set(NEWLIB_VERSION newlib-3.3.0)
  27. else()
  28. message(FATAL_ERROR "\t\nFATAL_ERROR:\n\"${CROSS_COMPILE}gcc-${gcc_version} is not supported !\"\n")
  29. endif()
  30. message("-- The libc library version is ${NEWLIB_VERSION}")
  31. if(CONFIG_CPU_ARM_CA5)
  32. set(abi_options -mcpu=cortex-a5 -mtune=generic-armv7-a -mthumb -mfpu=neon-vfpv4
  33. -mfloat-abi=hard -mno-unaligned-access)
  34. set(partial_link_options)
  35. set(libc_file_name ${CMAKE_CURRENT_SOURCE_DIR}/components/newlib/${NEWLIB_VERSION}/armca5/libc.a)
  36. set(libm_file_name ${CMAKE_CURRENT_SOURCE_DIR}/components/newlib/${NEWLIB_VERSION}/armca5/libm.a)
  37. endif()
  38. if(CONFIG_CPU_ARM_CM4F)
  39. set(abi_options -mcpu=cortex-m4 -mtune=cortex-m4 -mthumb -mfpu=fpv4-sp-d16
  40. -mfloat-abi=hard -mno-unaligned-access -fsingle-precision-constant)
  41. set(partial_link_options)
  42. set(libc_file_name ${CMAKE_CURRENT_SOURCE_DIR}/components/newlib/${NEWLIB_VERSION}/armcm4f/libc.a)
  43. set(libm_file_name ${CMAKE_CURRENT_SOURCE_DIR}/components/newlib/${NEWLIB_VERSION}/armcm4f/libm.a)
  44. endif()
  45. if(CONFIG_CPU_ARM_CM33F)
  46. set(abi_options -mcpu=cortex-m33 -mtune=cortex-m33 -mthumb -mfpu=fpv5-sp-d16
  47. -mfloat-abi=hard -mno-unaligned-access -fsingle-precision-constant)
  48. set(partial_link_options)
  49. set(libc_file_name ${CMAKE_CURRENT_SOURCE_DIR}/components/newlib/${NEWLIB_VERSION}/armcm33f/libc.a)
  50. set(libm_file_name ${CMAKE_CURRENT_SOURCE_DIR}/components/newlib/${NEWLIB_VERSION}/armcm33f/libm.a)
  51. endif()
  52. include_directories(${SOURCE_TOP_DIR}/components/newlib/${NEWLIB_VERSION}/include)
  53. if(CONFIG_ENABLE_GCC_LTO)
  54. set(lto_compile_option -flto -ffat-lto-objects)
  55. set(lto_link_option -flto -flto-partition=one)
  56. else()
  57. set(lto_link_option -fno-lto)
  58. endif()
  59. add_compile_options(${abi_options} -g -Os ${lto_compile_option}
  60. -Wall
  61. -fcommon
  62. -fno-strict-aliasing
  63. -ffunction-sections -fdata-sections
  64. )
  65. add_link_options(${abi_options} -Os ${lto_link_option})
  66. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
  67. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-exceptions -fno-rtti -fno-threadsafe-statics")
  68. # GNU ar will alreay create index
  69. set(CMAKE_C_ARCHIVE_FINISH "")
  70. set(CMAKE_CXX_ARCHIVE_FINISH "")
  71. if(WITH_WERROR)
  72. add_compile_options(-Werror)
  73. endif()
  74. if(WITH_LINK_CREF)
  75. set(link_cref_option -Wl,-cref)
  76. endif()
  77. set(multilib_opions ${abi_options})
  78. if((${gcc_version} VERSION_GREATER 8) AND (CONFIG_CPU_ARM_CA5))
  79. set(multilib_opions -march=armv7-a+neon-vfpv4 -mthumb -mfloat-abi=hard)
  80. endif()
  81. execute_process(COMMAND ${CMAKE_C_COMPILER} ${multilib_opions} --print-file-name libgcc.a
  82. OUTPUT_VARIABLE libgcc_file_name
  83. OUTPUT_STRIP_TRAILING_WHITESPACE
  84. )