diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index cc323f9..37f3857 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -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 + diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c1c349..d330d16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 +) \ No newline at end of file