Parameterise clangformat_targets for reuse by other projects#826
Open
Parameterise clangformat_targets for reuse by other projects#826
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.