1# First step is to inherit all properties from gcc, as clang is compatible with most flags. 2include(${ZEPHYR_BASE}/cmake/compiler/gcc/compiler_flags.cmake) 3 4# Now, let's overwrite the flags that are different in clang. 5 6# No property flag, clang doesn't understand fortify at all 7set_compiler_property(PROPERTY security_fortify_compile_time) 8set_compiler_property(PROPERTY security_fortify_run_time) 9 10# No printf-return-value optimizations in clang 11set_compiler_property(PROPERTY no_printf_return_value) 12 13# No property flag, this is used by the POSIX arch based targets when building with the host libC, 14# But clang has problems compiling these with -fno-freestanding. 15check_set_compiler_property(PROPERTY hosted) 16 17# clang flags for coverage generation 18if (CONFIG_COVERAGE_NATIVE_SOURCE) 19 set_compiler_property(PROPERTY coverage -fprofile-instr-generate -fcoverage-mapping) 20else() 21 set_compiler_property(PROPERTY coverage --coverage -fno-inline) 22endif() 23 24# clang flag for colourful diagnostic messages 25set_compiler_property(PROPERTY diagnostic -fcolor-diagnostics) 26 27# clang flag to save temporary object files 28set_compiler_property(PROPERTY save_temps -save-temps) 29 30# clang doesn't handle the -T flag 31set_compiler_property(PROPERTY linker_script -Wl,-T) 32 33####################################################### 34# This section covers flags related to warning levels # 35####################################################### 36 37# clang option standard warning base in Zephyr 38check_set_compiler_property(PROPERTY warning_base 39 -Wall 40 -Wformat 41 -Wformat-security 42 -Wno-format-zero-length 43 -Wno-unused-but-set-variable 44 -Wno-typedef-redefinition 45 -Wno-deprecated-non-prototype 46) 47 48# C implicit promotion rules will want to make floats into doubles very easily 49check_set_compiler_property(APPEND PROPERTY warning_base -Wdouble-promotion) 50 51check_set_compiler_property(APPEND PROPERTY warning_base -Wno-pointer-sign) 52 53# Prohibit void pointer arithmetic. Illegal in C99 54check_set_compiler_property(APPEND PROPERTY warning_base -Wpointer-arith) 55 56# clang options for warning levels 1, 2, 3, when using `-DW=[1|2|3]` 57set_compiler_property(PROPERTY warning_dw_1 58 -Wextra 59 -Wunused 60 -Wno-unused-parameter 61 -Wmissing-declarations 62 -Wmissing-format-attribute 63) 64check_set_compiler_property(APPEND PROPERTY warning_dw_1 65 -Wold-style-definition 66 -Wmissing-prototypes 67 -Wmissing-include-dirs 68 -Wunused-but-set-variable 69 -Wno-missing-field-initializers 70) 71 72set_compiler_property(PROPERTY warning_dw_2 73 -Waggregate-return 74 -Wcast-align 75 -Wdisabled-optimization 76 -Wnested-externs 77 -Wshadow 78) 79 80check_set_compiler_property(APPEND PROPERTY warning_dw_2 81 -Wlogical-op 82 -Wmissing-field-initializers 83) 84 85set_compiler_property(PROPERTY warning_dw_3 86 -Wbad-function-cast 87 -Wcast-qual 88 -Wconversion 89 -Wpacked 90 -Wpadded 91 -Wpointer-arith 92 -Wredundant-decls 93 -Wswitch-default 94) 95 96check_set_compiler_property(APPEND PROPERTY warning_dw_3 97 -Wpacked-bitfield-compat 98 -Wvla 99) 100 101 102check_set_compiler_property(PROPERTY warning_extended 103 #FIXME: need to fix all of those 104 -Wno-sometimes-uninitialized 105 -Wno-self-assign 106 -Wno-address-of-packed-member 107 -Wno-unused-function 108 -Wno-initializer-overrides 109 -Wno-section 110 -Wno-unused-variable 111 -Wno-gnu 112) 113 114set_compiler_property(PROPERTY warning_error_coding_guideline 115 -Werror=vla 116 -Wimplicit-fallthrough 117 -Wconversion 118 -Woverride-init 119) 120 121set_compiler_property(PROPERTY no_global_merge "-mno-global-merge") 122 123set_compiler_property(PROPERTY specs) 124