1# Copyright (c) 2025 IAR Systems AB 2# 3# SPDX-License-Identifier: Apache-2.0 4 5# Compiler options for the IAR C/C++ Compiler for Arm 6 7##################################################### 8# This section covers flags related to optimization # 9##################################################### 10set_compiler_property(PROPERTY no_optimization -On) 11 12set_compiler_property(PROPERTY optimization_debug -Ol) 13 14set_compiler_property(PROPERTY optimization_speed -Ohs) 15 16set_compiler_property(PROPERTY optimization_size -Ohz) 17 18set_compiler_property(PROPERTY optimization_size_aggressive -Ohz) 19 20set_compiler_property(PROPERTY optimization_fast --no_size_constraints) 21 22####################################################### 23# This section covers flags related to warning levels # 24####################################################### 25 26# Property for standard warning base in Zephyr, this will always be set when 27# compiling. 28set_compiler_property(PROPERTY warning_base 29 --diag_error=Pe223 # function "xxx" declared implicitly 30 --diag_warning=Pe054 # too few arguments in invocation of macro 31 --diag_warning=Pe144 # a value of type "void *" cannot be used to initialize an entity of type [...] "void (*)(struct onoff_manager *, int)" 32 --diag_warning=Pe167 # argument of type "void *" is incompatible with [...] "void (*)(void *, void *, void *)" 33 --diag_suppress=Pe1675 # unrecognized GCC pragma 34 --diag_suppress=Pe111 # statement is unreachable 35 --diag_suppress=Pe1143 # arithmetic on pointer to void or function type 36 --diag_suppress=Pe068) # integer conversion resulted in a change of sign) 37 38 39set(IAR_WARNING_DW_1 40 --diag_suppress=Pe188 # enumerated type mixed with another type 41 --diag_suppress=Pe128 # loop is not reachable 42 --diag_suppress=Pe550 # variable "res" was set but never used 43 --diag_suppress=Pe546 # transfer of control bypasses initialization 44 --diag_suppress=Pe186) # pointless comparison of unsigned integer with zero 45 46set(IAR_WARNING_DW2 47 --diag_suppress=Pe1097 # unknown attribute 48 --diag_suppress=Pe381 # extra ";" ignored 49 --diag_suppress=Pa082 # undefined behavior: the order of volatile accesses is undefined 50 --diag_suppress=Pa084 # pointless integer comparison, the result is always false 51 --diag_suppress=Pe185 # dynamic initialization in unreachable code ) 52 --diag_suppress=Pe167 # argument of type "onoff_notify_fn" is incompatible with... 53 --diag_suppress=Pe144 # a value of type "void *" cannot be used to initialize... 54 --diag_suppress=Pe177 # function "xxx" was declared but never referenced 55 --diag_suppress=Pe513) # a value of type "void *" cannot be assigned to an entity of type "int (*)(int)" 56 57set(IAR_WARNING_DW3) 58 59set_compiler_property(PROPERTY warning_dw_1 60 ${IAR_WARNING_DW_3} 61 ${IAR_WARNING_DW_2} 62 ${IAR_WARNING_DW_1}) 63 64set_compiler_property(PROPERTY warning_dw_2 65 ${IAR_WARNING_DW3} 66 ${IAR_WARNING_DW2}) 67 68# no suppressions 69set_compiler_property(PROPERTY warning_dw_3 ${IAR_WARNING_DW3}) 70 71# Extended warning set supported by the compiler 72set_compiler_property(PROPERTY warning_extended) 73 74# Compiler property that will issue error if a declaration does not specify a type 75set_compiler_property(PROPERTY warning_error_implicit_int) 76 77# Compiler flags to use when compiling according to MISRA 78set_compiler_property(PROPERTY warning_error_misra_sane) 79 80set_property(TARGET compiler PROPERTY warnings_as_errors --warnings_are_errors) 81 82########################################################################### 83# This section covers flags related to C or C++ standards / standard libs # 84########################################################################### 85 86# Compiler flags for C standard. The specific standard must be appended by user. 87# For example, gcc specifies this as: set_compiler_property(PROPERTY cstd -std=) 88# TC-WG: the `cstd99` is used regardless of this flag being useful for iccarm 89# This flag will make it a symbol. Works for C,CXX,ASM 90# Since ICCARM does not use C standard flags, we just make them a defined symbol 91# instead 92set_compiler_property(PROPERTY cstd -D__IAR_CSTD_) 93 94# Compiler flags for disabling C standard include and instead specify include 95# dirs in nostdinc_include to use. 96set_compiler_property(PROPERTY nostdinc) 97set_compiler_property(PROPERTY nostdinc_include) 98 99# Compiler flags for disabling C++ standard include. 100set_compiler_property(TARGET compiler-cpp PROPERTY nostdincxx) 101 102# Required C++ flags when compiling C++ code 103set_property(TARGET compiler-cpp PROPERTY required --c++) 104 105# Compiler flags to use for specific C++ dialects 106set_property(TARGET compiler-cpp PROPERTY dialect_cpp98) 107set_property(TARGET compiler-cpp PROPERTY dialect_cpp11) 108set_property(TARGET compiler-cpp PROPERTY dialect_cpp14) 109set_property(TARGET compiler-cpp PROPERTY dialect_cpp17 --libc++) 110set_property(TARGET compiler-cpp PROPERTY dialect_cpp2a --libc++) 111set_property(TARGET compiler-cpp PROPERTY dialect_cpp20 --libc++) 112set_property(TARGET compiler-cpp PROPERTY dialect_cpp2b --libc++) 113 114# Flag for disabling strict aliasing rule in C and C++ 115set_compiler_property(PROPERTY no_strict_aliasing) 116 117# Flag for disabling exceptions in C++ 118set_property(TARGET compiler-cpp PROPERTY no_exceptions --no_exceptions) 119 120# Flag for disabling rtti in C++ 121set_property(TARGET compiler-cpp PROPERTY no_rtti --no_rtti) 122 123################################################### 124# This section covers all remaining C / C++ flags # 125################################################### 126 127# Flags for coverage generation 128set_compiler_property(PROPERTY coverage) 129 130# Security canaries flags. 131set_compiler_property(PROPERTY security_canaries --stack_protection) 132set_compiler_property(PROPERTY security_canaries_strong --stack_protection) 133set_compiler_property(PROPERTY security_canaries_all --security_canaries_all_is_not_supported) 134set_compiler_property(PROPERTY security_canaries_explicit --security_canaries_explicit_is_not_supported) 135 136if(CONFIG_STACK_CANARIES_TLS) 137 check_set_compiler_property(APPEND PROPERTY security_canaries --stack_protector_guard=tls) 138 check_set_compiler_property(APPEND PROPERTY security_canaries_strong --stack_protector_guard=tls) 139 check_set_compiler_property(APPEND PROPERTY security_canaries_all --stack_protector_guard=tls) 140 check_set_compiler_property(APPEND PROPERTY security_canaries_explicit --stack_protector_guard=tls) 141endif() 142 143set_compiler_property(PROPERTY security_fortify) 144 145# Flag for a hosted (no-freestanding) application 146set_compiler_property(PROPERTY hosted) 147 148# gcc flag for a freestanding application 149set_compiler_property(PROPERTY freestanding) 150 151# Flag to include debugging symbol in compilation 152set_property(TARGET compiler PROPERTY debug --debug) 153set_property(TARGET compiler-cpp PROPERTY debug --debug) 154set_property(TARGET asm PROPERTY debug -gdwarf-4) 155 156set_compiler_property(PROPERTY no_common) 157 158# Flags for imacros. The specific header must be appended by user. 159set_property(TARGET compiler PROPERTY imacros --preinclude) 160set_property(TARGET compiler-cpp PROPERTY imacros --preinclude) 161set_property(TARGET asm PROPERTY imacros -imacros) 162 163# Compiler flag for turning off thread-safe initialization of local statics 164set_property(TARGET compiler-cpp PROPERTY no_threadsafe_statics) 165 166# Required ASM flags when compiling 167set_property(TARGET asm PROPERTY required) 168 169# Compiler flag for disabling pointer arithmetic warnings 170set_compiler_property(PROPERTY warning_no_pointer_arithmetic) 171# Compiler flag for warning about shadow variables 172set_compiler_property(PROPERTY warning_shadow_variables) 173# Compiler flag for disabling warning about array bounds 174set_compiler_property(PROPERTY warning_no_array_bounds) 175 176# Compiler flags for disabling position independent code / executable 177set_compiler_property(PROPERTY no_position_independent) 178 179# Compiler flag for defining preinclude files. 180set_compiler_property(PROPERTY include_file --preinclude) 181 182set_compiler_property(PROPERTY cmse --cmse) 183 184set_property(TARGET asm PROPERTY cmse -mcmse) 185