Skip to content

Commit

Permalink
build firmware with -O2 optimization level to reduce size
Browse files Browse the repository at this point in the history
  • Loading branch information
devbis committed Oct 16, 2023
1 parent b338837 commit da665e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ SET(CMAKE_BUILD_TYPE Release)
include(cmake/TelinkSDK.cmake)

# Main project settings
PROJECT(z03mmc C)

CMAKE_MINIMUM_REQUIRED(VERSION 3.8)
PROJECT(z03mmc C)
ENABLE_LANGUAGE(ASM)

ADD_SUBDIRECTORY(src)
8 changes: 7 additions & 1 deletion cmake/TelinkSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ ENDIF()

set(TELINK_PLATFORM "8258")

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")
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")
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")

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")

MACRO(REMOVE_C_FLAG flag)
string(REPLACE "${flag}" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
ENDMACRO()

# reduce size by 15% using -O2 instead of -O3
REMOVE_C_FLAG("-O3")

FUNCTION(ADD_BIN_TARGET TARGET TOOLS_PATH)
IF(EXECUTABLE_OUTPUT_PATH)
Expand Down

0 comments on commit da665e3

Please sign in to comment.