Build: Change default build option to MinSizeRel
* By default CMake's Release option builds with -O3,
which isn't efficient for Cortex-M devices,
where we wanted the lowest ROM/RAM usage.
* If TFM_SYSTEM_PROCESSOR is defined, then build and link
with this cpu instead of arch with both
armclang and gcc
Signed-off-by: Dávid Házi <david.hazi@arm.com>
Change-Id: I7550ab435fcf6bb595dcc153665009e47163214b
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b49456a..00f0393 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,12 +23,6 @@
message(FATAL_ERROR "Hardware DSP is currently not supported in TF-M")
endif()
-# The default build type is release. If debug symbols are needed then
-# -DCMAKE_BUILD_TYPE=debug should be used (likewise with other build types)
-if (NOT CMAKE_BUILD_TYPE)
- set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type: [Debug, Release, RelWithDebInfo, MinSizeRel]" FORCE)
-endif()
-
include(config/set_config.cmake)
if(NOT ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles" AND
diff --git a/config/set_config.cmake b/config/set_config.cmake
index 00da442..5f3d644 100644
--- a/config/set_config.cmake
+++ b/config/set_config.cmake
@@ -9,6 +9,12 @@
# docs/getting_started/tfm_build_instructions.rst under Cmake Configuration. If
# the sequence is updated here the docs must also be updated.
+# The default build type is MinSizeRel. If debug symbols are needed then
+# -DCMAKE_BUILD_TYPE=debug should be used (likewise with other build types)
+if (NOT CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE "MinSizeRel" CACHE STRING "Build type: [Debug, Release, RelWithDebInfo, MinSizeRel]" FORCE)
+endif()
+
# Load extra config
if (TFM_EXTRA_CONFIG_PATH)
include(${TFM_EXTRA_CONFIG_PATH})
diff --git a/docs/building/tfm_build_instruction.rst b/docs/building/tfm_build_instruction.rst
index 6d9f50a..62521ff 100644
--- a/docs/building/tfm_build_instruction.rst
+++ b/docs/building/tfm_build_instruction.rst
@@ -96,7 +96,7 @@
Build type
----------
-By default, a release configuration is built. Alternate build types can be
+By default, a MinSizeRel configuration is built. Alternate build types can be
specified with the ``CMAKE_BUILD_TYPE`` variable. The possible
types are:
@@ -105,7 +105,7 @@
- ``Release``
- ``MinSizeRel``
-``Release`` is default.
+``MinSizeRel`` is default.
Debug symbols are added by default to all builds, but can be removed
from ``Release`` and ``MinSizeRel`` builds by setting
diff --git a/toolchain_ARMCLANG.cmake b/toolchain_ARMCLANG.cmake
index 01d1423..403a9c1 100644
--- a/toolchain_ARMCLANG.cmake
+++ b/toolchain_ARMCLANG.cmake
@@ -180,12 +180,10 @@
" Please use other Armclang versions instead.")
endif()
- # Cmake's armclang support will set either mcpu or march, but march gives
- # better code size so we manually set it.
- set(CMAKE_C_FLAGS "-march=${CMAKE_SYSTEM_ARCH}")
set(CMAKE_ASM_FLAGS ${CMAKE_ASM_FLAGS_INIT})
if (DEFINED TFM_SYSTEM_PROCESSOR)
+ set(CMAKE_C_FLAGS "-mcpu=${CMAKE_SYSTEM_PROCESSOR}")
set(CMAKE_C_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
set(CMAKE_ASM_LINK_FLAGS "--cpu=${CMAKE_SYSTEM_PROCESSOR}")
# But armlink doesn't support this +dsp syntax
@@ -197,6 +195,8 @@
string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
string(REGEX REPLACE "\\+nomve" ".no_mve" CMAKE_ASM_LINK_FLAGS "${CMAKE_ASM_LINK_FLAGS}")
+ else()
+ set(CMAKE_C_FLAGS "-march=${CMAKE_SYSTEM_ARCH}")
endif()
# Workaround for issues with --depend-single-line with armasm and Ninja
diff --git a/toolchain_GNUARM.cmake b/toolchain_GNUARM.cmake
index 320ede1..f9c620a 100644
--- a/toolchain_GNUARM.cmake
+++ b/toolchain_GNUARM.cmake
@@ -171,6 +171,11 @@
# For GNU Arm Embedded Toolchain doesn't emit __ARM_ARCH_8_1M_MAIN__, adding this macro manually.
add_compile_definitions($<$<STREQUAL:${TFM_SYSTEM_ARCHITECTURE},armv8.1-m.main>:__ARM_ARCH_8_1M_MAIN__>)
+
+ # CMAKE_BUILD_TYPE=MinSizeRel default parameter is -Os.
+ # In ARMCLANG we redefined this variable to use -Oz level, but GCC still using -Os!
+ # GCC 11 not supports -Oz level, version 12 will.
+ # When this option will be available in GNUARM, set -Oz flag for both toolchains.
endmacro()
# Configure environment for the compiler setup run by cmake at the first