Commit 4d232d5
authored
Parameterise clangformat_targets for reuse by other projects (#826)
The clangformat_targets() CMake function previously hardcoded the source glob patterns, exclusion regexes, target name, and tool version, making it unusable for projects with a different directory layout or toolchain.
This PR makes the function fully configurable via optional keyword arguments, with defaults that preserve the existing behaviour for snmalloc:
INCLUDE_PATTERNS — glob patterns for source file discovery (default: src/.cc src/.h src/.hh).
EXCLUDE_PATTERNS — regex patterns to exclude from formatting (default: src/[^/]/[^/]*_concept.h$).
VERSION — clang-format version to search for (default: 15). The versioned names (clang-format-15, clang-format150) are tried first; if not found, falls back to the unversioned clang-format with a warning.
TARGET_NAME — name of the generated CMake target (default: clangformat), avoiding collisions when snmalloc is consumed as a subdirectory.
Additionally, a -check target (e.g. clangformat-check) is now generated alongside the formatting target. It runs clang-format --dry-run --Werror, suitable for CI validation without modifying files.
The existing call site clangformat_targets() is unchanged and behaves identically to before.1 parent 139180c commit 4d232d5
3 files changed
+73
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
| 376 | + | |
380 | 377 | | |
381 | 378 | | |
382 | 379 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
216 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
217 | 264 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 265 | + | |
| 266 | + | |
222 | 267 | | |
223 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
224 | 277 | | |
225 | 278 | | |
226 | 279 | | |
227 | 280 | | |
228 | | - | |
| 281 | + | |
229 | 282 | | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
235 | 288 | | |
236 | | - | |
| 289 | + | |
237 | 290 | | |
238 | 291 | | |
239 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
240 | 298 | | |
241 | 299 | | |
242 | 300 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
| 3 | + | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
0 commit comments