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 native_posix, clang has problems
14# compiling the native_posix with -fno-freestanding.
15check_set_compiler_property(PROPERTY hosted)
16
17# clang flags for coverage generation
18set_property(TARGET compiler PROPERTY coverage --coverage -fno-inline)
19
20# clang flag for colourful diagnostic messages
21set_compiler_property(PROPERTY diagnostic -fcolor-diagnostics)
22
23# clang flag to save temporary object files
24set_compiler_property(PROPERTY save_temps -save-temps)
25
26#######################################################
27# This section covers flags related to warning levels #
28#######################################################
29
30# clang option standard warning base in Zephyr
31check_set_compiler_property(PROPERTY warning_base
32                            -Wall
33                            -Wformat
34                            -Wformat-security
35                            -Wno-format-zero-length
36                            -Wno-unused-but-set-variable
37                            -Wno-typedef-redefinition
38                            -Wno-deprecated-non-prototype
39)
40
41check_set_compiler_property(APPEND PROPERTY warning_base -Wno-pointer-sign)
42
43# Prohibit void pointer arithmetic. Illegal in C99
44check_set_compiler_property(APPEND PROPERTY warning_base -Wpointer-arith)
45
46# clang options for warning levels 1, 2, 3, when using `-DW=[1|2|3]`
47set_compiler_property(PROPERTY warning_dw_1
48                      -Wextra
49                      -Wunused
50                      -Wno-unused-parameter
51                      -Wmissing-declarations
52                      -Wmissing-format-attribute
53)
54check_set_compiler_property(APPEND PROPERTY warning_dw_1
55                            -Wold-style-definition
56                            -Wmissing-prototypes
57                            -Wmissing-include-dirs
58                            -Wunused-but-set-variable
59                            -Wno-missing-field-initializers
60)
61
62set_compiler_property(PROPERTY warning_dw_2
63                      -Waggregate-return
64                      -Wcast-align
65                      -Wdisabled-optimization
66                      -Wnested-externs
67                      -Wshadow
68)
69
70check_set_compiler_property(APPEND PROPERTY warning_dw_2
71                            -Wlogical-op
72                            -Wmissing-field-initializers
73)
74
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
92check_set_compiler_property(PROPERTY warning_extended
93                            #FIXME: need to fix all of those
94                            -Wno-sometimes-uninitialized
95                            -Wno-shift-overflow
96                            -Wno-missing-braces
97                            -Wno-self-assign
98                            -Wno-address-of-packed-member
99                            -Wno-unused-function
100                            -Wno-initializer-overrides
101                            -Wno-section
102                            -Wno-unknown-warning-option
103                            -Wno-unused-variable
104                            -Wno-format-invalid-specifier
105                            -Wno-gnu
106                            # comparison of unsigned expression < 0 is always false
107                            -Wno-tautological-compare
108)
109
110set_compiler_property(PROPERTY warning_error_coding_guideline
111                      -Werror=vla
112                      -Wimplicit-fallthrough
113                      -Wconversion
114                      -Woverride-init
115)
116
117set_compiler_property(PROPERTY no_global_merge "-mno-global-merge")
118