gcc.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Setting Linux is forcing th extension to be .o instead of .obj when building on WIndows.
  2. # It is important because armlink is failing when files have .obj extensions (error with
  3. # scatter file section not found)
  4. SET(CMAKE_SYSTEM_NAME Linux)
  5. SET(CMAKE_SYSTEM_PROCESSOR arm)
  6. #SET(CMAKE_C_COMPILER "${tools}/bin/arm-none-eabi-gcc")
  7. #SET(CMAKE_CXX_COMPILER "${tools}/bin/arm-none-eabi-g++")
  8. #SET(CMAKE_ASM_COMPILER "${tools}/bin/arm-none-eabi-gcc")
  9. find_program(CMAKE_C_COMPILER NAMES arm-none-eabi-gcc arm-none-eabi-gcc.exe)
  10. find_program(CMAKE_CXX_COMPILER NAMES arm-none-eabi-g++ arm-none-eabi-g++.exe)
  11. find_program(CMAKE_ASM_COMPILER NAMES arm-none-eabi-gcc arm-none-eabi-gcc.exe)
  12. if (NOT ("${tools}" STREQUAL ""))
  13. message(STATUS "Tools path is set")
  14. SET(CMAKE_AR "${tools}/bin/ar")
  15. SET(CMAKE_CXX_COMPILER_AR "${tools}/bin/ar")
  16. SET(CMAKE_C_COMPILER_AR "${tools}/bin/ar")
  17. else()
  18. find_program(CMAKE_AR NAMES arm-none-eabi-gcc-ar arm-none-eabi-gcc-ar.exe )
  19. find_program(CMAKE_CXX_COMPILER_AR NAMES arm-none-eabi-gcc-ar arm-none-eabi-gcc-ar.exe )
  20. find_program(CMAKE_C_COMPILER_AR NAMES arm-none-eabi-gcc-ar arm-none-eabi-gcc-ar.exe)
  21. endif()
  22. #SET(CMAKE_LINKER "${tools}/bin/arm-none-eabi-g++")
  23. find_program(CMAKE_LINKER NAMES arm-none-eabi-g++ arm-none-eabi-g++.exe)
  24. SET(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
  25. SET(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_LINKER> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
  26. SET(CMAKE_C_OUTPUT_EXTENSION .o)
  27. SET(CMAKE_CXX_OUTPUT_EXTENSION .o)
  28. SET(CMAKE_ASM_OUTPUT_EXTENSION .o)
  29. # When library defined as STATIC, this line is needed to describe how the .a file must be
  30. # create. Some changes to the line may be needed.
  31. SET(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> -crs <TARGET> <LINK_FLAGS> <OBJECTS>" )
  32. SET(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> -crs <TARGET> <LINK_FLAGS> <OBJECTS>" )
  33. set(GCC ON)
  34. # default core
  35. if(NOT ARM_CPU)
  36. set(
  37. ARM_CPU "cortex-a5"
  38. CACHE STRING "Set ARM CPU. Default : cortex-a5"
  39. )
  40. endif(NOT ARM_CPU)
  41. if (ARM_CPU STREQUAL "cortex-m55")
  42. # For gcc 10q4
  43. SET(CMAKE_C_FLAGS "-ffunction-sections -fdata-sections -march=armv8.1-m.main+mve.fp+fp.dp" CACHE INTERNAL "C compiler common flags")
  44. SET(CMAKE_CXX_FLAGS "-ffunction-sections -fdata-sections -march=armv8.1-m.main+mve.fp+fp.dp" CACHE INTERNAL "C compiler common flags")
  45. SET(CMAKE_ASM_FLAGS "-march=armv8.1-m.main+mve.fp+fp.dp" CACHE INTERNAL "ASM compiler common flags")
  46. SET(CMAKE_EXE_LINKER_FLAGS "-fno-use-linker-plugin -march=armv8.1-m.main+mve.fp+fp.dp" CACHE INTERNAL "linker flags")
  47. elseif (ARM_CPU STREQUAL "cortex-m55+nomve.fp+nofp")
  48. # This case is not tested nor supported
  49. SET(CMAKE_C_FLAGS "-ffunction-sections -fdata-sections -march=armv8.1-m.main+dsp+nofp" CACHE INTERNAL "C compiler common flags")
  50. SET(CMAKE_CXX_FLAGS "-ffunction-sections -fdata-sections -march=armv8.1-m.main+dsp+nofp" CACHE INTERNAL "C compiler common flags")
  51. SET(CMAKE_ASM_FLAGS "-march=armv8.1-m.main+dsp+nofp" CACHE INTERNAL "ASM compiler common flags")
  52. SET(CMAKE_EXE_LINKER_FLAGS "-fno-use-linker-plugin -march=armv8.1-m.main+dsp+nofp" CACHE INTERNAL "linker flags")
  53. elseif (ARM_CPU STREQUAL "cortex-m55+nomve.fp+fp.dp")
  54. # This case is not tested nor supported
  55. SET(CMAKE_C_FLAGS "-ffunction-sections -fdata-sections -march=armv8.1-m.main+dsp+fp.dp" CACHE INTERNAL "C compiler common flags")
  56. SET(CMAKE_CXX_FLAGS "-ffunction-sections -fdata-sections -march=armv8.1-m.main+dsp+fp.dp" CACHE INTERNAL "C compiler common flags")
  57. SET(CMAKE_ASM_FLAGS "-march=armv8.1-m.main+dsp+fp.dp" CACHE INTERNAL "ASM compiler common flags")
  58. SET(CMAKE_EXE_LINKER_FLAGS "-fno-use-linker-plugin -march=armv8.1-m.main+dsp+fp.dp" CACHE INTERNAL "linker flags")
  59. else()
  60. SET(CMAKE_C_FLAGS "-ffunction-sections -fdata-sections -mcpu=${ARM_CPU}" CACHE INTERNAL "C compiler common flags")
  61. SET(CMAKE_CXX_FLAGS "-ffunction-sections -fdata-sections -mcpu=${ARM_CPU}" CACHE INTERNAL "C compiler common flags")
  62. SET(CMAKE_ASM_FLAGS "-mcpu=${ARM_CPU}" CACHE INTERNAL "ASM compiler common flags")
  63. SET(CMAKE_EXE_LINKER_FLAGS "-mcpu=${ARM_CPU}" CACHE INTERNAL "linker flags")
  64. endif()
  65. get_property(IS_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
  66. if(IS_IN_TRY_COMPILE)
  67. add_link_options("--specs=nosys.specs")
  68. endif()
  69. add_link_options("-Wl,--start-group")
  70. #add_link_options("-mcpu=${ARM_CPU}")
  71. # Where is the target environment
  72. #SET(CMAKE_FIND_ROOT_PATH "${tools}")
  73. # Search for programs in the build host directories
  74. SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  75. # For libraries and headers in the target directories
  76. SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  77. SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)