gcc-arm-none-eabi.cmake 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. set(CMAKE_SYSTEM_NAME Generic)
  2. set(CMAKE_SYSTEM_PROCESSOR arm)
  3. set(CMAKE_C_COMPILER_FORCED TRUE)
  4. set(CMAKE_CXX_COMPILER_FORCED TRUE)
  5. set(CMAKE_C_COMPILER_ID GNU)
  6. set(CMAKE_CXX_COMPILER_ID GNU)
  7. # Some default GCC settings
  8. # arm-none-eabi- must be part of path environment
  9. set(TOOLCHAIN_PREFIX arm-none-eabi-)
  10. set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
  11. set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
  12. set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
  13. set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}g++)
  14. set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy)
  15. set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size)
  16. set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf")
  17. set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")
  18. set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf")
  19. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  20. # MCU specific flags
  21. set(TARGET_FLAGS "-mcpu=cortex-m3 ")
  22. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}")
  23. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -fdata-sections -ffunction-sections")
  24. if(CMAKE_BUILD_TYPE MATCHES Debug)
  25. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g3")
  26. endif()
  27. if(CMAKE_BUILD_TYPE MATCHES Release)
  28. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -g0")
  29. endif()
  30. set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp -MMD -MP")
  31. set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions -fno-threadsafe-statics")
  32. set(CMAKE_C_LINK_FLAGS "${TARGET_FLAGS}")
  33. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -T \"${CMAKE_SOURCE_DIR}/STM32F103RCTx_FLASH.ld\"")
  34. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --specs=nano.specs")
  35. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections")
  36. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--start-group -lc -lm -Wl,--end-group")
  37. set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--print-memory-usage")
  38. set(CMAKE_CXX_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--start-group -lstdc++ -lsupc++ -Wl,--end-group")
  39. if(CMAKE_PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME)
  40. execute_process(
  41. COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json
  42. )
  43. endif()