CMakeLists.txt 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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}/../../Drivers/CMSIS/Device/ST/STM32F1xx/Include
  16. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/CMSIS/Include
  17. )
  18. # STM32CubeMX generated application sources
  19. set(MX_Application_Src
  20. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/main.c
  21. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/stm32f1xx_it.c
  22. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/stm32f1xx_hal_msp.c
  23. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/stm32f1xx_hal_timebase_tim.c
  24. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/sysmem.c
  25. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/syscalls.c
  26. ${CMAKE_CURRENT_SOURCE_DIR}/../../startup_stm32f103xb.s
  27. )
  28. # STM32 HAL/LL Drivers
  29. set(STM32_Drivers_Src
  30. ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/system_stm32f1xx.c
  31. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c
  32. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c
  33. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c
  34. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc.c
  35. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc_ex.c
  36. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c
  37. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c
  38. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c
  39. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c
  40. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c
  41. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c
  42. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c
  43. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c
  44. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c
  45. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c
  46. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c
  47. )
  48. # Drivers Midllewares
  49. # Link directories setup
  50. set(MX_LINK_DIRS
  51. )
  52. # Project static libraries
  53. set(MX_LINK_LIBS
  54. STM32_Drivers
  55. ${TOOLCHAIN_LINK_LIBRARIES}
  56. )
  57. # Interface library for includes and symbols
  58. add_library(stm32cubemx INTERFACE)
  59. target_include_directories(stm32cubemx INTERFACE ${MX_Include_Dirs})
  60. target_compile_definitions(stm32cubemx INTERFACE ${MX_Defines_Syms})
  61. # Create STM32_Drivers static library
  62. add_library(STM32_Drivers OBJECT)
  63. target_sources(STM32_Drivers PRIVATE ${STM32_Drivers_Src})
  64. target_link_libraries(STM32_Drivers PUBLIC stm32cubemx)
  65. # Add STM32CubeMX generated application sources to the project
  66. target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${MX_Application_Src})
  67. # Link directories setup
  68. target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE ${MX_LINK_DIRS})
  69. # Add libraries to the project
  70. target_link_libraries(${CMAKE_PROJECT_NAME} ${MX_LINK_LIBS})
  71. # Add the map file to the list of files to be removed with 'clean' target
  72. set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES ADDITIONAL_CLEAN_FILES ${CMAKE_PROJECT_NAME}.map)
  73. # Validate that STM32CubeMX code is compatible with C standard
  74. if((CMAKE_C_STANDARD EQUAL 90) OR (CMAKE_C_STANDARD EQUAL 99))
  75. message(ERROR "Generated code requires C11 or higher")
  76. endif()