[chore][cmake] refactor cmake building style,remove all components support,using auto component building instead
This commit is contained in:
parent
a1912eeec1
commit
46ed669b1a
@ -1,10 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/tools/cmake/riscv64-unknown-elf-gcc.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/drivers/${CHIP}_driver/cpu_flags.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/tools/cmake/compiler_flags.cmake)
|
||||
include(${CMAKE_SOURCE_DIR}/tools/cmake/tools.cmake)
|
||||
|
||||
PROJECT(${BOARD} C CXX ASM)
|
||||
|
||||
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
ENABLE_LANGUAGE(ASM)
|
||||
|
||||
|
17
Makefile
17
Makefile
@ -5,16 +5,7 @@ APP?=helloworld
|
||||
CPU_ID?=none
|
||||
COMx?=
|
||||
|
||||
SUPPORT_SHELL?=n
|
||||
SUPPORT_FREERTOS?=n
|
||||
SUPPORT_CRYPTO?=n
|
||||
SUPPORT_LVGL?=n
|
||||
SUPPORT_FLOAT?=n
|
||||
SUPPORT_BLE?=n
|
||||
SUPPORT_XZ?=n
|
||||
SUPPORT_LWIP?=n
|
||||
SUPPORT_TFLITE?=n
|
||||
|
||||
INTERFACE?=uart
|
||||
BAUDRATE ?=2000000
|
||||
|
||||
@ -25,15 +16,7 @@ export CHIP
|
||||
export APP_DIR
|
||||
export APP
|
||||
export CPU_ID
|
||||
export SUPPORT_SHELL
|
||||
export SUPPORT_FREERTOS
|
||||
export SUPPORT_CRYPTO
|
||||
export SUPPORT_LVGL
|
||||
export SUPPORT_FLOAT
|
||||
export SUPPORT_BLE
|
||||
export SUPPORT_XZ
|
||||
export SUPPORT_LWIP
|
||||
export SUPPORT_TFLITE
|
||||
|
||||
# The command to remove a file.
|
||||
RM = cmake -E rm -rf
|
||||
|
@ -1,6 +1,6 @@
|
||||
set(BSP_COMMON_DIR ${CMAKE_SOURCE_DIR}/bsp/bsp_common)
|
||||
set(TARGET_REQUIRED_SRCS ${CMAKE_CURRENT_LIST_DIR}/ble_central_tp_client.c)
|
||||
set(TARGET_REQUIRED_LIBS ble)
|
||||
set(TARGET_REQUIRED_LIBS freertos ble)
|
||||
set(mains main.c)
|
||||
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/examples/ble/bl702_flash_ble.ld)
|
||||
generate_bin()
|
||||
|
@ -1,6 +1,6 @@
|
||||
set(BSP_COMMON_DIR ${CMAKE_SOURCE_DIR}/bsp/bsp_common)
|
||||
set(TARGET_REQUIRED_SRCS ${CMAKE_CURRENT_LIST_DIR}/ble_peripheral_tp_server.c)
|
||||
set(TARGET_REQUIRED_LIBS ble)
|
||||
set(TARGET_REQUIRED_LIBS freertos ble)
|
||||
set(mains main.c)
|
||||
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/examples/ble/bl702_flash_ble.ld)
|
||||
generate_bin()
|
||||
|
@ -1,11 +1,5 @@
|
||||
set(BSP_COMMON_DIR ${CMAKE_SOURCE_DIR}/bsp/bsp_common)
|
||||
|
||||
if(${SUPPORT_SHELL} STREQUAL "y")
|
||||
set(TARGET_REQUIRED_LIBS fatfs shell)
|
||||
else()
|
||||
set(TARGET_REQUIRED_LIBS fatfs)
|
||||
endif()
|
||||
|
||||
set(TARGET_REQUIRED_PRIVATE_INCLUDE ${BSP_COMMON_DIR}/es8388 ${BSP_COMMON_DIR}/spi_sd )
|
||||
set(TARGET_REQUIRED_SRCS ${BSP_COMMON_DIR}/es8388/bsp_es8388.c ${BSP_COMMON_DIR}/fatfs/fatfs_spi_sd.c ${BSP_COMMON_DIR}/spi_sd/bsp_spi_sd.c wav_play_from_sd_card.c sd_play_shell.c)
|
||||
set(mains main.c)
|
||||
|
@ -5,14 +5,6 @@ endif
|
||||
cmake_definition+= -DCHIP=$(CHIP)
|
||||
cmake_definition+= -DBOARD=$(BOARD)
|
||||
cmake_definition+= -DSUPPORT_FLOAT=$(SUPPORT_FLOAT)
|
||||
cmake_definition+= -DSUPPORT_SHELL=$(SUPPORT_SHELL)
|
||||
cmake_definition+= -DSUPPORT_FREERTOS=$(SUPPORT_FREERTOS)
|
||||
cmake_definition+= -DSUPPORT_CRYPTO=$(SUPPORT_CRYPTO)
|
||||
cmake_definition+= -DSUPPORT_LVGL=$(SUPPORT_LVGL)
|
||||
cmake_definition+= -DSUPPORT_BLE=$(SUPPORT_BLE)
|
||||
cmake_definition+= -DSUPPORT_XZ=$(SUPPORT_XZ)
|
||||
cmake_definition+= -DSUPPORT_LWIP=$(SUPPORT_LWIP)
|
||||
cmake_definition+= -DSUPPORT_TFLITE=$(SUPPORT_TFLITE)
|
||||
cmake_definition+= -DAPP_DIR=$(APP_DIR)
|
||||
cmake_definition+= -DAPP=$(APP)
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
include(${CMAKE_SOURCE_DIR}/drivers/${CHIP}_driver/cpu_flags.cmake)
|
||||
|
||||
list(APPEND GLOBAL_C_FLAGS -Os -g3)
|
||||
list(APPEND GLOBAL_C_FLAGS -fshort-enums -fno-common -fms-extensions -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -ffast-math)
|
||||
list(APPEND GLOBAL_C_FLAGS -Wall -Wshift-negative-value -Wchar-subscripts -Wformat -Wuninitialized -Winit-self -Wignored-qualifiers -Wunused -Wundef)
|
||||
@ -15,7 +13,9 @@ if(${SUPPORT_FLOAT} STREQUAL "y")
|
||||
list(APPEND GLOBAL_LD_FLAGS -u _printf_float)
|
||||
endif()
|
||||
|
||||
# if(${SUPPORT_BACKTRACE} STREQUAL "y")
|
||||
# list(APPEND GLOBAL_C_FLAGS -fno-omit-frame-pointer)
|
||||
# endif()
|
||||
|
||||
|
||||
|
||||
if(${SUPPORT_SHELL} STREQUAL "y")
|
||||
list(APPEND GLOBAL_C_FLAGS -DSHELL_SUPPORT)
|
||||
endif()
|
||||
|
@ -95,8 +95,18 @@ function(generate_bin)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>)
|
||||
|
||||
check_all_library()
|
||||
# add basic library which is built by add_library
|
||||
check_add_library(common ${CMAKE_SOURCE_DIR}/common)
|
||||
check_add_library(${CHIP}_driver ${CMAKE_SOURCE_DIR}/drivers/${CHIP}_driver)
|
||||
|
||||
# add other libraries which are target or extern library
|
||||
if(TARGET_REQUIRED_LIBS)
|
||||
foreach(lib ${TARGET_REQUIRED_LIBS})
|
||||
check_add_library(${lib} ${CMAKE_SOURCE_DIR}/components/${lib})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# list mains to execute,now is executing one elf
|
||||
foreach(mainfile IN LISTS mains)
|
||||
# Get file name without directory
|
||||
get_filename_component(mainname ${mainfile} NAME_WE)
|
||||
@ -107,12 +117,10 @@ function(generate_bin)
|
||||
else()
|
||||
if(${above_relative_dir_name} STREQUAL "examples")
|
||||
set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/out/${APP_DIR}/${current_relative_dir_name})
|
||||
set(target_name ${current_relative_dir_name}_${mainname})
|
||||
else()
|
||||
set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/out/${APP_DIR}/${above_relative_dir_name}/${current_relative_dir_name})
|
||||
set(target_name ${current_relative_dir_name}_${mainname})
|
||||
endif()
|
||||
|
||||
set(target_name ${current_relative_dir_name})
|
||||
endif()
|
||||
|
||||
file(MAKE_DIRECTORY ${OUTPUT_DIR})
|
||||
@ -205,55 +213,17 @@ endif()
|
||||
endfunction()
|
||||
|
||||
function(check_add_library target_name directory)
|
||||
if(NOT TARGET ${target_name})
|
||||
add_subdirectory(${directory} ${CMAKE_SOURCE_DIR}/build/libraries/${target_name})
|
||||
if(IS_DIRECTORY ${directory})
|
||||
if(NOT TARGET ${target_name})
|
||||
add_subdirectory(${directory} ${CMAKE_SOURCE_DIR}/build/libraries/${target_name})
|
||||
endif()
|
||||
elseif()
|
||||
if(EXISTS ${target_name})
|
||||
get_filename_component(lib_relative_dir ${target_name} DIRECTORY)
|
||||
get_filename_component(library_name ${target_name} NAME_WE)
|
||||
message(STATUS "[register extern library component: ${library_name}], path:${lib_relative_dir}")
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "both ${target_name} and ${directory} is not exist")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(check_all_library)
|
||||
check_add_library(common ${CMAKE_SOURCE_DIR}/common)
|
||||
check_add_library(fatfs ${CMAKE_SOURCE_DIR}/components/fatfs)
|
||||
check_add_library(usb_stack ${CMAKE_SOURCE_DIR}/components/usb_stack)
|
||||
|
||||
if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/drivers/${CHIP}_driver)
|
||||
check_add_library(${CHIP}_driver ${CMAKE_SOURCE_DIR}/drivers/${CHIP}_driver)
|
||||
endif()
|
||||
|
||||
if(${SUPPORT_SHELL} STREQUAL "y")
|
||||
check_add_library(shell ${CMAKE_SOURCE_DIR}/components/shell)
|
||||
endif()
|
||||
if(${SUPPORT_FREERTOS} STREQUAL "y")
|
||||
check_add_library(freertos ${CMAKE_SOURCE_DIR}/components/freertos)
|
||||
endif()
|
||||
|
||||
if(${SUPPORT_CRYPTO} STREQUAL "sw" OR ${SUPPORT_CRYPTO} STREQUAL "hw")
|
||||
check_add_library(bflb_port ${CMAKE_SOURCE_DIR}/components/mbedtls/bflb_port)
|
||||
endif()
|
||||
|
||||
if(${SUPPORT_LVGL} STREQUAL "y")
|
||||
check_add_library(lvgl ${CMAKE_SOURCE_DIR}/components/lvgl)
|
||||
endif()
|
||||
|
||||
if(${SUPPORT_XZ} STREQUAL "y")
|
||||
check_add_library(xz ${CMAKE_SOURCE_DIR}/components/xz)
|
||||
endif()
|
||||
|
||||
if(${SUPPORT_BLE} STREQUAL "y")
|
||||
if(${SUPPORT_FREERTOS} STREQUAL "n")
|
||||
message(FATAL_ERROR "ble need freertos,so you should set SUPPORT_FREERTOS=y")
|
||||
endif()
|
||||
check_add_library(ble ${CMAKE_SOURCE_DIR}/components/ble)
|
||||
endif()
|
||||
|
||||
if(${SUPPORT_LWIP} STREQUAL "y")
|
||||
if(${SUPPORT_FREERTOS} STREQUAL "n")
|
||||
message(FATAL_ERROR "lwip need freertos,so you should set SUPPORT_FREERTOS=y")
|
||||
endif()
|
||||
check_add_library(lwip ${CMAKE_SOURCE_DIR}/components/lwip)
|
||||
endif()
|
||||
|
||||
if(${SUPPORT_TFLITE} STREQUAL "y")
|
||||
check_add_library(tflite ${CMAKE_SOURCE_DIR}/components/tflite)
|
||||
endif()
|
||||
|
||||
endfunction(check_all_library)
|
||||
endfunction()
|
Reference in New Issue
Block a user