Skip to content

Commit 408decf

Browse files
committed
Improve exceptions configuration for IDF framework // Issue espressif#24
1 parent 4828aef commit 408decf

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

builder/frameworks/espidf.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,35 @@ def build_arduino_framework():
422422
)
423423

424424

425+
def configure_exceptions(sdk_params):
426+
# Exceptions might be configured using a special PIO macro or
427+
# directly in sdkconfig.h
428+
cppdefines = env.Flatten(env.get("CPPDEFINES", []))
429+
pio_exceptions = "PIO_FRAMEWORK_ESP_IDF_ENABLE_EXCEPTIONS" in cppdefines
430+
config_exceptions = int(sdk_params.get("CONFIG_CXX_EXCEPTIONS", 0)) != 0
431+
432+
if pio_exceptions or config_exceptions:
433+
# remove unnecessary flag defined in main.py that disables exceptions
434+
try:
435+
index = env['CXXFLAGS'].index("-fno-exceptions")
436+
if index > 0:
437+
env['CXXFLAGS'].remove("-fno-exceptions")
438+
except IndexError:
439+
pass
440+
441+
env.Append(CXXFLAGS=["-fexceptions"])
442+
443+
if pio_exceptions:
444+
env.Append(
445+
CPPDEFINES=[
446+
("CONFIG_CXX_EXCEPTIONS", 1),
447+
("CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE", 0)
448+
]
449+
)
450+
else:
451+
env.Append(LINKFLAGS=["-u", "__cxx_fatal_exception"])
452+
453+
425454
env.Prepend(
426455
CPPPATH=[
427456
join(FRAMEWORK_DIR, "components", "app_trace", "include"),
@@ -569,31 +598,6 @@ def build_arduino_framework():
569598
]
570599
)
571600

572-
cppdefines = env.Flatten(env.get("CPPDEFINES", []))
573-
574-
if "PIO_FRAMEWORK_ESP_IDF_ENABLE_EXCEPTIONS" in cppdefines:
575-
576-
# remove unnecessary flag defined in main.py that disables exceptions
577-
try:
578-
index = env['CXXFLAGS'].index("-fno-exceptions")
579-
if index > 0:
580-
env['CXXFLAGS'].remove("-fno-exceptions")
581-
except IndexError:
582-
pass
583-
584-
env.Append(
585-
CPPDEFINES=[
586-
("CONFIG_CXX_EXCEPTIONS", 1),
587-
("CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE", 0)
588-
],
589-
590-
CXXFLAGS=["-fexceptions"]
591-
)
592-
593-
else:
594-
env.Append(LINKFLAGS=["-u", "__cxx_fatal_exception"])
595-
596-
597601
#
598602
# ESP-IDF doesn't need assembler-with-cpp option
599603
#
@@ -631,6 +635,8 @@ def build_arduino_framework():
631635

632636
sdk_params = get_sdk_configuration(sdk_config_file)
633637

638+
configure_exceptions(sdk_params)
639+
634640
#
635641
# Generate partition table
636642
#

0 commit comments

Comments
 (0)