Build: add build type support
Refactor cmake files to support setting the "build type" following CMake
idioms. A "build type" is a set of compiler flags controlling code
optimization and debug information generation. For more information on
the supported types and their meaning please refer to the documentation.
This change extends build type support to external components too. The
build type of each component can be independently controlled using
command line settings. For details about the supported types and
settings, please refer to the cmake file of the external component and
the documentation of the external project.
This change tries to be backwards compatible and selects the default
build type to be "Debug". This may change in the future.
Change-Id: Ic041140bb8d4aaf0f07be9c4cac0638c03996eb5
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
diff --git a/components/service/spm_test/spm_test.cmake b/components/service/spm_test/spm_test.cmake
index 484892a..f4add98 100644
--- a/components/service/spm_test/spm_test.cmake
+++ b/components/service/spm_test/spm_test.cmake
@@ -47,33 +47,18 @@
${TS_ROOT}/components/service/spm_test
)
+if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ target_compile_options(spm-test${SP_NUMBER} PRIVATE
+ -std=c99
+ )
+endif()
+
#-------------------------------------------------------------------------------
# Deployment specific source files
#-------------------------------------------------------------------------------
target_sources(spm-test${SP_NUMBER} PRIVATE
${TS_ROOT}/components/service/spm_test/sp.c
)
-if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_options(spm-test${SP_NUMBER} PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
- -O0
- $<$<COMPILE_LANGUAGE:C>:-std=c99>
- $<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>
- )
-
- # Options for GCC that control linking
- target_link_options(spm-test${SP_NUMBER} PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(spm-test${SP_NUMBER} PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list
- )
-endif()
compiler_generate_stripped_elf(TARGET spm-test${SP_NUMBER} NAME "${SP_UUID_CANON}.stripped.elf" RES STRIPPED_ELF)
diff --git a/deployments/attestation/opteesp/CMakeLists.txt b/deployments/attestation/opteesp/CMakeLists.txt
index c38be06..fa58a4d 100644
--- a/deployments/attestation/opteesp/CMakeLists.txt
+++ b/deployments/attestation/opteesp/CMakeLists.txt
@@ -63,23 +63,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(attestation PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
- -O0
-std=c99
)
- # Options for GCC that control linking
- target_link_options(attestation PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(attestation PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list
- )
endif()
compiler_generate_stripped_elf(TARGET attestation NAME "${SP_UUID_CANON}.stripped.elf" RES STRIPPED_ELF)
diff --git a/deployments/attestation/sp/CMakeLists.txt b/deployments/attestation/sp/CMakeLists.txt
index f6c94c2..08d130e 100644
--- a/deployments/attestation/sp/CMakeLists.txt
+++ b/deployments/attestation/sp/CMakeLists.txt
@@ -59,21 +59,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(attestation PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
-std=c99
)
- # Options for GCC that control linking
- target_link_options(attestation PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(attestation PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- )
endif()
compiler_generate_binary_output(TARGET attestation NAME "${SP_UUID_CANON}.bin" SP_BINARY)
diff --git a/deployments/component-test/arm-linux/CMakeLists.txt b/deployments/component-test/arm-linux/CMakeLists.txt
index b30b160..f104dd6 100644
--- a/deployments/component-test/arm-linux/CMakeLists.txt
+++ b/deployments/component-test/arm-linux/CMakeLists.txt
@@ -50,5 +50,4 @@
# Define library options and dependencies.
#
#-------------------------------------------------------------------------------
-env_set_link_options(TGT component-test)
target_link_libraries(component-test PRIVATE stdc++ gcc m)
diff --git a/deployments/crypto/opteesp/CMakeLists.txt b/deployments/crypto/opteesp/CMakeLists.txt
index 9f6453a..6909fd5 100644
--- a/deployments/crypto/opteesp/CMakeLists.txt
+++ b/deployments/crypto/opteesp/CMakeLists.txt
@@ -8,6 +8,13 @@
# Set default platform.
set(TS_PLATFORM "arm/fvp/fvp_base_revc-2xaemv8a" CACHE STRING "Target platform location.")
+
+# Te crypto SP is big. Set default build type to MinSizWithDebInfo to avoid running ouf of
+# secure memory on low resource IoT platforms.
+if (NOT DEFINED CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE "MinSizWithDebInfo" CACHE STRING "Build type.")
+endif()
+
include(../../deployment.cmake REQUIRED)
#-------------------------------------------------------------------------------
@@ -59,23 +66,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(crypto PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
- -Os
-std=c99
)
- # Options for GCC that control linking
- target_link_options(crypto PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(crypto PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list
- )
endif()
compiler_generate_stripped_elf(TARGET crypto NAME "${SP_UUID_CANON}.stripped.elf" RES STRIPPED_ELF)
diff --git a/deployments/crypto/sp/CMakeLists.txt b/deployments/crypto/sp/CMakeLists.txt
index c4f85df..943b9a6 100644
--- a/deployments/crypto/sp/CMakeLists.txt
+++ b/deployments/crypto/sp/CMakeLists.txt
@@ -8,6 +8,13 @@
# Set default platform.
set(TS_PLATFORM "arm/fvp/fvp_base_revc-2xaemv8a" CACHE STRING "Target platform location.")
+
+# Te crypto SP is big. Set default build type to MinSizWithDebInfo to avoid running ouf of
+# secure memory on low resource IoT platforms.
+if (NOT DEFINED CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE "MinSizWithDebInfo" CACHE STRING "Build type.")
+endif()
+
include(../../deployment.cmake REQUIRED)
#-------------------------------------------------------------------------------
@@ -55,21 +62,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(crypto PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
-std=c99
)
- # Options for GCC that control linking
- target_link_options(crypto PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(crypto PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- )
endif()
compiler_generate_binary_output(TARGET crypto NAME "${SP_UUID_CANON}.bin" SP_BINARY)
diff --git a/deployments/deployment.cmake b/deployments/deployment.cmake
index e1aaed0..3e13a54 100644
--- a/deployments/deployment.cmake
+++ b/deployments/deployment.cmake
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -55,4 +55,22 @@
define_property(TARGET PROPERTY TS_PLATFORM_DRIVER_DEPENDENCIES
BRIEF_DOCS "List of platform driver interfaces used for a deployment."
FULL_DOCS "Used by the platform specific builder to specify a configuration for the built platform components."
- )
\ No newline at end of file
+ )
+
+# Set default build type to Debug
+if (NOT CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type.")
+endif()
+
+# List of supported build types. Needs to be in alignment with the toolchain file
+set(TS_SUPPORTED_BUILD_TYPES DEBUG "MINSIZEREL" "MINSIZWITHDEBINFO" "RELEASE" "RELWITHDEBINFO" CACHE
+ STRING "List of supported build types.")
+
+# Convert the build type string to upper case to help case insensitive comparison.
+string(TOUPPER "${CMAKE_BUILD_TYPE}" UC_CMAKE_BUILD_TYPE CACHE STRING "Easy to compare build type.")
+mark_as_advanced(UC_CMAKE_BUILD_TYPE)
+
+# Validate build type
+if (NOT "${UC_CMAKE_BUILD_TYPE}" IN_LIST TS_SUPPORTED_BUILD_TYPES)
+ message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\" specified in CMAKE_BUILD_TYPE.")
+endif()
diff --git a/deployments/env-test/opteesp/CMakeLists.txt b/deployments/env-test/opteesp/CMakeLists.txt
index 430993e..4b3a246 100644
--- a/deployments/env-test/opteesp/CMakeLists.txt
+++ b/deployments/env-test/opteesp/CMakeLists.txt
@@ -72,23 +72,7 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(env-test PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
- -O0
- $<$<COMPILE_LANGUAGE:C>:-std=c99>
- $<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>
- )
-
- # Options for GCC that control linking
- target_link_options(env-test PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(env-test PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list
+ -std=c99
)
endif()
diff --git a/deployments/env-test/sp/CMakeLists.txt b/deployments/env-test/sp/CMakeLists.txt
index 52de2db..99aa8f8 100644
--- a/deployments/env-test/sp/CMakeLists.txt
+++ b/deployments/env-test/sp/CMakeLists.txt
@@ -63,22 +63,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(env-test PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
- $<$<COMPILE_LANGUAGE:C>:-std=c99>
- $<$<COMPILE_LANGUAGE:CXX>:-fno-use-cxa-atexit>
+ -std=c99
)
- # Options for GCC that control linking
- target_link_options(env-test PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(env-test PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- )
endif()
compiler_generate_binary_output(TARGET env-test NAME "${SP_UUID_CANON}.bin" SP_BINARY)
diff --git a/deployments/internal-trusted-storage/opteesp/CMakeLists.txt b/deployments/internal-trusted-storage/opteesp/CMakeLists.txt
index ba3c654..5f4b911 100644
--- a/deployments/internal-trusted-storage/opteesp/CMakeLists.txt
+++ b/deployments/internal-trusted-storage/opteesp/CMakeLists.txt
@@ -44,23 +44,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(internal-trusted-storage PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
- -O0
-std=c99
)
- # Options for GCC that control linking
- target_link_options(internal-trusted-storage PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(internal-trusted-storage PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list
- )
endif()
compiler_generate_stripped_elf(TARGET internal-trusted-storage NAME "${SP_UUID_CANON}.stripped.elf" RES STRIPPED_ELF)
diff --git a/deployments/internal-trusted-storage/sp/CMakeLists.txt b/deployments/internal-trusted-storage/sp/CMakeLists.txt
index d3f65c0..90a84dd 100644
--- a/deployments/internal-trusted-storage/sp/CMakeLists.txt
+++ b/deployments/internal-trusted-storage/sp/CMakeLists.txt
@@ -40,21 +40,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(internal-trusted-storage PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
-std=c99
)
- # Options for GCC that control linking
- target_link_options(internal-trusted-storage PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(internal-trusted-storage PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- )
endif()
compiler_generate_binary_output(TARGET internal-trusted-storage NAME "${SP_UUID_CANON}.bin" SP_BINARY)
diff --git a/deployments/libsp/opteesp/CMakeLists.txt b/deployments/libsp/opteesp/CMakeLists.txt
index 8495679..fb47a60 100644
--- a/deployments/libsp/opteesp/CMakeLists.txt
+++ b/deployments/libsp/opteesp/CMakeLists.txt
@@ -63,10 +63,6 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(sp PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
- -O0
-std=c99
)
endif()
diff --git a/deployments/libts/arm-linux/CMakeLists.txt b/deployments/libts/arm-linux/CMakeLists.txt
index cc589ba..75ce321 100644
--- a/deployments/libts/arm-linux/CMakeLists.txt
+++ b/deployments/libts/arm-linux/CMakeLists.txt
@@ -51,5 +51,4 @@
# Define library options and dependencies.
#
#-------------------------------------------------------------------------------
-env_set_link_options(TGT ts)
target_link_libraries(ts PRIVATE gcc)
diff --git a/deployments/platform-inspect/arm-linux/CMakeLists.txt b/deployments/platform-inspect/arm-linux/CMakeLists.txt
index b7f254a..0f41586 100644
--- a/deployments/platform-inspect/arm-linux/CMakeLists.txt
+++ b/deployments/platform-inspect/arm-linux/CMakeLists.txt
@@ -33,7 +33,6 @@
# Define library options and dependencies.
#
#-------------------------------------------------------------------------------
-env_set_link_options(TGT platform-inspect)
target_link_libraries(platform-inspect PRIVATE stdc++ gcc m)
#-------------------------------------------------------------------------------
diff --git a/deployments/protected-storage/opteesp/CMakeLists.txt b/deployments/protected-storage/opteesp/CMakeLists.txt
index a7034c0..44b7a2b 100644
--- a/deployments/protected-storage/opteesp/CMakeLists.txt
+++ b/deployments/protected-storage/opteesp/CMakeLists.txt
@@ -44,23 +44,8 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(protected-storage PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
- -O0
-std=c99
)
-
- # Options for GCC that control linking
- target_link_options(protected-storage PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(protected-storage PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list
- )
endif()
compiler_generate_stripped_elf(TARGET protected-storage NAME "${SP_UUID_CANON}.stripped.elf" RES STRIPPED_ELF)
diff --git a/deployments/protected-storage/sp/CMakeLists.txt b/deployments/protected-storage/sp/CMakeLists.txt
index a22b1a7..05d2a00 100644
--- a/deployments/protected-storage/sp/CMakeLists.txt
+++ b/deployments/protected-storage/sp/CMakeLists.txt
@@ -40,21 +40,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(protected-storage PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
-std=c99
)
- # Options for GCC that control linking
- target_link_options(protected-storage PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(protected-storage PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- )
endif()
compiler_generate_binary_output(TARGET protected-storage NAME "${SP_UUID_CANON}.bin" SP_BINARY)
diff --git a/deployments/se-proxy/opteesp/CMakeLists.txt b/deployments/se-proxy/opteesp/CMakeLists.txt
index 1c6753a..fadbf72 100644
--- a/deployments/se-proxy/opteesp/CMakeLists.txt
+++ b/deployments/se-proxy/opteesp/CMakeLists.txt
@@ -59,23 +59,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(se-proxy PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
- -O0
-std=c99
)
- # Options for GCC that control linking
- target_link_options(se-proxy PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(se-proxy PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list
- )
endif()
compiler_generate_stripped_elf(TARGET se-proxy NAME "${SP_UUID_CANON}.stripped.elf" RES STRIPPED_ELF)
diff --git a/deployments/se-proxy/sp/CMakeLists.txt b/deployments/se-proxy/sp/CMakeLists.txt
index 314446e..ea95008 100644
--- a/deployments/se-proxy/sp/CMakeLists.txt
+++ b/deployments/se-proxy/sp/CMakeLists.txt
@@ -55,21 +55,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(se-proxy PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
-std=c99
)
- # Options for GCC that control linking
- target_link_options(se-proxy PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(se-proxy PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- )
endif()
compiler_generate_binary_output(TARGET se-proxy NAME "${SP_UUID_CANON}.bin" SP_BINARY)
diff --git a/deployments/sfs-demo/opteesp/CMakeLists.txt b/deployments/sfs-demo/opteesp/CMakeLists.txt
index ac07e60..1dbc279 100644
--- a/deployments/sfs-demo/opteesp/CMakeLists.txt
+++ b/deployments/sfs-demo/opteesp/CMakeLists.txt
@@ -43,23 +43,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(sfs-demo PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
- -O0
-std=c99
)
- # Options for GCC that control linking
- target_link_options(sfs-demo PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(sfs-demo PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list
- )
endif()
compiler_generate_stripped_elf(TARGET sfs-demo NAME "${SP_UUID_CANON}.stripped.elf" RES STRIPPED_ELF)
diff --git a/deployments/sfs-demo/sp/CMakeLists.txt b/deployments/sfs-demo/sp/CMakeLists.txt
index 5c0d098..6e24288 100644
--- a/deployments/sfs-demo/sp/CMakeLists.txt
+++ b/deployments/sfs-demo/sp/CMakeLists.txt
@@ -40,21 +40,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(sfs-demo PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
-std=c99
)
- # Options for GCC that control linking
- target_link_options(sfs-demo PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(sfs-demo PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- )
endif()
compiler_generate_binary_output(TARGET sfs-demo NAME "${SP_UUID_CANON}.bin" SP_BINARY)
diff --git a/deployments/smm-gateway/opteesp/CMakeLists.txt b/deployments/smm-gateway/opteesp/CMakeLists.txt
index 8a277cd..ac7369f 100644
--- a/deployments/smm-gateway/opteesp/CMakeLists.txt
+++ b/deployments/smm-gateway/opteesp/CMakeLists.txt
@@ -63,23 +63,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(smm-gateway PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
- -O0
-std=c99
)
- # Options for GCC that control linking
- target_link_options(smm-gateway PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(smm-gateway PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- # -Wl,--dynamic-list ${CMAKE_CURRENT_LIST_DIR}/dyn_list
- )
endif()
compiler_generate_stripped_elf(TARGET smm-gateway NAME "${SP_UUID_CANON}.stripped.elf" RES STRIPPED_ELF)
diff --git a/deployments/smm-gateway/sp/CMakeLists.txt b/deployments/smm-gateway/sp/CMakeLists.txt
index ea63444..38db310 100644
--- a/deployments/smm-gateway/sp/CMakeLists.txt
+++ b/deployments/smm-gateway/sp/CMakeLists.txt
@@ -59,21 +59,9 @@
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(smm-gateway PRIVATE
- -fdiagnostics-show-option
- -gdwarf-2
- -mstrict-align
-std=c99
)
- # Options for GCC that control linking
- target_link_options(smm-gateway PRIVATE
- -zmax-page-size=4096
- )
- # Options directly for LD, these are not understood by GCC
- target_link_options(smm-gateway PRIVATE
- -Wl,--as-needed
- -Wl,--sort-section=alignment
- )
endif()
compiler_generate_binary_output(TARGET smm-gateway NAME "${SP_UUID_CANON}.bin" SP_BINARY)
diff --git a/deployments/ts-demo/arm-linux/CMakeLists.txt b/deployments/ts-demo/arm-linux/CMakeLists.txt
index 0e20148..db59599 100644
--- a/deployments/ts-demo/arm-linux/CMakeLists.txt
+++ b/deployments/ts-demo/arm-linux/CMakeLists.txt
@@ -29,5 +29,4 @@
# Define library options and dependencies.
#
#-------------------------------------------------------------------------------
-env_set_link_options(TGT ts-demo)
target_link_libraries(ts-demo PRIVATE stdc++ gcc m)
diff --git a/deployments/ts-remote-test/arm-linux/CMakeLists.txt b/deployments/ts-remote-test/arm-linux/CMakeLists.txt
index 831246e..a44cb4c 100644
--- a/deployments/ts-remote-test/arm-linux/CMakeLists.txt
+++ b/deployments/ts-remote-test/arm-linux/CMakeLists.txt
@@ -27,5 +27,4 @@
# Define library options and dependencies.
#
#-------------------------------------------------------------------------------
-env_set_link_options(TGT ts-remote-test)
target_link_libraries(ts-remote-test PRIVATE stdc++ gcc m)
diff --git a/deployments/ts-service-test/arm-linux/CMakeLists.txt b/deployments/ts-service-test/arm-linux/CMakeLists.txt
index 67388ce..6eef67d 100644
--- a/deployments/ts-service-test/arm-linux/CMakeLists.txt
+++ b/deployments/ts-service-test/arm-linux/CMakeLists.txt
@@ -39,5 +39,4 @@
# Define library options and dependencies.
#
#-------------------------------------------------------------------------------
-env_set_link_options(TGT ts-service-test)
target_link_libraries(ts-service-test PRIVATE stdc++ gcc m)
diff --git a/deployments/uefi-test/arm-linux/CMakeLists.txt b/deployments/uefi-test/arm-linux/CMakeLists.txt
index e94a61a..c555b3a 100644
--- a/deployments/uefi-test/arm-linux/CMakeLists.txt
+++ b/deployments/uefi-test/arm-linux/CMakeLists.txt
@@ -39,5 +39,4 @@
# Define library options and dependencies.
#
#-------------------------------------------------------------------------------
-env_set_link_options(TGT uefi-test)
target_link_libraries(uefi-test PRIVATE stdc++ gcc m)
diff --git a/docs/developer/build-instructions.rst b/docs/developer/build-instructions.rst
index 5fe6c63..d5f23bc 100644
--- a/docs/developer/build-instructions.rst
+++ b/docs/developer/build-instructions.rst
@@ -25,6 +25,39 @@
.. uml:: uml/BuildFlow.puml
+Selecting the build type
+-------------------------
+The build type selects code optimization and debug information related compiler settings. The build system follows the
+standard CMake methodology and uses the `CMAKE_BUILD_TYPE`_ variable.
+
+The build system uses the following build types:
+
+.. list-table:: Supported build types
+ :header-rows: 1
+
+ * - Build type
+ - Purpose
+ - Description
+ * - Debug
+ - For debugging purposes.
+ - Optimization is off, debugging information generation is enabled.
+ * - MinSizeRel
+ - Size optimized release build.
+ - Optimization is configured to prefer small code size, debugging information is not generated.
+ * - MinSizWithDebInfo
+ - For debugging size optimized release build.
+ - Optimization is configured to prefer small code size, debugging information generation is enabled.
+ * - Release
+ - Speed optimized release build.
+ - Optimization is configured to prefer execution speed, debugging information is not generated.
+ * - RelWithDebugInfo
+ - For debugging speed optimized release build.
+ - Optimization is configured to prefer execution speed, debugging information generation is enabled.
+
+Build type of external components can be configured with command line parameters. Parameter names follow this pattern:
+``-D<upper case component name>_BUILD_TYPE=<value>`` e.g. ``-DNANOPB_BUILD_TYPE=Release``. Supported values are
+component specific, please refer to the appropriate cmake file under ``<TS_ROOT>/external/<name>``.
+
Building and Installing
-----------------------
When building from a clean environment where no generated build files exist, it is necessary to run
@@ -135,6 +168,8 @@
--------------
-*Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.*
+.. _CMAKE_BUILD_TYPE: https://cmake.org/cmake/help/v3.18/variable/CMAKE_BUILD_TYPE.html
+
+*Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.*
SPDX-License-Identifier: BSD-3-Clause
diff --git a/environments/arm-linux/default_toolchain_file.cmake b/environments/arm-linux/default_toolchain_file.cmake
index 85de9df..e77d355 100644
--- a/environments/arm-linux/default_toolchain_file.cmake
+++ b/environments/arm-linux/default_toolchain_file.cmake
@@ -4,6 +4,11 @@
# SPDX-License-Identifier: BSD-3-Clause
#
#-------------------------------------------------------------------------------
+
+# Since we append to default compilation flags stop multiple inclusion to avoid
+# flags being added multiple times.
+include_guard(GLOBAL)
+
if(NOT CROSS_COMPILE AND NOT DEFINED ENV{CROSS_COMPILE})
set(CROSS_COMPILE "aarch64-linux-gnu-;aarch64-none-linux-gnu-" CACHE STRING "List of GCC prefix triplets to use.")
endif()
@@ -12,15 +17,40 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
-string(APPEND CMAKE_C_FLAGS_INIT " -fdiagnostics-show-option -gdwarf-2 -mstrict-align -O0 -DARM64=1")
-string(APPEND CMAKE_CXX_FLAGS_INIT " -fdiagnostics-show-option -gdwarf-2 -mstrict-align -O0 -DARM64=1")
+set(TS_DEBUG_INFO_FLAGS "-fdiagnostics-show-option -gdwarf-2" CACHE STRING "Compiler flags to add debug information.")
+set(TS_MANDATORY_AARCH_FLAGS "-mstrict-align -DARM64=1" CACHE STRING "Compiler flags configuring architecture specific ")
+set(TS_WARNING_FLAGS "-Wall" CACHE STRING "Compiler flags affecting generating warning messages.")
+set(TS_MANDATORY_LINKER_FLAGS "" CACHE STRING "Linker flags needed for correct builds.")
-# Set compiler warning level for the root build context. External components
-# are responsible for setting their own warning level.
-if(DEFINED TS_ROOT)
- string(APPEND CMAKE_C_FLAGS_INIT " -Wall")
- string(APPEND CMAKE_CXX_FLAGS_INIT " -Wall")
-endif()
+# Set flags affecting all build types
+foreach(_b_type IN ITEMS DEBUG MINSIZEREL MINSIZWITHDEBINFO RELEASE RELWITHDEBINFO)
+ string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_MANDATORY_AARCH_FLAGS}")
+ string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_MANDATORY_AARCH_FLAGS}")
+ string(APPEND CMAKE_EXE_LINKER_FLAGS_${_b_type}_INIT " ${TS_MANDATORY_LINKER_FLAGS}")
+ if(DEFINED TS_ROOT)
+ # Flags not to be used with external components.
+ string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_WARNING_FLAGS}")
+ string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_WARNING_FLAGS}")
+ endif()
+endforeach()
+
+# Set flags affecting all build types supporting debugging.
+foreach(_b_type IN ITEMS DEBUG RELWITHDEBINFO MINSIZWITHDEBINFO)
+ string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_DEBUG_INFO_FLAGS}")
+ string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_DEBUG_INFO_FLAGS}")
+endforeach()
+
+# Build type specific flags
+string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -O0")
+string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -Os")
+string(APPEND CMAKE_C_FLAGS_MINSIZWITHDEBINFO_INIT " -Os")
+string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -O2")
+string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -O2")
+string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " -O0")
+string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -Os")
+string(APPEND CMAKE_CXX_FLAGS_MINSIZWITHDEBINFO_INIT " -Os")
+string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -O2")
+string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT " -O2")
include($ENV{TS_ROOT}/tools/cmake/compiler/GCC.cmake REQUIRED)
include($ENV{TS_ROOT}/tools/cmake/compiler/config_iface.cmake REQUIRED)
diff --git a/environments/linux-pc/default_toolchain_file.cmake b/environments/linux-pc/default_toolchain_file.cmake
index 1fa32cc..3f15eb3 100644
--- a/environments/linux-pc/default_toolchain_file.cmake
+++ b/environments/linux-pc/default_toolchain_file.cmake
@@ -5,11 +5,43 @@
#
#-------------------------------------------------------------------------------
-include($ENV{TS_ROOT}/tools/cmake/compiler/config_iface.cmake REQUIRED)
+# Since we append to default compilation flags stop multiple inclusion to avoid
+# flags being added multiple times.
+include_guard(GLOBAL)
-# Set compiler warning level for the root build context. External components
-# are responsible for setting their own warning level.
-if(DEFINED TS_ROOT)
- string(APPEND CMAKE_C_FLAGS_INIT " -Wall")
- string(APPEND CMAKE_CXX_FLAGS_INIT " -Wall")
-endif()
+set(TS_DEBUG_INFO_FLAGS "-fdiagnostics-show-option -gdwarf-2" CACHE STRING "Compiler flags to add debug information.")
+set(TS_MANDATORY_AARCH_FLAGS "" CACHE STRING "Compiler flags configuring architecture specific ")
+set(TS_WARNING_FLAGS "-Wall" CACHE STRING "Compiler flags affecting generating warning messages.")
+set(TS_MANDATORY_LINKER_FLAGS "" CACHE STRING "Linker flags needed for correct builds.")
+
+# Set flags affecting all build types
+foreach(_b_type IN ITEMS DEBUG MINSIZEREL MINSIZWITHDEBINFO RELEASE RELWITHDEBINFO)
+ string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_MANDATORY_AARCH_FLAGS}")
+ string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_MANDATORY_AARCH_FLAGS}")
+ string(APPEND CMAKE_EXE_LINKER_FLAGS_${_b_type}_INIT " ${TS_MANDATORY_LINKER_FLAGS}")
+ if(DEFINED TS_ROOT)
+ # Flags not to be used with external components.
+ string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_WARNING_FLAGS}")
+ string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_WARNING_FLAGS}")
+ endif()
+endforeach()
+
+# Set flags affecting all build types supporting debugging.
+foreach(_b_type IN ITEMS DEBUG RELWITHDEBINFO MINSIZWITHDEBINFO)
+ string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_DEBUG_INFO_FLAGS}")
+ string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_DEBUG_INFO_FLAGS}")
+endforeach()
+
+# Build type specific flags
+string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -O0")
+string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -Os")
+string(APPEND CMAKE_C_FLAGS_MINSIZWITHDEBINFO_INIT " -Os")
+string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -O2")
+string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -O2")
+string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " -O0")
+string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -Os")
+string(APPEND CMAKE_CXX_FLAGS_MINSIZWITHDEBINFO_INIT " -Os")
+string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -O2")
+string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT " -O2")
+
+include($ENV{TS_ROOT}/tools/cmake/compiler/config_iface.cmake REQUIRED)
diff --git a/environments/opteesp/default_toolchain_file.cmake b/environments/opteesp/default_toolchain_file.cmake
index 3c4b9a6..ec5b4d7 100644
--- a/environments/opteesp/default_toolchain_file.cmake
+++ b/environments/opteesp/default_toolchain_file.cmake
@@ -5,6 +5,10 @@
#
#-------------------------------------------------------------------------------
+# Since we append to default compilation flags stop multiple inclusion to avoid
+# flags being added multiple times.
+include_guard(GLOBAL)
+
#GNUARM v8 and v9 compilers use a different triplet.
if(NOT CROSS_COMPILE AND NOT DEFINED ENV{CROSS_COMPILE})
set(CROSS_COMPILE "aarch64-elf-;aarch64-none-elf-;aarch64-linux-gnu-;aarch64-none-linux-gnu-" CACHE STRING "List of GCC prefix triplets to use.")
@@ -15,18 +19,41 @@
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_POSITION_INDEPENDENT_CODE True)
+set(TS_DEBUG_INFO_FLAGS "-fdiagnostics-show-option -gdwarf-2" CACHE STRING "Compiler flags to add debug information.")
+set(TS_MANDATORY_AARCH_FLAGS "-fpic -mstrict-align" CACHE STRING "Compiler flags configuring architecture specific ")
+set(TS_WARNING_FLAGS "-Wall" CACHE STRING "Compiler flags affecting generating warning messages.")
+set(TS_MANDATORY_LINKER_FLAGS "-pie -Wl,--as-needed -Wl,--sort-section=alignment -zmax-page-size=4096"
+ CACHE STRING "Linker flags needed for correct builds.")
+
+# Set flags affecting all build types
+foreach(_b_type IN ITEMS DEBUG MINSIZEREL MINSIZWITHDEBINFO RELEASE RELWITHDEBINFO)
+ string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_MANDATORY_AARCH_FLAGS}")
+ string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_MANDATORY_AARCH_FLAGS}")
+ string(APPEND CMAKE_EXE_LINKER_FLAGS_${_b_type}_INIT " ${TS_MANDATORY_LINKER_FLAGS}")
+ if(DEFINED TS_ROOT)
+ # Flags not to be used with external components.
+ string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_WARNING_FLAGS}")
+ string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_WARNING_FLAGS}")
+ endif()
+endforeach()
+
+# Set flags affecting all build types supporting debugging.
+foreach(_b_type IN ITEMS DEBUG RELWITHDEBINFO MINSIZWITHDEBINFO)
+ string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_DEBUG_INFO_FLAGS}")
+ string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_DEBUG_INFO_FLAGS}")
+endforeach()
+
+# Build type specific flags
+string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -O0")
+string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -Os")
+string(APPEND CMAKE_C_FLAGS_MINSIZWITHDEBINFO_INIT " -Os")
+string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -O2")
+string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -O2")
+string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " -O0")
+string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -Os")
+string(APPEND CMAKE_CXX_FLAGS_MINSIZWITHDEBINFO_INIT " -Os")
+string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -O2")
+string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT " -O2")
+
include($ENV{TS_ROOT}/tools/cmake/compiler/GCC.cmake REQUIRED)
include($ENV{TS_ROOT}/tools/cmake/compiler/config_iface.cmake REQUIRED)
-
-# Set mandatory compiler and linker flags for this environment:
-# - Compile position independent code
-string(APPEND CMAKE_C_FLAGS_INIT " -fpic")
-
-# Set compiler warning level for the root build context. External components
-# are responsible for setting their own warning level.
-if(DEFINED TS_ROOT)
- string(APPEND CMAKE_C_FLAGS_INIT " -Wall")
-endif()
-
-# - Link position independent executable
-string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " -pie")
diff --git a/environments/sp/default_toolchain_file.cmake b/environments/sp/default_toolchain_file.cmake
index 5e0a888..e43a00e 100644
--- a/environments/sp/default_toolchain_file.cmake
+++ b/environments/sp/default_toolchain_file.cmake
@@ -5,6 +5,10 @@
#
#-------------------------------------------------------------------------------
+# Since we append to default compilation flags stop multiple inclusion to avoid
+# flags being added multiple times.
+include_guard(GLOBAL)
+
#GNUARM v8 and v9 compilers use a different triplet.
if(NOT CROSS_COMPILE AND NOT DEFINED ENV{CROSS_COMPILE})
set(CROSS_COMPILE "aarch64-elf-;aarch64-none-elf-;aarch64-linux-gnu-;aarch64-none-linux-gnu-" CACHE STRING "List of GCC prefix triplets to use.")
@@ -15,16 +19,40 @@
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_POSITION_INDEPENDENT_CODE True)
+set(TS_DEBUG_INFO_FLAGS "-fdiagnostics-show-option -gdwarf-2" CACHE STRING "Compiler flags to add debug information.")
+set(TS_MANDATORY_AARCH_FLAGS "-fpie -mstrict-align" CACHE STRING "Compiler flags configuring architecture specific ")
+set(TS_WARNING_FLAGS "-Wall" CACHE STRING "Compiler flags affecting generating warning messages.")
+set(TS_MANDATORY_LINKER_FLAGS "-Wl,-pie -Wl,--no-dynamic-linker -Wl,--sort-section=alignment -zmax-page-size=4096" CACHE STRING "Linker flags needed for correct builds.")
+
+# Set flags affecting all build types
+foreach(_b_type IN ITEMS DEBUG MINSIZEREL MINSIZWITHDEBINFO RELEASE RELWITHDEBINFO)
+ string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_MANDATORY_AARCH_FLAGS}")
+ string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_MANDATORY_AARCH_FLAGS}")
+ string(APPEND CMAKE_EXE_LINKER_FLAGS_${_b_type}_INIT " ${TS_MANDATORY_LINKER_FLAGS}")
+ if(DEFINED TS_ROOT)
+ # Flags not to be used with external components.
+ string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_WARNING_FLAGS}")
+ string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_WARNING_FLAGS}")
+ endif()
+endforeach()
+
+# Set flags affecting all build types supporting debugging.
+foreach(_b_type IN ITEMS DEBUG RELWITHDEBINFO MINSIZWITHDEBINFO)
+ string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_DEBUG_INFO_FLAGS}")
+ string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_DEBUG_INFO_FLAGS}")
+endforeach()
+
+# Build type specific flags
+string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -O0")
+string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -Os")
+string(APPEND CMAKE_C_FLAGS_MINSIZWITHDEBINFO_INIT " -Os")
+string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -O2")
+string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -O2")
+string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " -O0")
+string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -Os")
+string(APPEND CMAKE_CXX_FLAGS_MINSIZWITHDEBINFO_INIT " -Os")
+string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -O2")
+string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT " -O2")
+
include($ENV{TS_ROOT}/tools/cmake/compiler/GCC.cmake REQUIRED)
include($ENV{TS_ROOT}/tools/cmake/compiler/config_iface.cmake REQUIRED)
-# Set mandatory compiler and linker flags for this environment:
-# - Compile position independent code
-string(APPEND CMAKE_C_FLAGS_INIT " -fpie")
-# - Disable startup files and default libraries.
-# - Link position independent executable
-string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " -Wl,-pie -Wl,--no-dynamic-linker")
-
-# -link libgcc with full PATH to work around disabled linker search paths.
-gcc_get_lib_location("libgcc.a" _TMP_VAR)
-string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${_TMP_VAR} ")
-unset(_TMP_VAR)
diff --git a/external/CppUTest/CppUTest.cmake b/external/CppUTest/CppUTest.cmake
index 8fd8ab1..7b916d5 100644
--- a/external/CppUTest/CppUTest.cmake
+++ b/external/CppUTest/CppUTest.cmake
@@ -10,6 +10,7 @@
set(CPPUTEST_REFSPEC "v3.8" CACHE STRING "CppUTest git refspec")
set(CPPUTEST_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/CppUTest_install CACHE PATH "CppUTest installation directory")
set(CPPUTEST_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/_deps/cpputest-src CACHE PATH "CppUTest source directory")
+set(CPPUTEST_BUILD_TYPE "Release" CACHE STRING "CppUTest build type")
set(GIT_OPTIONS
GIT_REPOSITORY ${CPPUTEST_URL}
diff --git a/external/MbedTLS/MbedTLS.cmake b/external/MbedTLS/MbedTLS.cmake
index 78efdb7..88aa68b 100644
--- a/external/MbedTLS/MbedTLS.cmake
+++ b/external/MbedTLS/MbedTLS.cmake
@@ -13,6 +13,7 @@
CACHE PATH "MbedTLS source directory")
set(MBEDTLS_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/mbedtls_install"
CACHE PATH "Mbed TLS installation directory")
+set(MBEDTLS_BUILD_TYPE "Release" CACHE STRING "Mbed TLS build type")
find_library(MBEDCRYPTO_LIB_FILE
NAMES libmbedcrypto.a mbedcrypto.a libmbedcrypto.lib mbedcrypto.lib
@@ -120,6 +121,7 @@
execute_process(COMMAND
${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}"
${CMAKE_COMMAND}
+ -DCMAKE_BUILD_TYPE=${MBEDTLS_BUILD_TYPE}
-DENABLE_PROGRAMS=OFF
-DENABLE_TESTING=OFF
-DUNSAFE_BUILD=ON
diff --git a/external/nanopb/nanopb.cmake b/external/nanopb/nanopb.cmake
index 60620b9..92c6e5b 100644
--- a/external/nanopb/nanopb.cmake
+++ b/external/nanopb/nanopb.cmake
@@ -34,6 +34,8 @@
CACHE PATH "nanopb source-code")
set(NANOPB_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/nanopb_install"
CACHE PATH "nanopb installation directory")
+set(NANOPB_BUILD_TYPE "Release"
+ CACHE STRING "nanopb build type")
# Checking git
find_program(GIT_COMMAND "git")
diff --git a/external/newlib/newlib.cmake b/external/newlib/newlib.cmake
index b1884be..3a0eb23 100644
--- a/external/newlib/newlib.cmake
+++ b/external/newlib/newlib.cmake
@@ -33,6 +33,10 @@
CACHE PATH "newlib source-code location")
set(NEWLIB_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/newlib_install"
CACHE PATH "newlib installation directory")
+# Supported build types: "Release" "Debug" "RelWithDebInfo" "Off"
+# If set to "Off" -DNEWLIB_CFLAGS_TARGET can be used to set compiler
+# switches from the command line.
+set(NEWLIB_BUILD_TYPE "Release" CACHE STRING "newlib build type")
# Extracting compiler prefix without the trailing hyphen from the C compiler name
get_filename_component(COMPILER_PATH ${CMAKE_C_COMPILER} DIRECTORY)
@@ -147,6 +151,17 @@
string(REPLACE ";" " -I" _more_cflags_target "${LIBGCC_INCLUDE_DIRS}" )
set(_more_cflags_target "-fpic -I${_more_cflags_target}")
+ string(TOUPPER ${NEWLIB_BUILD_TYPE} UC_NEWLIB_BUILD_TYPE)
+ if ("${UC_NEWLIB_BUILD_TYPE}" STREQUAL "DEBUG")
+ set(_more_cflags_target "${_more_cflags_target} -g -O0")
+ elseif ("${UC_NEWLIB_BUILD_TYPE}" STREQUAL "RELEASE")
+ set(_more_cflags_target "${_more_cflags_target} -O2")
+ elseif ("${UC_NEWLIB_BUILD_TYPE}" STREQUAL "RELWITHDEBINFO")
+ set(_more_cflags_target "${_more_cflags_target} -g -O2")
+ elseif (NOT "${UC_NEWLIB_BUILD_TYPE}" STREQUAL "OFF")
+ message(FATAL_ERROR "unsupported build type to newlib.")
+ endif()
+
# Get external extra flags for target from environment.
set(NEWLIB_CFLAGS_TARGET $ENV{NEWLIB_CFLAGS_TARGET} CACHE STRING "")
diff --git a/external/psa_arch_tests/psa_arch_tests.cmake b/external/psa_arch_tests/psa_arch_tests.cmake
index 0c1992a..d0a46ac 100644
--- a/external/psa_arch_tests/psa_arch_tests.cmake
+++ b/external/psa_arch_tests/psa_arch_tests.cmake
@@ -8,6 +8,7 @@
set(PSA_ARCH_TESTS_URL "https://github.com/ARM-software/psa-arch-tests.git" CACHE STRING "psa-arch-tests repository URL")
set(PSA_ARCH_TESTS_REFSPEC "451aa087a40d02c7d04778235014c5619d126471" CACHE STRING "A tested SHA from main having the AEAD fixes.")
set(PSA_ARCH_TESTS_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/psa_arch_tests-src" CACHE PATH "psa-arch-tests source.")
+set(PSA_ARCH_TESTS_BUILD_TYPE "Release" CACHE STRING "psa-arch-tests build type.")
set(GIT_OPTIONS
GIT_REPOSITORY ${PSA_ARCH_TESTS_URL}
diff --git a/external/qcbor/qcbor.cmake b/external/qcbor/qcbor.cmake
index f2d940a..47ddb6c 100644
--- a/external/qcbor/qcbor.cmake
+++ b/external/qcbor/qcbor.cmake
@@ -10,6 +10,7 @@
set(QCBOR_REFSPEC "v1.0" CACHE STRING "qcbor git refspec")
set(QCBOR_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/qcbor-src" CACHE PATH "qcbor installation directory")
set(QCBOR_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/qcbor_install" CACHE PATH "qcbor installation directory")
+set(QCBOR_BUILD_TYPE "Release" CACHE STRING "qcbor build type")
set(GIT_OPTIONS
GIT_REPOSITORY ${QCBOR_URL}
diff --git a/external/t_cose/t_cose.cmake b/external/t_cose/t_cose.cmake
index 8a186a0..cf4f7f4 100644
--- a/external/t_cose/t_cose.cmake
+++ b/external/t_cose/t_cose.cmake
@@ -10,6 +10,7 @@
set(T_COSE_REFSPEC "fc3a4b2c7196ff582e8242de8bd4a1bc4eec577f" CACHE STRING "t_cose git refspec")
set(T_COSE_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/t_cose-src" CACHE PATH "t_cose installation directory")
set(T_COSE_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/t_cose_install" CACHE PATH "t_cose installation directory")
+set(T_COSE_BUILD_TYPE "Release" CACHE STRING "t_cose build type")
set(GIT_OPTIONS
GIT_REPOSITORY ${T_COSE_URL}
diff --git a/tools/cmake/common/LazyFetch.cmake b/tools/cmake/common/LazyFetch.cmake
index 54200c2..a820919 100644
--- a/tools/cmake/common/LazyFetch.cmake
+++ b/tools/cmake/common/LazyFetch.cmake
@@ -79,10 +79,19 @@
set(CONFIGURED_CACHE_FILE ${CMAKE_BINARY_DIR}/${BUILD_DEP_NAME}-init-cache.cmake)
configure_file(${BUILD_CACHE_FILE} ${CONFIGURED_CACHE_FILE} @ONLY)
+ string(TOUPPER ${BUILD_DEP_NAME} UC_DEP_NAME)
+
+ if (NOT DEFINED ${UC_DEP_NAME}_BUILD_TYPE)
+ message(FATAL_ERROR "Build type for external component ${DEP_NAME} is not set. Please pass "
+ "-D${UC_DEP_NAME}_BUILD_TYPE=<build type> to cmake. Supported build types are"
+ "component specific. Pleas refer to the upstream documentation for more information.")
+ endif()
+
execute_process(COMMAND
${CMAKE_COMMAND} -E env "CROSS_COMPILE=${CROSS_COMPILE}"
${CMAKE_COMMAND}
"-C${CONFIGURED_CACHE_FILE}"
+ -DCMAKE_BUILD_TYPE=${UC_DEP_NAME}_BUILD_TYPE
-S ${BUILD_SRC_DIR}
-B ${BUILD_BIN_DIR}
RESULT_VARIABLE