Set up auto-formatter

This commit is contained in:
Camden Dixie O'Brien 2024-12-25 18:08:53 +00:00
parent 21cf170b5a
commit 5c49bb98ce
5 changed files with 37 additions and 0 deletions

21
.clang-format Normal file
View File

@ -0,0 +1,21 @@
---
BasedOnStyle: WebKit
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: false
AlignTrailingComments: false
TabWidth: 4
UseTab: ForIndentation
DerivePointerAlignment: false
PointerAlignment: Right
BinPackArguments: true
BinPackParameters: true
ExperimentalAutoDetectBinPacking: false
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: None
ColumnLimit: 77
...

View File

@ -14,6 +14,15 @@ macro(set_default_target_options target)
endif()
endmacro()
add_custom_target(format
COMMAND sh ${CMAKE_SOURCE_DIR}/scripts/format.sh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(check-format
COMMAND sh ${CMAKE_SOURCE_DIR}/scripts/check-format.sh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_subdirectory(engine)
if (${TESTS})

2
scripts/check-format.sh Executable file
View File

@ -0,0 +1,2 @@
scripts_dir=`dirname $0`
sh "$scripts_dir/sources.sh" | xargs -n 1 clang-format --dry-run --Werror

2
scripts/format.sh Executable file
View File

@ -0,0 +1,2 @@
scripts_dir=`dirname $0`
sh "$scripts_dir/sources.sh" | xargs -n 1 clang-format -i

3
scripts/sources.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
root=`git rev-parse --show-toplevel`
find "$root/engine" "$root/tests" -name '*.c' -o -name '*.h'