add formatting to cmake

This commit is contained in:
Bechir Braham 2024-04-03 14:50:14 +02:00
parent 2e4eec0c8a
commit 76c0f7a757
No known key found for this signature in database
GPG Key ID: 7F511B55FD8E9671
2 changed files with 24 additions and 1 deletions

View File

@ -11,9 +11,13 @@ jobs:
# find all examples in build/examples and run them
run: |
pwd
find -name "*.cpp" -not -path "./build/*" | xargs -I {} -n 1 -P 10 clang-format {} -Werror --dry-run -style='file:.clang-format'
mkdir build
cd build
cmake ..
cmake --build . --target=check-format

View File

@ -164,3 +164,22 @@ add_subdirectory(examples)
if(AARE_PYTHON_BINDINGS)
add_subdirectory(python)
endif()
# custom target to run check formatting with clang-format
add_custom_target(
check-format
COMMAND find \( -name "*.cpp" -o -name "*.hpp" \) -not -path "./build/*" | xargs -I {} -n 1 -P 10 bash -c "clang-format -Werror -style=\"file:.clang-format\" {} | diff {} -"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Checking code formatting with clang-format"
VERBATIM
)
add_custom_target(
format-files
COMMAND find \( -name "*.cpp" -o -name "*.hpp" \) -not -path "./build/*" | xargs -I {} -n 1 -P 10 bash -c "clang-format -i -style=\"file:.clang-format\" {}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Formatting with clang-format"
VERBATIM
)