From 1b6acdedc2ae892bece04479a64ad28120eced8c Mon Sep 17 00:00:00 2001 From: JF002 Date: Tue, 1 Jun 2021 21:03:01 +0200 Subject: Enable various compilation flags to reduce the binary size (#401) * Add the following compilation flags: * -fno-exceptions and -fno-non-call-exceptions : disable exception handling * -fno-rtti : disable run time type information (needed by dynamic_cast, for example) These flags reduce the binary size by about 100KB! Also, -fstack-usage generate debug info (not in final binary) to allow tools like Puncover to do a stack analysis. * Remove unused CMake variables in CMake_nRF5x.cmake (duplicated in src/CMakeLists.txt). Replace -O0 by -Og in DEBUG builds. This generates a smaller binary (small enough for the internal memory) that is debugger friendly. --- cmake-nRF5x/CMake_nRF5x.cmake | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'cmake-nRF5x/CMake_nRF5x.cmake') diff --git a/cmake-nRF5x/CMake_nRF5x.cmake b/cmake-nRF5x/CMake_nRF5x.cmake index ead7b9f6..c7d0a68b 100755 --- a/cmake-nRF5x/CMake_nRF5x.cmake +++ b/cmake-nRF5x/CMake_nRF5x.cmake @@ -74,21 +74,6 @@ macro(nRF5x_setup) ) endif () - set(COMMON_FLAGS "-MP -MD -mthumb -mabi=aapcs -Wall -g3 -ffunction-sections -fdata-sections -fno-strict-aliasing -fno-builtin --short-enums ${CPU_FLAGS} -Wreturn-type -Werror=return-type") - - # compiler/assambler/linker flags - set(CMAKE_C_FLAGS "${COMMON_FLAGS}") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g3") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3") - set(CMAKE_CXX_FLAGS "${COMMON_FLAGS}") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") - set(CMAKE_ASM_FLAGS "-MP -MD -x assembler-with-cpp") - set(CMAKE_EXE_LINKER_FLAGS "-mthumb -mabi=aapcs -L ${NRF5_SDK_PATH}/modules/nrfx/mdk -T${NRF5_LINKER_SCRIPT} ${CPU_FLAGS} -Wl,--gc-sections --specs=nano.specs -lc -lnosys -lm") - # note: we must override the default cmake linker flags so that CMAKE_C_FLAGS are not added implicitly - set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_COMPILER} -o ") - set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_C_COMPILER} -lstdc++ -o ") - # basic board definitions and drivers include_directories( "${NRF5_SDK_PATH}/components" -- cgit v1.2.3