23
23
###########################################################################
24
24
include (CheckCCompilerFlag)
25
25
26
- unset (WPICKY )
26
+ unset (_picky )
27
27
28
28
if (CURL_WERROR AND
29
29
((CMAKE_COMPILER_IS_GNUCC AND
30
30
NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 AND
31
31
NOT CMAKE_VERSION VERSION_LESS 3.23.0) OR # to avoid check_symbol_exists() conflicting with GCC -pedantic-errors
32
32
CMAKE_C_COMPILER_ID MATCHES "Clang" ))
33
- list (APPEND WPICKY "-pedantic-errors" )
33
+ list (APPEND _picky "-pedantic-errors" )
34
34
endif ()
35
35
36
36
if (APPLE AND
37
37
(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.6) OR
38
38
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.3))
39
- list (APPEND WPICKY "-Werror=partial-availability" ) # clang 3.6 appleclang 6.3
39
+ list (APPEND _picky "-Werror=partial-availability" ) # clang 3.6 appleclang 6.3
40
40
endif ()
41
41
42
42
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang" )
43
- list (APPEND WPICKY "-Werror-implicit-function-declaration" ) # clang 1.0 gcc 2.95
43
+ list (APPEND _picky "-Werror-implicit-function-declaration" ) # clang 1.0 gcc 2.95
44
44
endif ()
45
45
46
46
if (PICKY_COMPILER)
@@ -49,29 +49,29 @@ if(PICKY_COMPILER)
49
49
# https://clang.llvm.org/docs/DiagnosticsReference.html
50
50
# https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
51
51
52
- # WPICKY_ENABLE = Options we want to enable as-is.
53
- # WPICKY_DETECT = Options we want to test first and enable if available.
52
+ # _picky_enable = Options we want to enable as-is.
53
+ # _picky_detect = Options we want to test first and enable if available.
54
54
55
55
# Prefer the -Wextra alias with clang.
56
56
if (CMAKE_C_COMPILER_ID MATCHES "Clang" )
57
- set (WPICKY_ENABLE "-Wextra" )
57
+ set (_picky_enable "-Wextra" )
58
58
else ()
59
- set (WPICKY_ENABLE "-W" )
59
+ set (_picky_enable "-W" )
60
60
endif ()
61
61
62
- list (APPEND WPICKY_ENABLE
62
+ list (APPEND _picky_enable
63
63
-Wall -pedantic
64
64
)
65
65
66
66
# ----------------------------------
67
67
# Add new options here, if in doubt:
68
68
# ----------------------------------
69
- set (WPICKY_DETECT
69
+ set (_picky_detect
70
70
)
71
71
72
72
# Assume these options always exist with both clang and gcc.
73
73
# Require clang 3.0 / gcc 2.95 or later.
74
- list (APPEND WPICKY_ENABLE
74
+ list (APPEND _picky_enable
75
75
-Wbad-function-cast # clang 2.7 gcc 2.95
76
76
-Wconversion # clang 2.7 gcc 2.95
77
77
-Winline # clang 1.0 gcc 1.0
@@ -89,7 +89,7 @@ if(PICKY_COMPILER)
89
89
)
90
90
91
91
# Always enable with clang, version dependent with gcc
92
- set (WPICKY_COMMON_OLD
92
+ set (_picky_common_old
93
93
-Waddress # clang 2.7 gcc 4.3
94
94
-Wattributes # clang 2.7 gcc 4.1
95
95
-Wcast-align # clang 1.0 gcc 4.2
@@ -118,16 +118,16 @@ if(PICKY_COMPILER)
118
118
-Wvla # clang 2.8 gcc 4.3
119
119
)
120
120
121
- set (WPICKY_COMMON
121
+ set (_picky_common
122
122
-Wdouble-promotion # clang 3.6 gcc 4.6 appleclang 6.3
123
123
-Wenum-conversion # clang 3.2 gcc 10.0 appleclang 4.6 g++ 11.0
124
124
-Wpragmas # clang 3.5 gcc 4.1 appleclang 6.0
125
125
-Wunused-const-variable # clang 3.4 gcc 6.0 appleclang 5.1
126
126
)
127
127
128
128
if (CMAKE_C_COMPILER_ID MATCHES "Clang" )
129
- list (APPEND WPICKY_ENABLE
130
- ${WPICKY_COMMON_OLD }
129
+ list (APPEND _picky_enable
130
+ ${_picky_common_old }
131
131
-Wshift-sign-overflow # clang 2.9
132
132
-Wshorten-64-to-32 # clang 1.0
133
133
-Wlanguage-extension-token # clang 3.0
@@ -136,41 +136,41 @@ if(PICKY_COMPILER)
136
136
# Enable based on compiler version
137
137
if ((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.6) OR
138
138
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.3))
139
- list (APPEND WPICKY_ENABLE
140
- ${WPICKY_COMMON }
139
+ list (APPEND _picky_enable
140
+ ${_picky_common }
141
141
-Wunreachable-code-break # clang 3.5 appleclang 6.0
142
142
-Wheader-guard # clang 3.4 appleclang 5.1
143
143
-Wsometimes-uninitialized # clang 3.2 appleclang 4.6
144
144
)
145
145
endif ()
146
146
if ((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.9) OR
147
147
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.3))
148
- list (APPEND WPICKY_ENABLE
148
+ list (APPEND _picky_enable
149
149
-Wcomma # clang 3.9 appleclang 8.3
150
150
-Wmissing-variable -declarations # clang 3.2 appleclang 4.6
151
151
)
152
152
endif ()
153
153
if ((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0) OR
154
154
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.3))
155
- list (APPEND WPICKY_ENABLE
155
+ list (APPEND _picky_enable
156
156
-Wassign-enum # clang 7.0 appleclang 10.3
157
157
-Wextra-semi-stmt # clang 7.0 appleclang 10.3
158
158
)
159
159
endif ()
160
160
if ((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0) OR
161
161
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.4))
162
- list (APPEND WPICKY_ENABLE
162
+ list (APPEND _picky_enable
163
163
-Wimplicit-fallthrough # clang 4.0 gcc 7.0 appleclang 12.4 # We do silencing for clang 10.0 and above only
164
164
)
165
165
endif ()
166
166
else () # gcc
167
- list (APPEND WPICKY_DETECT
168
- ${WPICKY_COMMON }
167
+ list (APPEND _picky_detect
168
+ ${_picky_common }
169
169
)
170
170
# Enable based on compiler version
171
171
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.3)
172
- list (APPEND WPICKY_ENABLE
173
- ${WPICKY_COMMON_OLD }
172
+ list (APPEND _picky_enable
173
+ ${_picky_common_old }
174
174
-Wclobbered # gcc 4.3
175
175
-Wmissing-parameter-type # gcc 4.3
176
176
-Wold-style-declaration # gcc 4.3
@@ -179,22 +179,22 @@ if(PICKY_COMPILER)
179
179
)
180
180
endif ()
181
181
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5 AND MINGW)
182
- list (APPEND WPICKY_ENABLE
182
+ list (APPEND _picky_enable
183
183
-Wno-pedantic-ms-format # gcc 4.5 (MinGW-only)
184
184
)
185
185
endif ()
186
186
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8)
187
- list (APPEND WPICKY_ENABLE
187
+ list (APPEND _picky_enable
188
188
-Wformat=2 # clang 3.0 gcc 4.8
189
189
)
190
190
endif ()
191
191
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0)
192
- list (APPEND WPICKY_ENABLE
192
+ list (APPEND _picky_enable
193
193
-Warray-bounds=2 -ftree-vrp # clang 3.0 gcc 5.0 (clang default: -Warray-bounds)
194
194
)
195
195
endif ()
196
196
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.0)
197
- list (APPEND WPICKY_ENABLE
197
+ list (APPEND _picky_enable
198
198
-Wduplicated-cond # gcc 6.0
199
199
-Wnull-dereference # clang 3.0 gcc 6.0 (clang default)
200
200
-fdelete-null-pointer-checks
@@ -203,7 +203,7 @@ if(PICKY_COMPILER)
203
203
)
204
204
endif ()
205
205
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0)
206
- list (APPEND WPICKY_ENABLE
206
+ list (APPEND _picky_enable
207
207
-Walloc-zero # gcc 7.0
208
208
-Wduplicated-branches # gcc 7.0
209
209
-Wformat-truncation=2 # gcc 7.0
@@ -212,45 +212,47 @@ if(PICKY_COMPILER)
212
212
)
213
213
endif ()
214
214
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0)
215
- list (APPEND WPICKY_ENABLE
215
+ list (APPEND _picky_enable
216
216
-Warith-conversion # gcc 10.0
217
217
)
218
218
endif ()
219
219
endif ()
220
220
221
221
#
222
222
223
- foreach (_ccopt IN LISTS WPICKY_ENABLE )
224
- list (APPEND WPICKY "${_ccopt} " )
223
+ foreach (_ccopt IN LISTS _picky_enable )
224
+ list (APPEND _picky "${_ccopt} " )
225
225
endforeach ()
226
226
227
- foreach (_ccopt IN LISTS WPICKY_DETECT)
228
- # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
229
- # test result in.
227
+ foreach (_ccopt IN LISTS _picky_detect)
228
+ # Use a unique variable name 1. for meaningful log output 2. to have a fresh, undefined variable for each detection
230
229
string (MAKE_C_IDENTIFIER "OPT${_ccopt} " _optvarname)
231
230
# GCC only warns about unknown -Wno- options if there are also other diagnostic messages,
232
231
# so test for the positive form instead
233
232
string (REPLACE "-Wno-" "-W" _ccopt_on "${_ccopt} " )
234
233
check_c_compiler_flag(${_ccopt_on} ${_optvarname} )
235
234
if (${_optvarname} )
236
- list (APPEND WPICKY "${_ccopt} " )
235
+ list (APPEND _picky "${_ccopt} " )
237
236
endif ()
238
237
endforeach ()
239
238
endif ()
240
239
endif ()
241
240
242
241
# clang-cl
243
242
if (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND MSVC )
244
- # list(TRANSFORM WPICKY PREPEND "/clang:") # since CMake 3.12
245
- set (_wpicky "" )
246
- foreach (_ccopt IN LISTS WPICKY)
247
- list (APPEND _wpicky "/clang:${_ccopt} " )
248
- endforeach ()
249
- set (WPICKY ${_wpicky} )
243
+ if (CMAKE_VERSION VERSION_LESS 3.12)
244
+ set (_picky_tmp "" )
245
+ foreach (_ccopt IN LISTS _picky)
246
+ list (APPEND _picky_tmp "/clang:${_ccopt} " )
247
+ endforeach ()
248
+ set (_picky ${_picky_tmp} )
249
+ else ()
250
+ list (TRANSFORM _picky PREPEND "/clang:" )
251
+ endif ()
250
252
endif ()
251
253
252
- if (WPICKY )
253
- string (REPLACE ";" " " WPICKY "${WPICKY } " )
254
- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WPICKY } " )
255
- message (STATUS "Picky compiler options:${WPICKY } " )
254
+ if (_picky )
255
+ string (REPLACE ";" " " _picky "${_picky } " )
256
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_picky } " )
257
+ message (STATUS "Picky compiler options:${_picky } " )
256
258
endif ()
0 commit comments