[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)
|
cmake_minimum_required(VERSION 3.15)
|
||||||
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/tools/cmake/riscv64-unknown-elf-gcc.cmake)
|
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/compiler_flags.cmake)
|
||||||
include(${CMAKE_SOURCE_DIR}/tools/cmake/tools.cmake)
|
include(${CMAKE_SOURCE_DIR}/tools/cmake/tools.cmake)
|
||||||
|
|
||||||
PROJECT(${BOARD} C CXX ASM)
|
PROJECT(${BOARD} C CXX ASM)
|
||||||
|
|
||||||
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
# set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||||
ENABLE_LANGUAGE(ASM)
|
ENABLE_LANGUAGE(ASM)
|
||||||
|
|
||||||
|
17
Makefile
17
Makefile
@ -5,16 +5,7 @@ APP?=helloworld
|
|||||||
CPU_ID?=none
|
CPU_ID?=none
|
||||||
COMx?=
|
COMx?=
|
||||||
|
|
||||||
SUPPORT_SHELL?=n
|
|
||||||
SUPPORT_FREERTOS?=n
|
|
||||||
SUPPORT_CRYPTO?=n
|
|
||||||
SUPPORT_LVGL?=n
|
|
||||||
SUPPORT_FLOAT?=n
|
SUPPORT_FLOAT?=n
|
||||||
SUPPORT_BLE?=n
|
|
||||||
SUPPORT_XZ?=n
|
|
||||||
SUPPORT_LWIP?=n
|
|
||||||
SUPPORT_TFLITE?=n
|
|
||||||
|
|
||||||
INTERFACE?=uart
|
INTERFACE?=uart
|
||||||
BAUDRATE ?=2000000
|
BAUDRATE ?=2000000
|
||||||
|
|
||||||
@ -25,15 +16,7 @@ export CHIP
|
|||||||
export APP_DIR
|
export APP_DIR
|
||||||
export APP
|
export APP
|
||||||
export CPU_ID
|
export CPU_ID
|
||||||
export SUPPORT_SHELL
|
|
||||||
export SUPPORT_FREERTOS
|
|
||||||
export SUPPORT_CRYPTO
|
|
||||||
export SUPPORT_LVGL
|
|
||||||
export SUPPORT_FLOAT
|
export SUPPORT_FLOAT
|
||||||
export SUPPORT_BLE
|
|
||||||
export SUPPORT_XZ
|
|
||||||
export SUPPORT_LWIP
|
|
||||||
export SUPPORT_TFLITE
|
|
||||||
|
|
||||||
# The command to remove a file.
|
# The command to remove a file.
|
||||||
RM = cmake -E rm -rf
|
RM = cmake -E rm -rf
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
set(BSP_COMMON_DIR ${CMAKE_SOURCE_DIR}/bsp/bsp_common)
|
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_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(mains main.c)
|
||||||
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/examples/ble/bl702_flash_ble.ld)
|
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/examples/ble/bl702_flash_ble.ld)
|
||||||
generate_bin()
|
generate_bin()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
set(BSP_COMMON_DIR ${CMAKE_SOURCE_DIR}/bsp/bsp_common)
|
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_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(mains main.c)
|
||||||
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/examples/ble/bl702_flash_ble.ld)
|
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/examples/ble/bl702_flash_ble.ld)
|
||||||
generate_bin()
|
generate_bin()
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
set(BSP_COMMON_DIR ${CMAKE_SOURCE_DIR}/bsp/bsp_common)
|
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)
|
set(TARGET_REQUIRED_LIBS fatfs)
|
||||||
endif()
|
|
||||||
|
|
||||||
set(TARGET_REQUIRED_PRIVATE_INCLUDE ${BSP_COMMON_DIR}/es8388 ${BSP_COMMON_DIR}/spi_sd )
|
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(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)
|
set(mains main.c)
|
||||||
|
@ -5,14 +5,6 @@ endif
|
|||||||
cmake_definition+= -DCHIP=$(CHIP)
|
cmake_definition+= -DCHIP=$(CHIP)
|
||||||
cmake_definition+= -DBOARD=$(BOARD)
|
cmake_definition+= -DBOARD=$(BOARD)
|
||||||
cmake_definition+= -DSUPPORT_FLOAT=$(SUPPORT_FLOAT)
|
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_DIR=$(APP_DIR)
|
||||||
cmake_definition+= -DAPP=$(APP)
|
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 -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 -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)
|
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)
|
list(APPEND GLOBAL_LD_FLAGS -u _printf_float)
|
||||||
endif()
|
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-rtti>)
|
||||||
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>)
|
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)
|
foreach(mainfile IN LISTS mains)
|
||||||
# Get file name without directory
|
# Get file name without directory
|
||||||
get_filename_component(mainname ${mainfile} NAME_WE)
|
get_filename_component(mainname ${mainfile} NAME_WE)
|
||||||
@ -107,12 +117,10 @@ function(generate_bin)
|
|||||||
else()
|
else()
|
||||||
if(${above_relative_dir_name} STREQUAL "examples")
|
if(${above_relative_dir_name} STREQUAL "examples")
|
||||||
set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/out/${APP_DIR}/${current_relative_dir_name})
|
set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/out/${APP_DIR}/${current_relative_dir_name})
|
||||||
set(target_name ${current_relative_dir_name}_${mainname})
|
|
||||||
else()
|
else()
|
||||||
set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/out/${APP_DIR}/${above_relative_dir_name}/${current_relative_dir_name})
|
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()
|
endif()
|
||||||
|
set(target_name ${current_relative_dir_name})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
file(MAKE_DIRECTORY ${OUTPUT_DIR})
|
file(MAKE_DIRECTORY ${OUTPUT_DIR})
|
||||||
@ -205,55 +213,17 @@ endif()
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(check_add_library target_name directory)
|
function(check_add_library target_name directory)
|
||||||
if(NOT TARGET ${target_name})
|
if(IS_DIRECTORY ${directory})
|
||||||
add_subdirectory(${directory} ${CMAKE_SOURCE_DIR}/build/libraries/${target_name})
|
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()
|
endif()
|
||||||
endfunction()
|
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)
|
|
Reference in New Issue
Block a user