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