1# List the warnings that are not supported for C++ compilations 2list(APPEND CXX_EXCLUDED_OPTIONS 3 -Werror=implicit-int 4 -Wold-style-definition 5 ) 6 7################################################### 8# Setting compiler properties for MWDT compilers. # 9################################################### 10 11##################################################### 12# This section covers flags related to optimization # 13##################################################### 14set_compiler_property(PROPERTY no_optimization -O0) 15set_compiler_property(PROPERTY optimization_debug -O0) 16set_compiler_property(PROPERTY optimization_speed -O2) 17set_compiler_property(PROPERTY optimization_size -Os) 18set_compiler_property(PROPERTY optimization_fast -O3) 19 20####################################################### 21# This section covers flags related to warning levels # 22####################################################### 23 24# options for warnings 25# base options 26set_compiler_property(PROPERTY warning_base 27 -Wformat 28 -Wformat-security 29 -Wno-format-zero-length 30 -Wno-unaligned-pointer-conversion 31 -Wno-incompatible-pointer-types-discards-qualifiers 32 -Wno-typedef-redefinition 33) 34 35# C implicit promotion rules will want to make floats into doubles very easily 36check_set_compiler_property(APPEND PROPERTY warning_base -Wdouble-promotion) 37 38check_set_compiler_property(APPEND PROPERTY warning_base -Wno-pointer-sign) 39 40# Prohibit void pointer arithmetic. Illegal in C99 41check_set_compiler_property(APPEND PROPERTY warning_base -Wpointer-arith) 42 43# level 1 warning options 44set_compiler_property(PROPERTY warning_dw_1 45 -Wextra 46 -Wunused 47 -Wno-unused-parameter 48 -Wmissing-declarations 49 -Wmissing-format-attribute 50) 51 52check_set_compiler_property(APPEND PROPERTY warning_dw_1 53 -Wold-style-definition 54 -Wmissing-prototypes 55 -Wmissing-include-dirs 56 -Wunused-but-set-variable 57 -Wno-missing-field-initializers 58) 59 60# level 2 warning options 61set_compiler_property(PROPERTY warning_dw_2 62 -Waggregate-return 63 -Wcast-align 64 -Wdisabled-optimization 65 -Wnested-externs 66 -Wshadow 67) 68 69check_set_compiler_property(APPEND PROPERTY warning_dw_2 70 -Wlogical-op 71 -Wmissing-field-initializers 72) 73 74# level 3 warning options 75set_compiler_property(PROPERTY warning_dw_3 76 -Wbad-function-cast 77 -Wcast-qual 78 -Wconversion 79 -Wpacked 80 -Wpadded 81 -Wpointer-arith 82 -Wredundant-decls 83 -Wswitch-default 84) 85 86check_set_compiler_property(APPEND PROPERTY warning_dw_3 87 -Wpacked-bitfield-compat 88 -Wvla 89) 90 91# extended warning options 92check_set_compiler_property(PROPERTY warning_extended 93 -Wno-sometimes-uninitialized 94 -Wno-shift-overflow 95 -Wno-missing-braces 96 -Wno-self-assign 97 -Wno-address-of-packed-member 98 -Wno-unused-function 99 -Wno-initializer-overrides 100 -Wno-section 101 -Wno-unknown-warning-option 102 -Wno-unused-variable 103 -Wno-format-invalid-specifier 104 -Wno-gnu 105 # comparison of unsigned expression < 0 is always false 106 -Wno-tautological-compare 107) 108 109check_set_compiler_property(PROPERTY warning_error_implicit_int -Werror=implicit-int) 110 111set_compiler_property(PROPERTY warning_error_misra_sane -Werror=vla) 112 113########################################################################### 114# This section covers flags related to C or C++ standards / standard libs # 115########################################################################### 116 117set_compiler_property(PROPERTY cstd -std=) 118 119if (NOT CONFIG_ARCMWDT_LIBC) 120 set_compiler_property(PROPERTY nostdinc -Hno_default_include -Hnoarcexlib -U__STDC_LIB_EXT1__) 121 set_compiler_property(APPEND PROPERTY nostdinc_include ${NOSTDINC}) 122endif() 123 124# C++ std options 125set_property(TARGET compiler-cpp PROPERTY dialect_cpp98 "-std=c++98") 126set_property(TARGET compiler-cpp PROPERTY dialect_cpp11 "-std=c++11") 127set_property(TARGET compiler-cpp PROPERTY dialect_cpp14 "-std=c++14") 128set_property(TARGET compiler-cpp PROPERTY dialect_cpp17 "-std=c++17") 129 130# no support of C++2a, C++20, C++2b, C++23 131set_property(TARGET compiler-cpp PROPERTY dialect_cpp2a "") 132set_property(TARGET compiler-cpp PROPERTY dialect_cpp20 "") 133set_property(TARGET compiler-cpp PROPERTY dialect_cpp2b "") 134set_property(TARGET compiler-cpp PROPERTY dialect_cpp23 "") 135 136# Flag for disabling strict aliasing rule in C and C++ 137set_compiler_property(PROPERTY no_strict_aliasing -fno-strict-aliasing) 138 139# Flags for set extra warnigs (ARCMWDT asm can't recognize --fatal-warnings. Skip it) 140set_property(TARGET compiler PROPERTY warnings_as_errors -Werror) 141set_property(TARGET asm PROPERTY warnings_as_errors -Werror) 142 143# Disable exceptions flag in C++ 144set_property(TARGET compiler-cpp PROPERTY no_exceptions "-fno-exceptions") 145 146# Disable rtti in C++ 147set_property(TARGET compiler-cpp PROPERTY no_rtti "-fno-rtti") 148 149################################################### 150# This section covers all remaining C / C++ flags # 151################################################### 152 153# mwdt flag for a freestanding application 154# do not link in supplied run-time startup files 155set_compiler_property(PROPERTY freestanding -Hnocrt) 156 157# Flag to keep DWARF information (enable debug info) 158set_compiler_property(PROPERTY debug -g) 159 160# compile common globals like normal definitions 161set_compiler_property(PROPERTY no_common -fno-common) 162 163# mwdt's coverage mechanism is different with gnu 164# at present, zephyr only support gnu coverage 165set_compiler_property(PROPERTY coverage "") 166 167# mwdt compiler flags for imacros. The specific header must be appended by user. 168set_compiler_property(PROPERTY imacros -imacros) 169 170# assembler compiler flags for imacros. The specific header must be appended by user. 171set_property(TARGET asm PROPERTY imacros -imacros) 172 173# Security canaries. 174#no support of -mstack-protector-guard=global" 175set_compiler_property(PROPERTY security_canaries -fstack-protector) 176set_compiler_property(PROPERTY security_canaries_strong -fstack-protector-strong) 177set_compiler_property(PROPERTY security_canaries_all -fstack-protector-all) 178 179#no support of _FORTIFY_SOURCE" 180set_compiler_property(PROPERTY security_fortify_compile_time) 181set_compiler_property(PROPERTY security_fortify_run_time) 182 183# Required C++ flags when using mwdt 184set_property(TARGET compiler-cpp PROPERTY required "-Hcplus" ) 185 186if(CONFIG_ARC) 187 set_property(TARGET compiler-cpp PROPERTY required "-Hoff=Stackcheck_alloca") 188endif() 189 190# Compiler flag for turning off thread-safe initialization of local statics 191set_property(TARGET compiler-cpp PROPERTY no_threadsafe_statics "-fno-threadsafe-statics") 192 193# ARC MWDT does not support -fno-pic and -fno-pie flags, 194# but it has PIE disabled by default - so no extra flags are required here. 195set_compiler_property(PROPERTY no_position_independent "") 196 197set_compiler_property(PROPERTY no_global_merge "") 198 199################################# 200# This section covers asm flags # 201################################# 202 203# Required ASM flags when using mwdt 204set_property(TARGET asm PROPERTY required "-Hasmcpp") 205 206if(CONFIG_ARCMWDT_LIBC) 207 # We rely on the default C/C++ include locations which are provided by MWDT if we do build with 208 # MW C / C++ libraries. However, for that case we still need to explicitly set header directory 209 # to ASM builds (which may use 'stdbool.h'). 210 set_property(TARGET asm APPEND PROPERTY required "-I${NOSTDINC}") 211endif() 212 213# Update after testing that -Wshadow and -Wno-array-bounds works 214set_compiler_property(PROPERTY warning_shadow_variables) 215set_compiler_property(PROPERTY warning_no_array_bounds) 216 217set_compiler_property(PROPERTY no_builtin -fno-builtin) 218set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc) 219 220# Compiler flag for not placing functions in their own sections: 221set_compiler_property(PROPERTY no_function_sections "-fno-function-sections") 222 223# Compiler flag for not placing variables in their own sections: 224set_compiler_property(PROPERTY no_data_sections "-fno-data-sections") 225