Skip to content

Commit 8f35864

Browse files
author
haoli
committed
Add .clang-format
1 parent d012042 commit 8f35864

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

.clang-format

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
# display changed items only
3+
Language: Cpp
4+
BasedOnStyle: Google
5+
AccessModifierOffset: -4
6+
AllowShortEnumsOnASingleLine: true
7+
AllowShortBlocksOnASingleLine: Empty
8+
AllowShortCaseLabelsOnASingleLine: false
9+
AllowShortFunctionsOnASingleLine: Inline
10+
AllowShortLambdasOnASingleLine: All
11+
AllowShortIfStatementsOnASingleLine: Never
12+
AllowShortLoopsOnASingleLine: false
13+
AlwaysBreakBeforeMultilineStrings: false
14+
AlwaysBreakTemplateDeclarations: Yes
15+
BreakBeforeBraces: Custom
16+
BraceWrapping:
17+
AfterCaseLabel: true
18+
AfterClass: true
19+
AfterControlStatement: Always
20+
AfterEnum: true
21+
AfterFunction: true
22+
AfterNamespace: false
23+
AfterObjCDeclaration: false
24+
AfterStruct: true
25+
AfterUnion: true
26+
AfterExternBlock: true
27+
BeforeCatch: false
28+
BeforeElse: false
29+
BeforeLambdaBody: false
30+
BeforeWhile: false
31+
IndentBraces: false
32+
SplitEmptyFunction: false
33+
SplitEmptyRecord: false
34+
SplitEmptyNamespace: false
35+
BreakBeforeTernaryOperators: false
36+
ColumnLimit: 129
37+
CompactNamespaces: true
38+
IndentWidth: 4
39+
...

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ if(CPPBASE_BUILD_TESTING)
4747
add_subdirectory(tests)
4848
endif()
4949

50+
include(ClangFormat)
51+
clang_format_recurse("common" "logging" "network" "tests")
52+
5053
install(FILES
5154
${CMAKE_CURRENT_SOURCE_DIR}/common/Global.h
5255
${CMAKE_CURRENT_SOURCE_DIR}/common/Semaphore.h

cmake/ClangFormat.cmake

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# project/
2+
# --third3ty/
3+
# --src/
4+
# --test/
5+
# --doc/
6+
# --.clang_format
7+
#
8+
# clang_format_recurse("src" "test")
9+
10+
option(USE_CLANG_FORMAT "Apply clang-format to files in-place." OFF)
11+
12+
function(clang_format_recurse DIRS...)
13+
if(USE_CLANG_FORMAT)
14+
# Try to locate "clang-format"
15+
find_program(CLANG_FORMAT clang-format PATHS ENV PATH)
16+
if(CLANG_FORMAT)
17+
message(STATUS "clang-format found at: ${CLANG_FORMAT}")
18+
execute_process(COMMAND ${CLANG_FORMAT} --version)
19+
else()
20+
message(FATAL_ERROR "clang-format not found, style not available")
21+
endif()
22+
23+
# Process individual file
24+
foreach(DIR ${ARGV})
25+
file(GLOB_RECURSE FILES
26+
"${DIR}/*.cpp"
27+
"${DIR}/*.h"
28+
"${DIR}/*.hpp"
29+
)
30+
foreach(FILE ${FILES})
31+
if(NOT "${FILE}" STREQUAL "")
32+
execute_process(COMMAND ${CLANG_FORMAT} -style=file -i ${FILE})
33+
endif()
34+
endforeach(FILE)
35+
endforeach(DIR)
36+
endif()
37+
endfunction(clang_format_recurse)

0 commit comments

Comments
 (0)