CMakeLists.txt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. cmake_minimum_required(VERSION 3.22)
  2. # Enable CMake support for ASM and C languages
  3. enable_language(C ASM)
  4. # STM32CubeMX generated symbols (macros)
  5. set(MX_Defines_Syms
  6. USE_HAL_DRIVER
  7. STM32F103xB
  8. $<$<CONFIG:Debug>:DEBUG>
  9. )
  10. # STM32CubeMX generated include paths
  11. set(MX_Include_Dirs
  12. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Inc
  13. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Inc
  14. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy
  15. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/include
  16. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2
  17. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3
  18. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/CMSIS/Device/ST/STM32F1xx/Include
  19. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/CMSIS/Include
  20. )
  21. # STM32CubeMX generated application sources
  22. set(MX_Application_Src
  23. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/main.c
  24. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/freertos.c
  25. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/stm32f1xx_it.c
  26. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/stm32f1xx_hal_msp.c
  27. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/stm32f1xx_hal_timebase_tim.c
  28. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/sysmem.c
  29. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/syscalls.c
  30. ${CMAKE_CURRENT_SOURCE_DIR}/../../startup_stm32f103xb.s
  31. )
  32. # STM32 HAL/LL Drivers
  33. set(STM32_Drivers_Src
  34. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/system_stm32f1xx.c
  35. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c
  36. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c
  37. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c
  38. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c
  39. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c
  40. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c
  41. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c
  42. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c
  43. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c
  44. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c
  45. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c
  46. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c
  47. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c
  48. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c
  49. )
  50. # Drivers Midllewares
  51. set(FreeRTOS_Src
  52. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/croutine.c
  53. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/event_groups.c
  54. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/list.c
  55. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/queue.c
  56. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c
  57. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/tasks.c
  58. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/timers.c
  59. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c
  60. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c
  61. ${CMAKE_CURRENT_SOURCE_DIR}/../../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
  62. )
  63. # Link directories setup
  64. set(MX_LINK_DIRS
  65. )
  66. # Project static libraries
  67. set(MX_LINK_LIBS
  68. STM32_Drivers
  69. ${TOOLCHAIN_LINK_LIBRARIES}
  70. FreeRTOS
  71. )
  72. # Interface library for includes and symbols
  73. add_library(stm32cubemx INTERFACE)
  74. target_include_directories(stm32cubemx INTERFACE ${MX_Include_Dirs})
  75. target_compile_definitions(stm32cubemx INTERFACE ${MX_Defines_Syms})
  76. # Create STM32_Drivers static library
  77. add_library(STM32_Drivers OBJECT)
  78. target_sources(STM32_Drivers PRIVATE ${STM32_Drivers_Src})
  79. target_link_libraries(STM32_Drivers PUBLIC stm32cubemx)
  80. # Create FreeRTOS static library
  81. add_library(FreeRTOS OBJECT)
  82. target_sources(FreeRTOS PRIVATE ${FreeRTOS_Src})
  83. target_link_libraries(FreeRTOS PUBLIC stm32cubemx)
  84. # Add STM32CubeMX generated application sources to the project
  85. target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${MX_Application_Src})
  86. # Link directories setup
  87. target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE ${MX_LINK_DIRS})
  88. # Add libraries to the project
  89. target_link_libraries(${CMAKE_PROJECT_NAME} ${MX_LINK_LIBS})
  90. # Add the map file to the list of files to be removed with 'clean' target
  91. set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES ADDITIONAL_CLEAN_FILES ${CMAKE_PROJECT_NAME}.map)
  92. # Validate that STM32CubeMX code is compatible with C standard
  93. if((CMAKE_C_STANDARD EQUAL 90) OR (CMAKE_C_STANDARD EQUAL 99))
  94. message(ERROR "Generated code requires C11 or higher")
  95. endif()