Skip to content

Commit

Permalink
[cpp] attach CXXFLAGS to reduce the resource consumptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterywolf committed Jun 14, 2023
1 parent c4df1d6 commit 4f5ba63
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bsp/k210/drivers/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if GetDepend('RT_USING_PWM'):
if GetDepend('RT_USING_WDT'):
src += ['drv_wdt.c']

group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=['NNCASE_NO_EXCEPTIONS'])

objs = [group]

Expand Down
4 changes: 4 additions & 0 deletions components/libc/cplusplus/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ if RT_USING_CPLUSPLUS
bool "Enable RT-Thread APIs C++ wrapper"
default n

config RT_USING_CPP_EXCEPTIONS
bool "Enable C++ exceptions (will increase overhead)"
default n

endif
7 changes: 6 additions & 1 deletion components/libc/cplusplus/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ Import('rtconfig')
cwd = GetCurrentDir()
src = ['cxx_crt_init.c', 'cxx_crt.cpp']
CPPPATH = [cwd]
CXXFLAGS = ''

group = DefineGroup('CPP', src, depend=['RT_USING_CPLUSPLUS'], CPPPATH=CPPPATH)

if rtconfig.PLATFORM in ['gcc', 'armclang', 'llvm-arm'] and not GetDepend('RT_USING_CPP_EXCEPTIONS'):
CXXFLAGS += ' -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections' # reduce resource consumptions

group = DefineGroup('CPP', src, depend=['RT_USING_CPLUSPLUS'], CPPPATH=CPPPATH, CXXFLAGS=CXXFLAGS)

list = os.listdir(cwd)
for d in list:
Expand Down
4 changes: 1 addition & 3 deletions components/libc/cplusplus/cpp11/gcc/__utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

#include <rtthread.h>

#define RT_USING_CPP_EXCEPTION

inline void throw_system_error(int err, const char *what_msg)
{
#ifdef RT_USING_CPP_EXCEPTION
#ifdef RT_USING_CPP_EXCEPTIONS
throw std::system_error(std::error_code(err, std::system_category()), what_msg);
#else
(void)err;
Expand Down

0 comments on commit 4f5ba63

Please sign in to comment.