blob: 308c2a7bfce58c429bb84b23cdff56b24f0d7f8f [file] [log] [blame]
Julian Hall07679f22020-11-23 17:45:16 +01001#-------------------------------------------------------------------------------
Gyorgy Szing748838e2022-03-05 04:17:34 +00002# Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.
Julian Hall07679f22020-11-23 17:45:16 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
Gyorgy Szing34aaf212022-10-20 07:26:23 +02007
8# Since we append to default compilation flags stop multiple inclusion to avoid
9# flags being added multiple times.
10include_guard(GLOBAL)
11
Gyorgy Szingd80f8562021-02-11 19:31:43 +010012if(NOT CROSS_COMPILE AND NOT DEFINED ENV{CROSS_COMPILE})
Gyorgy Szing748838e2022-03-05 04:17:34 +000013 set(CROSS_COMPILE "aarch64-linux-gnu-;aarch64-none-linux-gnu-" CACHE STRING "List of GCC prefix triplets to use.")
Gyorgy Szingd80f8562021-02-11 19:31:43 +010014endif()
Julian Hall07679f22020-11-23 17:45:16 +010015
16set(CMAKE_CROSSCOMPILING True)
17set(CMAKE_SYSTEM_NAME Linux)
18set(CMAKE_SYSTEM_PROCESSOR arm)
19
Gyorgy Szing34aaf212022-10-20 07:26:23 +020020set(TS_DEBUG_INFO_FLAGS "-fdiagnostics-show-option -gdwarf-2" CACHE STRING "Compiler flags to add debug information.")
Balint Dobszay550ce872022-12-15 15:28:40 +010021set(TS_MANDATORY_AARCH_FLAGS "-mstrict-align -march=armv8-a+crc -DARM64=1" CACHE STRING "Compiler flags configuring architecture specific ")
Gabor Toth983264f2024-01-23 09:16:24 +010022set(TS_WARNING_FLAGS "-Wall -Werror" CACHE STRING "Compiler flags affecting generating warning messages.")
Gyorgy Szing34aaf212022-10-20 07:26:23 +020023set(TS_MANDATORY_LINKER_FLAGS "" CACHE STRING "Linker flags needed for correct builds.")
Julian Hall07679f22020-11-23 17:45:16 +010024
Gabor Tothb446a1e2024-05-10 10:42:20 +020025set(BTI_ENABLED unset CACHE STRING "Enable Branch Target Identification (BTI)")
26set_property(CACHE BTI_ENABLED PROPERTY STRINGS unset OFF ON)
27
28if(BTI_ENABLED STREQUAL "ON")
29 # branch-protection enables bti while compile force-bti tells the linker to
30 # warn if some object files lack the .note.gnu.property section with the BTI
31 # flag, and to turn on the BTI flag in the output anyway.
32 set(TS_MANDATORY_AARCH_FLAGS "${TS_MANDATORY_AARCH_FLAGS} -mbranch-protection=bti")
33 set(TS_MANDATORY_LINKER_FLAGS "${TS_MANDATORY_LINKER_FLAGS} -zforce-bti")
34elseif(BTI_ENABLED STREQUAL "OFF")
35 set(TS_MANDATORY_AARCH_FLAGS "${TS_MANDATORY_AARCH_FLAGS} -mbranch-protection=none")
36endif()
37
Gyorgy Szing34aaf212022-10-20 07:26:23 +020038# Set flags affecting all build types
Gabor Toth22d04d62024-06-25 12:42:34 +020039string(APPEND CMAKE_C_FLAGS_INIT " ${TS_MANDATORY_AARCH_FLAGS}")
40string(APPEND CMAKE_CXX_FLAGS_INIT " ${TS_MANDATORY_AARCH_FLAGS}")
41string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${TS_MANDATORY_LINKER_FLAGS}")
42if(DEFINED TS_ROOT)
43 # Flags not to be used with external components.
44 string(APPEND CMAKE_C_FLAGS_INIT " ${TS_WARNING_FLAGS}")
45 string(APPEND CMAKE_CXX_FLAGS_INIT " ${TS_WARNING_FLAGS}")
46endif()
Gyorgy Szing34aaf212022-10-20 07:26:23 +020047
48# Set flags affecting all build types supporting debugging.
49foreach(_b_type IN ITEMS DEBUG RELWITHDEBINFO MINSIZWITHDEBINFO)
50 string(APPEND CMAKE_C_FLAGS_${_b_type}_INIT " ${TS_DEBUG_INFO_FLAGS}")
51 string(APPEND CMAKE_CXX_FLAGS_${_b_type}_INIT " ${TS_DEBUG_INFO_FLAGS}")
52endforeach()
53
54# Build type specific flags
55string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -O0")
56string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -Os")
57string(APPEND CMAKE_C_FLAGS_MINSIZWITHDEBINFO_INIT " -Os")
58string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -O2")
59string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -O2")
60string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " -O0")
61string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -Os")
62string(APPEND CMAKE_CXX_FLAGS_MINSIZWITHDEBINFO_INIT " -Os")
63string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -O2")
64string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT " -O2")
Julian Hall6e02acf2022-02-22 16:25:03 +000065
Julian Hall07679f22020-11-23 17:45:16 +010066include($ENV{TS_ROOT}/tools/cmake/compiler/GCC.cmake REQUIRED)
Julian Hall0051ed12021-07-22 13:59:24 +010067include($ENV{TS_ROOT}/tools/cmake/compiler/config_iface.cmake REQUIRED)