diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..744bed2 --- /dev/null +++ b/.clang-format @@ -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 +... diff --git a/CMakeLists.txt b/CMakeLists.txt index a21dd57..d85e2ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,9 @@ include(cmake/common.cmake) # Config include(cmake/config.cmake) +# clang-format +include(cmake/clang-format.cmake) + # Libraries include(cmake/opengl.cmake) include(cmake/SFML.cmake) @@ -120,5 +123,8 @@ target_add_compile_definition(MagicPlayer ENABLE_CONSOLE_LOG) target_add_compile_definition(MagicPlayer SPDLOG_DEBUG_ON RELWITHDEBINFO DEBUG) #target_add_compile_definition(MagicPlayer SPDLOG_TRACE_ON DEBUG) +# Generate format target +target_generate_clang_format(MagicPlayer) + # Verbose makefile #set(CMAKE_VERBOSE_MAKEFILE ON) diff --git a/cmake/clang-format.cmake b/cmake/clang-format.cmake new file mode 100644 index 0000000..1662ffd --- /dev/null +++ b/cmake/clang-format.cmake @@ -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()