Add clang-format config file.

This commit is contained in:
fancy 2023-11-10 08:00:12 -08:00
parent 7867d78b42
commit 56f399dd15
4 changed files with 157 additions and 3 deletions

137
.clang-format Executable file
View File

@ -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
...

View File

@ -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/)

View File

@ -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 ------------ #

View File

@ -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 -------------------------- #