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