From 56f399dd1548c1bfdbf4321012df9a510c5b515e Mon Sep 17 00:00:00 2001 From: fancy <258828110.@qq.com> Date: Fri, 10 Nov 2023 08:00:12 -0800 Subject: [PATCH] Add clang-format config file. --- .clang-format | 137 ++++++++++++++++++++ CMakeLists.txt | 15 ++- build/cmake/toolchain/linux.toolchain.cmake | 5 +- build/global_config.cmake | 3 + 4 files changed, 157 insertions(+), 3 deletions(-) create mode 100755 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100755 index 00000000..365a8dea --- /dev/null +++ b/.clang-format @@ -0,0 +1,137 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: false + AfterEnum: true + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: true + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: true + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: false +IndentGotoLabels: true +IndentPPDirectives: BeforeHash +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Latest +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +... + diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c1e8a48..1e0cc507 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") unset(CLANG_TIDY_EXE CACHE) unset(CLANG_TIDY_FIND CACHE) if ("${CLANG_TIDY_SUPPORT}" MATCHES "true") -find_program(CLANG_TIDY_FIND NAMES clang-tidy PATHS ${LLVM_PATH}/build/bin) + find_program(CLANG_TIDY_FIND NAMES clang-tidy PATHS ${LLVM_PATH}/build/bin) if(CLANG_TIDY_FIND) message(STATUS "clang-tidy found: ${CLANG_TIDY_FIND}") # set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}" "-header-filter=no.h -system-headers=no.h -checks=modernize-use-override") @@ -33,6 +33,19 @@ find_program(CLANG_TIDY_FIND NAMES clang-tidy PATHS ${LLVM_PATH}/build/bin) message(FATAL_ERROR "You set support clang-tidy, bug clang-tidy not found.") endif() endif() +# find the clang-format tools +unset(CLANG_FORMAT_EXE CACHE) +unset(CLANG_FORMAT_FIND CACHE) +if ("${CLANG_FORMAT_SUPPORT}" MATCHES "true") + find_program(CLANG_FORMAT_FIND NAMES clang-format PATHS ${LLVM_PATH}/build/bin) + if(CLANG_FORMAT_FIND) + message(STATUS "clang-format found: ${CLANG_FORMAT_FIND}") + set(CLANG_FORMAT_EXE ${CLANG_FORMAT_FIND} CACHE STRING INTERNAL) + message("CLANG_FORMAT_EXE = ${CLANG_FORMAT_EXE}") + else() + message(FATAL_ERROR "You set support clang-format, bug clang-format not found.") + endif() +endif() if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX}) # execute_process(COMMAND sh build_lvgl_for_cmakelist.sh ${TARGET_PLATFORM} ${CMAKE_SOURCE_DIR_IPCSDK} WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/lvglLinux-x86/) diff --git a/build/cmake/toolchain/linux.toolchain.cmake b/build/cmake/toolchain/linux.toolchain.cmake index 040c839c..0ed88c74 100755 --- a/build/cmake/toolchain/linux.toolchain.cmake +++ b/build/cmake/toolchain/linux.toolchain.cmake @@ -37,10 +37,11 @@ set(TEST_COVERAGE "true") # ------------ build curl + openssl ------------ # set(CURL_OPENSSL_LIB_SHARED_ENABLE "false") # ------------ build curl + openssl end ------------ # -# ------------ build clang-tidy ------------ # +# ------------ build clang-tools ------------ # set(CLANG_TIDY_SUPPORT "true") +set(CLANG_FORMAT_SUPPORT "true") set(LLVM_PATH "/home/xiaojiazhu/project/tmp/llvm-project") -# ------------ build clang-tidy end ------------ # +# ------------ build clang-tools end ------------ # # ------------ build IpcConfig ------------ # set(IPC_CONFIG_FILE_PATH "./ipc_config") # ------------ build IpcConfig end ------------ # diff --git a/build/global_config.cmake b/build/global_config.cmake index ccd18c8c..e6d65647 100755 --- a/build/global_config.cmake +++ b/build/global_config.cmake @@ -45,6 +45,9 @@ set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-clang-diagnostic-error") set(CLANG_TIDY_CONFIG "-header-filter=\'.*\'") set(CLANG_TIDY_CONFIG "${CLANG_TIDY_CONFIG} -p ${CMAKE_SOURCE_DIR_IPCSDK}/cmake-shell") + +# set(CLANG_FORMAT_FILE "${CMAKE_SOURCE_DIR_IPCSDK}/tools/clang-format/.clang-format") +set(CLANG_FORMAT_FILE "LLVM ${CMAKE_SOURCE_DIR_IPCSDK}/tools/clang-format/.clang-format") # -------------------------- clang-tidy tools end -------------------------- # # -------------------------- log setting -------------------------- #