| 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 |         STM32G473xx | 
|---|
| 8 |     $<$<CONFIG:Debug>:DEBUG> | 
|---|
| 9 | ) | 
|---|
| 10 |  | 
|---|
| 11 | # STM32CubeMX generated include paths | 
|---|
| 12 | set(MX_Include_Dirs | 
|---|
| 13 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Inc | 
|---|
| 14 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Inc | 
|---|
| 15 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Inc/Legacy | 
|---|
| 16 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/CMSIS/Device/ST/STM32G4xx/Include | 
|---|
| 17 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/CMSIS/Include | 
|---|
| 18 | ) | 
|---|
| 19 |  | 
|---|
| 20 | # STM32CubeMX generated application sources | 
|---|
| 21 | set(MX_Application_Src | 
|---|
| 22 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/main.c | 
|---|
| 23 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/gpio.c | 
|---|
| 24 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/adc.c | 
|---|
| 25 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/crc.c | 
|---|
| 26 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/dma.c | 
|---|
| 27 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/fdcan.c | 
|---|
| 28 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/i2c.c | 
|---|
| 29 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/rtc.c | 
|---|
| 30 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/spi.c | 
|---|
| 31 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/usart.c | 
|---|
| 32 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/usb.c | 
|---|
| 33 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/stm32g4xx_it.c | 
|---|
| 34 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/stm32g4xx_hal_msp.c | 
|---|
| 35 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/sysmem.c | 
|---|
| 36 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/syscalls.c | 
|---|
| 37 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../startup_stm32g473xx.s | 
|---|
| 38 | ) | 
|---|
| 39 |  | 
|---|
| 40 | # STM32 HAL/LL Drivers | 
|---|
| 41 | set(STM32_Drivers_Src | 
|---|
| 42 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Core/Src/system_stm32g4xx.c | 
|---|
| 43 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc.c | 
|---|
| 44 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc_ex.c | 
|---|
| 45 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_adc.c | 
|---|
| 46 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal.c | 
|---|
| 47 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc.c | 
|---|
| 48 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc_ex.c | 
|---|
| 49 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash.c | 
|---|
| 50 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ex.c | 
|---|
| 51 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ramfunc.c | 
|---|
| 52 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_gpio.c | 
|---|
| 53 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_exti.c | 
|---|
| 54 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma.c | 
|---|
| 55 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma_ex.c | 
|---|
| 56 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr.c | 
|---|
| 57 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr_ex.c | 
|---|
| 58 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_cortex.c | 
|---|
| 59 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_crc.c | 
|---|
| 60 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_crc_ex.c | 
|---|
| 61 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_fdcan.c | 
|---|
| 62 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c.c | 
|---|
| 63 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c_ex.c | 
|---|
| 64 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rtc.c | 
|---|
| 65 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rtc_ex.c | 
|---|
| 66 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_spi.c | 
|---|
| 67 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_spi_ex.c | 
|---|
| 68 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart.c | 
|---|
| 69 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart_ex.c | 
|---|
| 70 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pcd.c | 
|---|
| 71 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pcd_ex.c | 
|---|
| 72 |     ${CMAKE_CURRENT_SOURCE_DIR}/../../Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_usb.c | 
|---|
| 73 | ) | 
|---|
| 74 |  | 
|---|
| 75 | # Drivers Midllewares | 
|---|
| 76 |  | 
|---|
| 77 |  | 
|---|
| 78 |  | 
|---|
| 79 | # Link directories setup | 
|---|
| 80 | set(MX_LINK_DIRS | 
|---|
| 81 |  | 
|---|
| 82 | ) | 
|---|
| 83 | # Project static libraries | 
|---|
| 84 | set(MX_LINK_LIBS  | 
|---|
| 85 |     STM32_Drivers | 
|---|
| 86 |     ${TOOLCHAIN_LINK_LIBRARIES} | 
|---|
| 87 |      | 
|---|
| 88 | ) | 
|---|
| 89 | # Interface library for includes and symbols | 
|---|
| 90 | add_library(stm32cubemx INTERFACE) | 
|---|
| 91 | target_include_directories(stm32cubemx INTERFACE ${MX_Include_Dirs}) | 
|---|
| 92 | target_compile_definitions(stm32cubemx INTERFACE ${MX_Defines_Syms}) | 
|---|
| 93 |  | 
|---|
| 94 | # Create STM32_Drivers static library | 
|---|
| 95 | add_library(STM32_Drivers OBJECT) | 
|---|
| 96 | target_sources(STM32_Drivers PRIVATE ${STM32_Drivers_Src}) | 
|---|
| 97 | target_link_libraries(STM32_Drivers PUBLIC stm32cubemx) | 
|---|
| 98 |  | 
|---|
| 99 |  | 
|---|
| 100 | # Add STM32CubeMX generated application sources to the project | 
|---|
| 101 | target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${MX_Application_Src}) | 
|---|
| 102 |  | 
|---|
| 103 | # Link directories setup | 
|---|
| 104 | target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE ${MX_LINK_DIRS}) | 
|---|
| 105 |  | 
|---|
| 106 | # Add libraries to the project | 
|---|
| 107 | target_link_libraries(${CMAKE_PROJECT_NAME} ${MX_LINK_LIBS}) | 
|---|
| 108 |  | 
|---|
| 109 | # Add the map file to the list of files to be removed with 'clean' target | 
|---|
| 110 | set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES ADDITIONAL_CLEAN_FILES ${CMAKE_PROJECT_NAME}.map) | 
|---|
| 111 |  | 
|---|
| 112 | # Validate that STM32CubeMX code is compatible with C standard | 
|---|
| 113 | if((CMAKE_C_STANDARD EQUAL 90) OR (CMAKE_C_STANDARD EQUAL 99)) | 
|---|
| 114 |     message(ERROR "Generated code requires C11 or higher") | 
|---|
| 115 | endif() | 
|---|