cmake-examples
cmake-examples copied to clipboard
Improve clang-format check target by showing files which are not correctly formatted
Hello, nice work creating/collecting all the examples.
I used your project to integrate clang-format into CMake. Doing that I adapted it slightly and want to suggest this as a possible improvement. I found that the check target would just error if code was not formatted. In clang-format you can use the --dry--run and --Werror flags to get output of what was not formatted and also getting a sensible return code without grep. My code for the custom target looks like this:
add_custom_target(clang-format-check
COMMENT "Checking clang-format changes"
COMMAND ${ClangFormat_EXECUTABLE}
--style=file
--dry-run
--Werror
${ALL_SOURCE_FILES}
)
The output when run: