Guest User

Untitled

a guest
Oct 2nd, 2023
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. cmake_minimum_required(VERSION 3.17)
  2. set(CMAKE_SYSTEM_NAME Generic)
  3. set(CMAKE_SYSTEM_VERSION 1)
  4. # specify cross compilers and tools
  5. set(CMAKE_C_COMPILER arm-none-eabi-gcc)
  6. set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
  7. set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
  8. set(CMAKE_AR arm-none-eabi-ar)
  9. set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
  10. set(CMAKE_OBJDUMP arm-none-eabi-objdump)
  11. set(SIZE arm-none-eabi-size)
  12. set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
  13.  
  14. # project settings
  15. project(LPC845Test C CXX ASM)
  16.  
  17. set(CMAKE_CXX_STANDARD 17)
  18. set(CMAKE_C_STANDARD 11)
  19.  
  20. set(MCPU cortex-m0plus)
  21.  
  22. #Uncomment for hardware floating point
  23. #add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING)
  24. #add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
  25. #add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
  26.  
  27. #Uncomment for software floating point
  28. add_compile_options(-mfloat-abi=soft)
  29.  
  30. add_compile_options(-mcpu=${MCPU} -mthumb -mthumb-interwork)
  31. add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0)
  32.  
  33. # uncomment to mitigate c++17 absolute addresses warnings
  34. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register")
  35.  
  36. if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
  37. message(STATUS "Maximum optimization for speed")
  38. add_compile_options(-Ofast)
  39. elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
  40. message(STATUS "Maximum optimization for speed, debug info included")
  41. add_compile_options(-Ofast -g)
  42. elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
  43. message(STATUS "Maximum optimization for size")
  44. add_compile_options(-Os)
  45. else ()
  46. message(STATUS "Minimal optimization, debug info included")
  47. add_compile_options(-Og -g)
  48. endif ()
  49.  
  50. include_directories(
  51. ${CMAKE_SOURCE_DIR}/Core/Inc
  52. ${CMAKE_SOURCE_DIR}/../Drivers/CMSIS/Include
  53. ${CMAKE_SOURCE_DIR}/LinkerScripts
  54.  
  55. #[[ TODO rest of include folder locations ex.:
  56. ${CMAKE_SOURCE_DIR}/../Drivers/STM32H7xx_HAL_Driver/Inc
  57. ${CMAKE_SOURCE_DIR}/../Drivers/STM32H7xx_HAL_Driver/Inc/Legacy
  58. ${CMAKE_SOURCE_DIR}/../Drivers/CMSIS/Device/ST/STM32H7xx/Include
  59. ]]
  60. )
  61.  
  62. add_definitions(#[[TODO insert definitions, ex. -DUSE_HAL_DRIVER -DCORE_CM4 -DDEBUG -DSTM32H745xx]])
  63. add_definitions("-DDEBUG -DCODE_RED -DNEWLIB -DCORE_M0PLUS -DMTB_BUFFER_SIZE=256 -DUSE_ROMDIVIDE -DCPP_USE_HEAP -DLPC84X__")
  64.  
  65. file(GLOB_RECURSE SOURCES
  66. "Core/*.*" "Core/Startup/*.*"
  67. "Drivers/*.*" "../Drivers/*.*"
  68. "../Common/*.*"
  69. "./src/*.*"
  70. #[[TODO rest of cource locations]]
  71. )
  72. set(CMAKE_VERBOSE_MAKEFILE ON)
  73. set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/LinkerScripts/LPC845_Debug.ld)
  74.  
  75. add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
  76. add_link_options(-mcpu=${MCPU} -mthumb -mthumb-interwork)
  77. add_link_options(-T ${LINKER_SCRIPT})
  78.  
  79. add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
  80.  
  81. set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
  82. set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
  83.  
  84. add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
  85. COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
  86. COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
  87. COMMENT "Building ${HEX_FILE}
  88. Building ${BIN_FILE}")
Advertisement
Add Comment
Please, Sign In to add comment