From b48a7cc9833924d91c5faea553cdffbe352147c6 Mon Sep 17 00:00:00 2001 From: cuiziwei Date: Sat, 12 Oct 2024 15:30:06 +0800 Subject: [PATCH] Unify the definition of GCCVER and remove duplicate code. Signed-off-by: cuiziwei --- arch/arm/src/cmake/gcc.cmake | 6 ------ arch/arm/src/common/Toolchain.defs | 4 ---- cmake/nuttx_toolchain.cmake | 6 ++++++ libs/libxx/libcxx.cmake | 8 -------- libs/libxx/libcxx.defs | 4 ---- tools/Config.mk | 3 +++ 6 files changed, 9 insertions(+), 22 deletions(-) diff --git a/arch/arm/src/cmake/gcc.cmake b/arch/arm/src/cmake/gcc.cmake index 1a4414314403b..d7a55be9125e0 100644 --- a/arch/arm/src/cmake/gcc.cmake +++ b/arch/arm/src/cmake/gcc.cmake @@ -62,12 +62,6 @@ endif() # array subscript [0] is outside array bounds: # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 -execute_process(COMMAND ${CMAKE_C_COMPILER} --version - OUTPUT_VARIABLE GCC_VERSION_OUTPUT) -string(REGEX MATCH "\\+\\+.* ([0-9]+)\\.[0-9]+" GCC_VERSION_REGEX - "${GCC_VERSION_OUTPUT}") -set(GCCVER ${CMAKE_MATCH_1}) - if(GCCVER EQUAL 12) add_compile_options(--param=min-pagesize=0) if(CONFIG_ARCH_RAMFUNCS) diff --git a/arch/arm/src/common/Toolchain.defs b/arch/arm/src/common/Toolchain.defs index dc1a2b2ccc133..69c3b1b9f40a2 100644 --- a/arch/arm/src/common/Toolchain.defs +++ b/arch/arm/src/common/Toolchain.defs @@ -309,10 +309,6 @@ else # Wrong warning array subscript [0] is outside array bounds: # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 - ifeq ($(GCCVER),) - export GCCVER := $(shell $(CC) --version | grep gcc | sed -E "s/.* ([0-9]+\.[0-9]+).*/\1/" | cut -d'.' -f1) - endif - ifeq ($(GCCVER),12) ARCHOPTIMIZATION += --param=min-pagesize=0 ifeq ($(CONFIG_ARCH_RAMFUNCS),y) diff --git a/cmake/nuttx_toolchain.cmake b/cmake/nuttx_toolchain.cmake index 89face31196e9..1bc7622ca3d2b 100644 --- a/cmake/nuttx_toolchain.cmake +++ b/cmake/nuttx_toolchain.cmake @@ -97,3 +97,9 @@ if(NOT NUTTX_FIND_TOOLCHAIN_LIB_DEFINED) nuttx_add_extra_library(${extra_lib_path}) endfunction() endif() + +execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version + OUTPUT_VARIABLE GCC_VERSION_OUTPUT) +string(REGEX MATCH "\\+\\+.* ([0-9]+)\\.[0-9]+" GCC_VERSION_REGEX + "${GCC_VERSION_OUTPUT}") +set(GCCVER ${CMAKE_MATCH_1}) diff --git a/libs/libxx/libcxx.cmake b/libs/libxx/libcxx.cmake index 73f436ccd1cf9..7eaa6739584ed 100644 --- a/libs/libxx/libcxx.cmake +++ b/libs/libxx/libcxx.cmake @@ -95,14 +95,6 @@ list(APPEND SRCS ${SRCSTMP}) set(FLAGS -Wno-attributes -Wno-deprecated-declarations -Wno-shadow -Wno-sign-compare) -if(NOT DEFINED GCCVER) - execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version - OUTPUT_VARIABLE GCC_VERSION_OUTPUT) - string(REGEX MATCH "\\+\\+.* ([0-9]+)\\.[0-9]+" GCC_VERSION_REGEX - "${GCC_VERSION_OUTPUT}") - set(GCCVER ${CMAKE_MATCH_1}) -endif() - if(GCCVER EQUAL 12) list(APPEND FLAGS -Wno-maybe-uninitialized -Wno-alloc-size-larger-than) endif() diff --git a/libs/libxx/libcxx.defs b/libs/libxx/libcxx.defs index 0740f19393e75..c0e6a2af21adb 100644 --- a/libs/libxx/libcxx.defs +++ b/libs/libxx/libcxx.defs @@ -61,10 +61,6 @@ endif CXXFLAGS += -Wno-shadow -Wno-sign-compare CXXFLAGS += -Wno-attributes -Wno-deprecated-declarations -ifeq ($(GCCVER),) - export GCCVER = $(shell $(CXX) --version | grep ++ | sed -E 's/.* ([0-9]+\.[0-9]+).*/\1/' | cut -d'.' -f1) -endif - ifeq ($(shell expr $(GCCVER) \>= 12), 1) CXXFLAGS += -Wno-maybe-uninitialized -Wno-alloc-size-larger-than endif diff --git a/tools/Config.mk b/tools/Config.mk index 2637786f0eb77..c3c8886b2ec09 100644 --- a/tools/Config.mk +++ b/tools/Config.mk @@ -732,6 +732,9 @@ export DEFINE_PREFIX ?= $(subst X,,${shell $(DEFINE) "$(CC)" X 2> ${EMPTYFILE}}) export INCDIR_PREFIX ?= $(subst "X",,${shell $(INCDIR) "$(CC)" X 2> ${EMPTYFILE}}) export INCSYSDIR_PREFIX ?= $(subst "X",,${shell $(INCDIR) -s "$(CC)" X 2> ${EMPTYFILE}}) +# Get the GCC version number +export GCCVER = $(shell $(CXX) --version | grep ++ | sed -E 's/.* ([0-9]+\.[0-9]+).*/\1/' | cut -d'.' -f1) + # ARCHxxx means the predefined setting(either toolchain, arch, or system specific) ARCHDEFINES += ${DEFINE_PREFIX}__NuttX__ ifeq ($(CONFIG_NDEBUG),y)