diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..54915a6 --- /dev/null +++ b/.clang-format @@ -0,0 +1,173 @@ +--- +# Project +Standard: c++17 +ColumnLimit: 120 + +# Indentation +AccessModifierOffset: -4 +BitFieldColonSpacing: Both +ContinuationIndentWidth: 4 +IndentCaseLabels: true +IndentCaseBlocks: false +IndentExternBlock: Indent +IndentPPDirectives: None +IndentRequires: true +IndentWidth: 4 +IndentWrappedFunctionNames: true +TabWidth: 4 +UseTab: Never + +# Alignment +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: Consecutive +AlignConsecutiveBitFields: Consecutive +AlignConsecutiveDeclarations: Consecutive +AlignConsecutiveMacros: Consecutive +AlignEscapedNewlines: Left +AlignOperands: Align +AlignTrailingComments: true + +# Allow +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortLambdasOnASingleLine: All + +# Break +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeConceptDeclarations: true +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: AfterColon +BreakBeforeBinaryOperators: None +BreakInheritanceList: AfterColon +BreakStringLiterals: true + +# Initializers & arguments +BinPackArguments: false +BinPackParameters: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 0 +Cpp11BracedListStyle: true + +# Braces +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: false + BeforeElse: true + BeforeLambdaBody: true + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true + +# Namespaces +CompactNamespaces: false +FixNamespaceComments: true +NamespaceIndentation: None + +# Derive +DeriveLineEnding: false +DerivePointerAlignment: false + +# Empty lines +EmptyLineBeforeAccessModifier: Always +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 + +# Sorting +IncludeBlocks: Regroup +IncludeCategories: + - Priority: 1 + Regex: '^$' + - Priority: 2 + Regex: '^$' + - Priority: 3 + Regex: '^$' +SortIncludes: true +SortUsingDeclarations: true + +# Penalties +PenaltyBreakAssignment: 1000 +PenaltyBreakBeforeFirstCallParameter: 1000 +PenaltyBreakComment: 200 +PenaltyBreakFirstLessLess: 100 +PenaltyBreakString: 1 +PenaltyBreakTemplateDeclaration: 0 +PenaltyExcessCharacter: 5 +PenaltyIndentedWhitespace: 1 +PenaltyReturnTypeOnItsOwnLine: 500 + +# Pointer alignment +PointerAlignment: Left + +# Comments +ReflowComments: false + +# Spaces +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false + +# Line endings +UseCRLF: false + +# Qualifiers (const, volatile, static, etc) +QualifierAlignment: Custom +QualifierOrder: ['static', 'inline', 'constexpr', 'const', 'volatile', 'type'] + +--- +Language: ObjC +IndentWidth: 4 +BreakBeforeBraces: Custom +BraceWrapping: + AfterObjCDeclaration: true + +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 4 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: false + +... diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8abb65..67d9106 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,6 +69,20 @@ jobs: - name: Test run: ctest --test-dir CSFML/build -C ${{matrix.type.name}} --output-on-failure + format: + name: Formatting + runs-on: ubuntu-22.04 + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Format Code + run: cmake -DCLANG_FORMAT_EXECUTABLE=clang-format-14 -P cmake/Format.cmake + + - name: Check Formatting + run: git diff --exit-code + tidy: name: Analyze runs-on: macos-14 diff --git a/CMakeLists.txt b/CMakeLists.txt index 248d9df..a00a37f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,6 +113,11 @@ if(CSFML_BUILD_TEST_SUITE) add_subdirectory(test) endif() +csfml_set_option(CLANG_FORMAT_EXECUTABLE clang-format STRING "Override clang-format executable, requires version 14") +add_custom_target(format + COMMAND ${CMAKE_COMMAND} -DCLANG_FORMAT_EXECUTABLE=${CLANG_FORMAT_EXECUTABLE} -P ./cmake/Format.cmake + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} VERBATIM) + csfml_set_option(CLANG_TIDY_EXECUTABLE clang-tidy STRING "Override clang-tidy executable, requires minimum version 14") add_custom_target(tidy COMMAND ${CMAKE_COMMAND} -DCLANG_TIDY_EXECUTABLE=${CLANG_TIDY_EXECUTABLE} -DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR} -P ./cmake/Tidy.cmake diff --git a/cmake/Format.cmake b/cmake/Format.cmake new file mode 100644 index 0000000..9fcc829 --- /dev/null +++ b/cmake/Format.cmake @@ -0,0 +1,27 @@ +# Check executable exists +if(NOT EXISTS ${CLANG_FORMAT_EXECUTABLE}) + find_program(CLANG_FORMAT_EXEC_TEMP ${CLANG_FORMAT_EXECUTABLE}) + if(CLANG_FORMAT_EXEC_TEMP) + set(CLANG_FORMAT_EXECUTABLE ${CLANG_FORMAT_EXEC_TEMP}) + unset(CLANG_FORMAT_EXEC_TEMP) + else() + message(FATAL_ERROR "Unable to find clang-format executable: \"${CLANG_FORMAT_EXECUTABLE}\"") + endif() +endif() + +# Check executable version +execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} --version OUTPUT_VARIABLE CLANG_FORMAT_VERSION) +string(REGEX MATCH "clang-format version ([0-9]+)" CLANG_FORMAT_VERSION ${CLANG_FORMAT_VERSION}) +unset(CLANG_FORMAT_VERSION) +if(NOT CMAKE_MATCH_1 EQUAL 14) + message(FATAL_ERROR "clang-format version ${CMAKE_MATCH_1} not supported. Must use version 14") +endif() + +# Run +set(SOURCES "") +foreach(FOLDER IN ITEMS examples include src test) + file(GLOB_RECURSE folder_files "${FOLDER}/*.h" "${FOLDER}/*.hpp" "${FOLDER}/*.c" "${FOLDER}/*.cpp") + list(APPEND SOURCES ${folder_files}) +endforeach() + +execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -i ${SOURCES}) diff --git a/src/CSFML/Graphics/ConvertTransform.hpp b/src/CSFML/Graphics/ConvertTransform.hpp index 928af0d..651e392 100644 --- a/src/CSFML/Graphics/ConvertTransform.hpp +++ b/src/CSFML/Graphics/ConvertTransform.hpp @@ -47,7 +47,10 @@ [[nodiscard]] inline sf::Transform convertTransform(const sfTransform& transform) { const float* m = transform.matrix; + + // clang-format off return {m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]}; + // clang-format on } diff --git a/src/CSFML/Graphics/Transform.cpp b/src/CSFML/Graphics/Transform.cpp index c24f5bc..3829479 100644 --- a/src/CSFML/Graphics/Transform.cpp +++ b/src/CSFML/Graphics/Transform.cpp @@ -37,9 +37,11 @@ //////////////////////////////////////////////////////////// const sfTransform sfTransform_Identity = { + // clang-format off 1, 0, 0, 0, 1, 0, 0, 0, 1, + // clang-format on };