Skip to content

Commit da665e3

Browse files
committed
build firmware with -O2 optimization level to reduce size
1 parent b338837 commit da665e3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ SET(CMAKE_BUILD_TYPE Release)
66
include(cmake/TelinkSDK.cmake)
77

88
# Main project settings
9-
PROJECT(z03mmc C)
109

1110
CMAKE_MINIMUM_REQUIRED(VERSION 3.8)
11+
PROJECT(z03mmc C)
1212
ENABLE_LANGUAGE(ASM)
1313

1414
ADD_SUBDIRECTORY(src)

cmake/TelinkSDK.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ ENDIF()
2020

2121
set(TELINK_PLATFORM "8258")
2222

23-
SET(CMAKE_C_FLAGS "-ffunction-sections -fdata-sections -Wall -fpack-struct -fshort-enums -finline-small-functions -std=gnu99 -fshort-wchar -fms-extensions -nostdlib" CACHE INTERNAL "c compiler flags")
23+
SET(CMAKE_C_FLAGS "-O2 -ffunction-sections -fdata-sections -Wall -fpack-struct -fshort-enums -finline-small-functions -std=gnu99 -fshort-wchar -fms-extensions -nostdlib" CACHE INTERNAL "c compiler flags")
2424
SET(CMAKE_ASM_FLAGS "-fomit-frame-pointer -fshort-enums -Wall -Wpacked -Wcast-align -fdata-sections -ffunction-sections -fno-use-cxa-atexit -fno-threadsafe-statics" CACHE INTERNAL "asm compiler flags")
2525

2626
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections -Wl,-uss_apsmeSwitchKeyReq -Os -fshort-enums -nostartfiles -fno-rtti -fno-exceptions -fno-use-cxa-atexit -fno-threadsafe-statics -Wl,--gc-sections " CACHE INTERNAL "executable linker flags")
2727

28+
MACRO(REMOVE_C_FLAG flag)
29+
string(REPLACE "${flag}" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
30+
ENDMACRO()
31+
32+
# reduce size by 15% using -O2 instead of -O3
33+
REMOVE_C_FLAG("-O3")
2834

2935
FUNCTION(ADD_BIN_TARGET TARGET TOOLS_PATH)
3036
IF(EXECUTABLE_OUTPUT_PATH)

0 commit comments

Comments
 (0)