Skip to content

Parameterise clangformat_targets for reuse by other projects#826

Open
mjp41 wants to merge 6 commits intomainfrom
clangformat_updates
Open

Parameterise clangformat_targets for reuse by other projects#826
mjp41 wants to merge 6 commits intomainfrom
clangformat_updates

Conversation

@mjp41
Copy link
Member

@mjp41 mjp41 commented Mar 20, 2026

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.

mjp41 added 6 commits March 20, 2026 08:12
The function previously hardcoded the source glob patterns and
exclusion regexes, making it unusable for projects with a different
directory layout.

Add optional INCLUDE_PATTERNS and EXCLUDE_PATTERNS arguments via
cmake_parse_arguments.  The defaults match the existing behaviour
(src/*.cc, src/*.h, src/*.hh; exclude *_concept.h), so the current
call site is unchanged.
@mjp41 mjp41 marked this pull request as ready for review March 20, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant