-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CMake format targets generation using clang-format
- Loading branch information
Showing
3 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--- | ||
Language: Cpp | ||
AccessModifierOffset: '-4' | ||
AlignAfterOpenBracket: Align | ||
AlignConsecutiveAssignments: 'false' | ||
AlignConsecutiveDeclarations: 'false' | ||
AlignEscapedNewlines: Left | ||
AlignOperands: 'true' | ||
AlignTrailingComments: 'false' | ||
AllowAllParametersOfDeclarationOnNextLine: 'false' | ||
AllowShortBlocksOnASingleLine: 'false' | ||
AllowShortCaseLabelsOnASingleLine: 'false' | ||
AllowShortFunctionsOnASingleLine: None | ||
AllowShortIfStatementsOnASingleLine: 'false' | ||
AllowShortLoopsOnASingleLine: 'false' | ||
AlwaysBreakAfterReturnType: None | ||
AlwaysBreakBeforeMultilineStrings: 'false' | ||
AlwaysBreakTemplateDeclarations: 'Yes' | ||
BinPackArguments: 'false' | ||
BinPackParameters: 'false' | ||
BraceWrapping: | ||
AfterClass: true | ||
AfterControlStatement: true | ||
AfterEnum: true | ||
AfterFunction: true | ||
AfterNamespace: true | ||
AfterObjCDeclaration: false | ||
AfterStruct: true | ||
AfterUnion: true | ||
AfterExternBlock: true | ||
BeforeCatch: true | ||
BeforeElse: true | ||
IndentBraces: false | ||
SplitEmptyFunction: true | ||
SplitEmptyRecord: true | ||
SplitEmptyNamespace: true | ||
BreakAfterJavaFieldAnnotations: 'true' | ||
BreakBeforeBinaryOperators: NonAssignment | ||
BreakBeforeBraces: Custom | ||
BreakBeforeTernaryOperators: 'true' | ||
BreakConstructorInitializers: BeforeComma | ||
BreakInheritanceList: BeforeComma | ||
BreakStringLiterals: 'false' | ||
ColumnLimit: '100' | ||
CompactNamespaces: 'false' | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true' | ||
ConstructorInitializerIndentWidth: '2' | ||
ContinuationIndentWidth: '2' | ||
Cpp11BracedListStyle: 'true' | ||
DerivePointerAlignment: 'false' | ||
DisableFormat: 'false' | ||
ExperimentalAutoDetectBinPacking: 'false' | ||
FixNamespaceComments: 'true' | ||
ForEachMacros: | ||
- foreach | ||
- Q_FOREACH | ||
- BOOST_FOREACH | ||
IncludeBlocks: Preserve | ||
IndentCaseLabels: 'true' | ||
IndentPPDirectives: AfterHash | ||
IndentWidth: '4' | ||
IndentWrappedFunctionNames: 'false' | ||
KeepEmptyLinesAtTheStartOfBlocks: 'true' | ||
MacroBlockBegin: '' | ||
MacroBlockEnd: '' | ||
MaxEmptyLinesToKeep: '1' | ||
NamespaceIndentation: All | ||
PenaltyBreakAssignment: 2 | ||
PenaltyBreakBeforeFirstCallParameter: 19 | ||
PenaltyBreakComment: 300 | ||
PenaltyBreakFirstLessLess: 120 | ||
PenaltyBreakString: 1000 | ||
PenaltyBreakTemplateDeclaration: 10 | ||
PenaltyExcessCharacter: 1000000 | ||
PenaltyReturnTypeOnItsOwnLine: 1000000 | ||
PointerAlignment: Left | ||
ReflowComments: 'false' | ||
SortIncludes: 'false' | ||
SortUsingDeclarations: 'false' | ||
SpaceAfterCStyleCast: 'false' | ||
SpaceAfterTemplateKeyword: 'false' | ||
SpaceBeforeAssignmentOperators: 'true' | ||
SpaceBeforeCpp11BracedList: 'false' | ||
SpaceBeforeCtorInitializerColon: 'false' | ||
SpaceBeforeInheritanceColon: 'true' | ||
SpaceBeforeParens: Never | ||
SpaceBeforeRangeBasedForLoopColon: 'false' | ||
SpaceInEmptyParentheses: 'false' | ||
SpacesBeforeTrailingComments: '1' | ||
SpacesInAngles: 'false' | ||
SpacesInCStyleCastParentheses: 'false' | ||
SpacesInContainerLiterals: 'false' | ||
SpacesInParentheses: 'false' | ||
SpacesInSquareBrackets: 'false' | ||
Standard: Cpp11 | ||
TabWidth: '4' | ||
UseTab: ForIndentation | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
## target_generate_clang_format(target) | ||
# Generate a format target for the target (format-${target}). | ||
# The generated target lanch clang-format on all the target sources with -style=file | ||
# {value} [in] target: Target from wich generate format target | ||
function(target_generate_clang_format target) | ||
if(NOT TARGET ${target}) | ||
message(FATAL_ERROR "${target} is not a target)") | ||
endif() | ||
|
||
set(format-target "format-${target}") | ||
find_program(CLANG_FORMAT clang-format | ||
NAMES clang-format-9 clang-format-8 clang-format-7 clang-format-6) | ||
if(${CLANG_FORMAT} STREQUAL CLANG_FORMAT-NOTFOUND) | ||
message(WARNING "clang-format not found, ${format-target} not generated") | ||
return() | ||
else() | ||
message(STATUS "clang-format found: ${CLANG_FORMAT}") | ||
endif() | ||
|
||
get_property(target_sources TARGET ${target} PROPERTY SOURCES) | ||
add_custom_target( | ||
${format-target} | ||
COMMAND "${CLANG_FORMAT}" -style=file -i ${target_sources} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
VERBATIM | ||
) | ||
message(STATUS "Format target ${format-target} generated") | ||
endfunction() |