CMakeLists.txt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. cmake_minimum_required(VERSION 3.22)
  2. #
  3. # This file is generated only once,
  4. # and is not re-generated if converter is called multiple times.
  5. #
  6. # User is free to modify the file as much as necessary
  7. #
  8. # Setup compiler settings
  9. set(CMAKE_C_STANDARD 11)
  10. set(CMAKE_C_STANDARD_REQUIRED ON)
  11. set(CMAKE_C_EXTENSIONS ON)
  12. # Define the build type
  13. if(NOT CMAKE_BUILD_TYPE)
  14. set(CMAKE_BUILD_TYPE "Debug")
  15. endif()
  16. # Set the project name
  17. set(CMAKE_PROJECT_NAME msts)
  18. # Include toolchain file
  19. include("cmake/gcc-arm-none-eabi.cmake")
  20. # Enable compile command to ease indexing with e.g. clangd
  21. set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
  22. # Enable CMake support for ASM and C languages
  23. enable_language(C ASM)
  24. # Core project settings
  25. project(${CMAKE_PROJECT_NAME})
  26. message("Build type: " ${CMAKE_BUILD_TYPE})
  27. # Create an executable object type
  28. add_executable(${CMAKE_PROJECT_NAME})
  29. # Add STM32CubeMX generated sources
  30. add_subdirectory(cmake/stm32cubemx)
  31. # Link directories setup
  32. target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE
  33. # Add user defined library search paths
  34. )
  35. # Add sources to executable
  36. target_sources(${CMAKE_PROJECT_NAME} PRIVATE
  37. # Add user sources here
  38. App/BootLoader/Src/boot.c
  39. App/BootLoader/Src/flash.c
  40. App/BootLoader/Src/iap.c
  41. App/Can/Src/can_task.c
  42. App/Can/Src/can_interface.c
  43. App/Common/Src/hal_math.c
  44. App/Task/Src/schedule.c
  45. App/Task/Src/task.c
  46. App/Uart/Src/uart_interface.c
  47. App/Uart/Src/uart_table.c
  48. App/Uart/Src/uart_task.c
  49. )
  50. # Add include paths
  51. target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
  52. # Add user defined include paths
  53. App/BootLoader/Inc
  54. App/Common/Inc
  55. App/Can/Inc
  56. App/Task/Inc
  57. App/Uart/Inc
  58. )
  59. # Add project symbols (macros)
  60. target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
  61. # Add user defined symbols
  62. )
  63. # Add linked libraries
  64. target_link_libraries(${CMAKE_PROJECT_NAME}
  65. stm32cubemx
  66. # Add user defined libraries
  67. )
  68. # post-build
  69. add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
  70. COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${CMAKE_PROJECT_NAME}>
  71. )
  72. # 生成 hex 文件
  73. add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
  74. COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.hex
  75. )
  76. # 生成 bin 文件
  77. add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
  78. COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.bin
  79. )