CMakeLists.txt 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c
  48. ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c
  49. )
  50. # Drivers Midllewares
  51. # Link directories setup
  52. set(MX_LINK_DIRS
  53. )
  54. # Project static libraries
  55. set(MX_LINK_LIBS
  56. STM32_Drivers
  57. ${TOOLCHAIN_LINK_LIBRARIES}
  58. )
  59. # Interface library for includes and symbols
  60. add_library(stm32cubemx INTERFACE)
  61. target_include_directories(stm32cubemx INTERFACE ${MX_Include_Dirs})
  62. target_compile_definitions(stm32cubemx INTERFACE ${MX_Defines_Syms})
  63. # Create STM32_Drivers static library
  64. add_library(STM32_Drivers OBJECT)
  65. target_sources(STM32_Drivers PRIVATE ${STM32_Drivers_Src})
  66. target_link_libraries(STM32_Drivers PUBLIC stm32cubemx)
  67. # Add STM32CubeMX generated application sources to the project
  68. target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${MX_Application_Src})
  69. # Link directories setup
  70. target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE ${MX_LINK_DIRS})
  71. # Add libraries to the project
  72. target_link_libraries(${CMAKE_PROJECT_NAME} ${MX_LINK_LIBS})
  73. # Add the map file to the list of files to be removed with 'clean' target
  74. set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES ADDITIONAL_CLEAN_FILES ${CMAKE_PROJECT_NAME}.map)
  75. # Validate that STM32CubeMX code is compatible with C standard
  76. if((CMAKE_C_STANDARD EQUAL 90) OR (CMAKE_C_STANDARD EQUAL 99))
  77. message(ERROR "Generated code requires C11 or higher")
  78. endif()