123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- cmake_minimum_required(VERSION 3.20)
- # 项目设置
- project(armfly)
- enable_language(C CXX ASM)
- message("Build type: " ${CMAKE_BUILD_TYPE})
- # 编译脚本设置
- set(CMAKE_C_STANDARD 11)
- set(CMAKE_C_STANDARD_REQUIRED ON)
- set(CMAKE_C_EXTENSIONS ON)
- set(CMAKE_CXX_STANDARD 20)
- set(CMAKE_CXX_STANDARD_REQUIRED ON)
- set(CMAKE_CXX_EXTENSIONS ON)
- #添加的部分,关闭警告
- add_definitions(-w)
- # MCU 参数设置
- set(MCU_PARAMS
- -mthumb
- -mcpu=cortex-m4
- # -mfpu=fpv5-d16
- # -mfloat-abi=hard
- )
- # C 源文件
- file(GLOB_RECURSE C_SRCS
- ${CMAKE_CURRENT_SOURCE_DIR}/Project/main.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Project/stm32f4xx_it.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Project/system_stm32f4xx.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Project/conf/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Project/GCC/startup_stm32f40xx.s
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32F4xx_StdPeriph_Driver/src/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32F4x7_ETH_Driver/src/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32_USB_HOST_Library/Class/MSC/src/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32_USB_HOST_Library/Core/src/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32_USB_OTG_Driver/src/usb_core.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32_USB_OTG_Driver/src/usb_hcd.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32_USB_OTG_Driver/src/usb_hcd_int.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/FATFS/src/ff.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/FATFS/src/option/cc936.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/api/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/apps/tftp/*.c
- # ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/apps/httpd/fs.c
- # ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/apps/httpd/fsdata.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/core/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/core/ipv4/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/core/snmp/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/netif/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/netif/ppp/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uC-CPU/cpu_core.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uC-CPU/ARM-Cortex-M4/GNU/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uC-CPU/ARM-Cortex-M4/GNU/*.s
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uC-LIB/lib_ascii.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uC-LIB/lib_math.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uC-LIB/lib_mem.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uC-LIB/lib_str.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uC-LIB/Ports/ARM-Cortex-M4/GNU/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uC-LIB/Ports/ARM-Cortex-M4/GNU/*.s
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/UCOS-BSP/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uCOS-II/Source/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uCOS-II/Ports/ARM-Cortex-M4/Generic/GNU/*.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uCOS-II/Ports/ARM-Cortex-M4/Generic/GNU/*.s
- ${CMAKE_CURRENT_SOURCE_DIR}/User/*.c
- )
- file(GLOB_RECURSE R_SRCS
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_qspi.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fmpi2c.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fmc.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_cec.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spdifrx.c
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32_USB_HOST_Library/Class/MSC/src/usbh_msc_fatfs.c
- )
- list(REMOVE_ITEM C_SRCS ${R_SRCS})
- # C .h文件
- set(INC_C_DIRS
- ${CMAKE_CURRENT_SOURCE_DIR}/Project
- ${CMAKE_CURRENT_SOURCE_DIR}/Project/conf/fatfs
- ${CMAKE_CURRENT_SOURCE_DIR}/Project/conf/lwip
- ${CMAKE_CURRENT_SOURCE_DIR}/Project/conf/lwip/port
- ${CMAKE_CURRENT_SOURCE_DIR}/Project/conf/lwip/port/arch
- ${CMAKE_CURRENT_SOURCE_DIR}/Project/conf/ucos
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/CMSIS/Include
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/CMSIS/Device/ST/STM32F4xx/Include
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32F4xx_StdPeriph_Driver/inc
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32F4x7_ETH_Driver/inc
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32_USB_HOST_Library/Core/inc
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32_USB_HOST_Library/Class/MSC/inc
- ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/STM32_USB_OTG_Driver/inc
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uC-CPU
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uC-CPU/ARM-Cortex-M4/GNU
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uC-LIB
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uCOS-BSP
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uCOS-II/Source
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/uCOS_II/uCOS-II/Ports/ARM-Cortex-M4/Generic/GNU
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/include
- # ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/apps/httpd
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/include/lwip
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/include/netif
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/include/posix
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/lwip-2.0.2/src/include/posix/sys
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/FATFS/src
- ${CMAKE_CURRENT_SOURCE_DIR}/Third_Party/cJSON
- ${CMAKE_CURRENT_SOURCE_DIR}/User
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/ad7606
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/am2303
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/can
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/dm9k
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/eth
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/ext_sram
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/dwt
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/interface
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/iwdg
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/lcd
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/nand_flash
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/nor_flash
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/sdio
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/spi
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/timer
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/uart
- ${CMAKE_CURRENT_SOURCE_DIR}/User/bsp/usbh
- ${CMAKE_CURRENT_SOURCE_DIR}/User/app
- ${CMAKE_CURRENT_SOURCE_DIR}/User/app/avltree
- ${CMAKE_CURRENT_SOURCE_DIR}/User/app/ftp
- ${CMAKE_CURRENT_SOURCE_DIR}/User/app/iec104
- ${CMAKE_CURRENT_SOURCE_DIR}/User/app/key
- ${CMAKE_CURRENT_SOURCE_DIR}/User/app/queue
- ${CMAKE_CURRENT_SOURCE_DIR}/User/app/tftp
- ${CMAKE_CURRENT_SOURCE_DIR}/User/app/memory
- ${CMAKE_CURRENT_SOURCE_DIR}/User/app/modbus
- ${CMAKE_CURRENT_SOURCE_DIR}/User/app/net
- )
- set(INC_CXX_DIRS)
- set(INC_ASM_DIRS)
- # 链接定义
- set(C_SYMB
- "DEBUG"
- "STM32F40_41xxx"
- "USE_STDPERIPH_DRIVER"
- "USE_USB_OTG_HS"
- "USE_EMBEDDED_PHY"
- )
- set(CXX_SYMB)
- set(ASM_SYMB)
- # 链接静态库或者文件夹
- set(LINK_DIRS)
- set(LINK_LIBS)
- # 链接脚本
- set(LINK_SRC
- ${CMAKE_CURRENT_SOURCE_DIR}/Project/GCC/STM32F417IG_FLASH.ld
- )
- # 编译器参数
- set(compiler_OPTS)
- # 链接脚本参数
- set(LINK_OPTS)
- link_directories(${CMAKE_PROJECT_NAME} ${LINK_DIRS})
- add_executable(${CMAKE_PROJECT_NAME})
- target_sources(${CMAKE_PROJECT_NAME} PUBLIC ${C_SRCS})
- # 添加 include 路径
- target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
- $<$<COMPILE_LANGUAGE:C>: ${INC_C_DIRS}>
- $<$<COMPILE_LANGUAGE:CXX>: ${INC_CXX_DIRS}>
- $<$<COMPILE_LANGUAGE:ASM>: ${INC_ASM_DIRS}>
- )
- # 添加 链接 文件
- target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
- $<$<COMPILE_LANGUAGE:C>: ${C_SYMB}>
- $<$<COMPILE_LANGUAGE:CXX>: ${CXX_SYMB}>
- $<$<COMPILE_LANGUAGE:ASM>: ${ASM_SYMB}>
- $<$<CONFIG:Debug>:DEBUG>
- $<$<CONFIG:Release>: >
- )
- target_link_libraries(${CMAKE_PROJECT_NAME} ${LINK_LIBS})
- # 编译器参数
- target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
- ${MCU_PARAMS}
- ${compiler_OPTS}
- -Wall
- -Wextra
- -Wpedantic
- $<$<COMPILE_LANGUAGE:C>: >
- $<$<COMPILE_LANGUAGE:CXX>:
- # 去除编译警告
- -Wno-unused-variable
- -Wno-pointer-sign
- -Wno-unused-but-set-variable
- -Wno-unused-function
- -Wno-unused-parameter
- -Wno-format=
- # -Wno-volatile
- # -Wold-style-cast
- # -Wuseless-cast
- # -Wsuggest-override
- >
- $<$<COMPILE_LANGUAGE:ASM>:-x assembler-with-cpp -MMD -MP>
- $<$<CONFIG:Debug>:-Og -g3 -ggdb>
- $<$<CONFIG:Release>:-Og -g0>
- )
- # 链接参数
- target_link_options(${CMAKE_PROJECT_NAME} PRIVATE
- -T${LINK_SRC}
- ${MCU_PARAMS}
- ${LINK_OPTS}
- -Wl,-Map=${CMAKE_PROJECT_NAME}.map
- # -u _printf_float
- --specs=nosys.specs
- -Wl,--start-group
- -lc
- -lm
- -lstdc++
- -lsupc++
- -Wl,--end-group
- # Allow good software remapping across address space (with proper GCC section making)
- -Wl,-z,max-page-size=8
- -Wl,--print-memory-usage
- )
- # post-build
- add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
- COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${CMAKE_PROJECT_NAME}>
- )
- # 生成 hex 文件
- add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
- COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.hex
- )
- # 生成 bin 文件
- add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
- COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.bin
- )
|