From 0c23387317b4f9f5df0592035d100d89161441ef Mon Sep 17 00:00:00 2001 From: fenugrec Date: Mon, 5 Dec 2022 14:08:22 -0500 Subject: [PATCH] cmake : remove some duplication in add_XYZ_target --- CMakeLists.txt | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d462f1f..1ff402f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,64 +202,47 @@ populate_ldscript(CPU_FAMILY STM32G0B1XK ######### commands for adding each target have a lot in common: make helper func. # Split into two categories, F042-based and F072-based. -function(add_f042_target TGTNAME) - set(CPU_FAMILY STM32F042X6) +function(add_target_common TGTNAME CPU_FAMILY) add_executable(${TGTNAME}_fw ${SOURCE_FILES}) add_dependencies(${TGTNAME}_fw version_h) target_include_directories(${TGTNAME}_fw PRIVATE include/ ${CMAKE_CURRENT_BINARY_DIR}) - target_compile_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_F0}) - target_compile_definitions(${TGTNAME}_fw PRIVATE BOARD_${TGTNAME} STM32F0) - target_link_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_F0}) target_link_options(${TGTNAME}_fw PRIVATE -T ${CPU_FAMILY}_processed.ld) - target_link_libraries(${TGTNAME}_fw PRIVATE STM32_HAL_STM32F042x6 STM32_USB_Device_Library_STM32F042x6) make_bin_file(${TGTNAME}_fw) dfu_flash(${TGTNAME}_fw) show_object_size(${TGTNAME}_fw) endfunction() +function(add_f042_target TGTNAME) + add_target_common(${TGTNAME} STM32F042X6) + target_compile_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_F0}) + target_compile_definitions(${TGTNAME}_fw PRIVATE BOARD_${TGTNAME} STM32F0) + target_link_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_F0}) + target_link_libraries(${TGTNAME}_fw PRIVATE STM32_HAL_STM32F042x6 STM32_USB_Device_Library_STM32F042x6) +endfunction() + function(add_f072_target TGTNAME) - set(CPU_FAMILY STM32F072XB) - add_executable(${TGTNAME}_fw ${SOURCE_FILES}) - add_dependencies(${TGTNAME}_fw version_h) - target_include_directories(${TGTNAME}_fw PRIVATE include/ ${CMAKE_CURRENT_BINARY_DIR}) + add_target_common(${TGTNAME} STM32F072XB) target_compile_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_F0}) target_compile_definitions(${TGTNAME}_fw PRIVATE BOARD_${TGTNAME} STM32F0) target_link_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_F0}) - target_link_options(${TGTNAME}_fw PRIVATE -T ${CPU_FAMILY}_processed.ld) target_link_libraries(${TGTNAME}_fw PRIVATE STM32_HAL_STM32F072xB STM32_USB_Device_Library_STM32F072xB) - make_bin_file(${TGTNAME}_fw) - dfu_flash(${TGTNAME}_fw) - show_object_size(${TGTNAME}_fw) + endfunction() function(add_f407_target TGTNAME) - set(CPU_FAMILY STM32F407XE) - add_executable(${TGTNAME}_fw ${SOURCE_FILES}) - add_dependencies(${TGTNAME}_fw version_h) - target_include_directories(${TGTNAME}_fw PRIVATE include/ ${CMAKE_CURRENT_BINARY_DIR}) + add_target_common(${TGTNAME} STM32F407XE) target_compile_definitions(${TGTNAME}_fw PRIVATE BOARD_${TGTNAME} STM32F4) target_compile_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_F4}) target_link_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_F4}) - target_link_options(${TGTNAME}_fw PRIVATE -T ${CPU_FAMILY}_processed.ld) target_link_libraries(${TGTNAME}_fw PRIVATE STM32_HAL_STM32F407xE STM32_USB_Device_Library_STM32F407xE) - make_bin_file(${TGTNAME}_fw) - dfu_flash(${TGTNAME}_fw) - show_object_size(${TGTNAME}_fw) endfunction() function(add_g0b1_target TGTNAME) - set(CPU_FAMILY STM32G0B1XK) - add_executable(${TGTNAME}_fw ${SOURCE_FILES}) - add_dependencies(${TGTNAME}_fw version_h) - target_include_directories(${TGTNAME}_fw PRIVATE include/ ${CMAKE_CURRENT_BINARY_DIR}) + add_target_common(${TGTNAME} STM32G0B1XK) target_compile_definitions(${TGTNAME}_fw PRIVATE BOARD_${TGTNAME} STM32G0) target_compile_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_G0}) target_link_options(${TGTNAME}_fw BEFORE PRIVATE ${CPUFLAGS_G0}) - target_link_options(${TGTNAME}_fw PRIVATE -T ${CPU_FAMILY}_processed.ld) target_link_libraries(${TGTNAME}_fw PRIVATE STM32_HAL_STM32G0B1xK STM32_USB_Device_Library_STM32G0B1xK) - make_bin_file(${TGTNAME}_fw) - dfu_flash(${TGTNAME}_fw) - show_object_size(${TGTNAME}_fw) endfunction() ########## generate list of targets.