diff options
author | Ralf Habacker <ralf.habacker@freenet.de> | 2018-03-14 01:17:27 +0100 |
---|---|---|
committer | Ralf Habacker <ralf.habacker@freenet.de> | 2018-03-14 01:41:55 +0100 |
commit | f3a3804725b021c644da7ef01fcc88b9f1a9e0fb (patch) | |
tree | a9444268c32285260e5383c068242037e957b984 | |
parent | 29afefef7223e0182aeb1dbf8e61cc8b5aee6e62 (diff) |
Add clang-format supportclang-format
After trying astyle, indent and uncrustify it turned out that clang-format
gives the best result so far.
With the current configuration file .clang-format code formatting with
make 'clang-format', which has been introduced with this commit, may not
be applicable to all files, but gives some insights about style differences. and may help
Reformatting single files or parts of files as a preparation for
creating patches may be more applicable.
The added clang configuration can also be used from development IDE's like
QtCreator by enabling the Beautifier plugin and selecting 'file' from the
list of predefined styles. Code formatting of single files can be processed
by selecting menu entry Extra->Beautifier->ClangFormat->Format Current File
or Extra->Beautifier->ClangFormat->Format At Cursor.
-rw-r--r-- | .clang-format | 92 | ||||
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | cmake/CMakeLists.txt | 9 |
3 files changed, 105 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..248150212 --- /dev/null +++ b/.clang-format @@ -0,0 +1,92 @@ +--- +Language: Cpp +# BasedOnStyle: GNU +AccessModifierOffset: -2 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: false +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: All +AlwaysBreakAfterReturnType: AllDefinitions +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: GNU +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: true +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 3 + - Regex: '^(<|"(gtest|isl|json)/)' + Priority: 4 + - Regex: '.\*' + Priority: 2 + - Regex: '^(<|"(config|config-)/)' + Priority: 1 +IndentCaseLabels: false +IndentWidth: 2 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: false +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: Always +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp03 +TabWidth: 8 +UseTab: Never +... + diff --git a/Makefile.am b/Makefile.am index 8ffa97bfd..4405d93dc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,5 +50,9 @@ DISTCHECK_CONFIGURE_FLAGS = \ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} +# TODO find clang-format +clang-format: + clang-format -style=file -i $(find $(top_srcdir) -name '*.[ch]') + # Add rules for code-coverage testing, as defined by AX_CODE_COVERAGE @CODE_COVERAGE_RULES@ diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 3becfc90e..e67257784 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -661,6 +661,15 @@ add_custom_target(help-options WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) +find_program(CLANG_FORMAT_EXECUTABLE clang-format) +if (CLANG_FORMAT_EXECUTABLE) + file(GLOB_RECURSE SOURCE_FILES RELATIVE_PATH "${CMAKE_SOURCE_DIR}/../*.[ch]") + add_custom_target(clang-format + clang-format -style=file -i ${SOURCE_FILES} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/.. + ) +endif() + # # create pkgconfig file # |