Skip to content

Commit 0dfbdaf

Browse files
committed
Add .clang-tidy
1 parent e1d6d52 commit 0dfbdaf

File tree

4 files changed

+86
-5
lines changed

4 files changed

+86
-5
lines changed

.clang-tidy

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Checks: '
2+
*,
3+
-cert-err58-cpp,
4+
-cppcoreguidelines-pro-type-union-access,
5+
-fuchsia-default-arguments,
6+
-fuchsia-overloaded-operator,
7+
-fuchsia-statically-constructed-objects,
8+
-google-readability-todo,
9+
-hicpp-signed-bitwise
10+
'
11+
12+
WarningsAsErrors: '
13+
clang-analyzer-*,
14+
modernize-*,
15+
performance-*
16+
'
17+
18+
FormatStyle: 'file'
19+
20+
CheckOptions:
21+
- key: readability-magic-numbers.IgnoredIntegerValues
22+
value: '0;1;2;3;4;16;255;1024'
23+
- key: cppcoreguidelines-readability-magic-numbers.IgnoredIntegerValues
24+
value: '0;1;2;3;4;16;255;1024'

CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ IF(NOT ARCH MATCHES "i386|x86_64|NATIVE")
1717
MESSAGE(FATAL_ERROR "ARCH should be one of i386, x86_64, NATIVE")
1818
ENDIF()
1919

20+
IF(NOT DEFINED WITH_CLANG_TIDY)
21+
SET(WITH_CLANG_TIDY "NO")
22+
ENDIF()
23+
IF(NOT WITH_CLANG_TIDY MATCHES "YES|NO")
24+
MESSAGE(FATAL_ERROR "WITH_CLANG_TIDY should be one of YES, NO")
25+
ENDIF()
26+
2027
INCLUDE(external/libseccomp.cmake)
2128
INCLUDE(external/libcap.cmake)
2229
INCLUDE(external/libtclap.cmake)
@@ -47,6 +54,11 @@ ADD_DEFINITIONS('-DBUILD_KERNEL_RELEASE="${BUILD_KERNEL_RELEASE}"')
4754

4855
ENABLE_TESTING()
4956

57+
IF(WITH_CLANG_TIDY STREQUAL "YES")
58+
CMAKE_MINIMUM_REQUIRED(VERSION 3.6.3)
59+
SET(CMAKE_CXX_CLANG_TIDY clang-tidy)
60+
ENDIF()
61+
5062
IF(NOT DEFINED WITH_DOCS)
5163
SET(WITH_DOCS "YES")
5264
ENDIF()

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,27 @@ running tests
8282
To run test suit use 'check' target, e.g in build directory run:
8383

8484
make check
85+
86+
notes for developers
87+
--------------------
88+
89+
To manually run clang-format on each file run:
90+
91+
make clang-format
92+
93+
inside build directory.
94+
95+
To manually run clang-tidy on each source file run:
96+
97+
make clang-tidy
98+
99+
or to use automatically fix errors:
100+
101+
make clang-tidy-fix
102+
103+
inside build directory.
104+
105+
There is possibility to enable running clang-tidy automatically during
106+
compilation on each file (can significantly slow down compilation):
107+
108+
-DWITH_CLANG_TIDY=YES

src/CMakeLists.txt

+26-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,29 @@ INSTALL(TARGETS sio2jail DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
1111
FILE(GLOB_RECURSE all_sources *.cc *.h *.hpp)
1212

1313
ADD_CUSTOM_TARGET(
14-
clang-format
15-
COMMAND
16-
clang-format -style=file -i ${all_sources}
17-
WORKING_DIRECTORY
18-
${CMAKE_CURRENT_SOURCE_DIR})
14+
clang-format
15+
COMMAND
16+
clang-format -style=file -i ${all_sources}
17+
WORKING_DIRECTORY
18+
${CMAKE_CURRENT_SOURCE_DIR})
19+
20+
SET(clang_tidy_cxx_flags -x;c++;-std=gnu++14)
21+
22+
GET_PROPERTY(include_directories DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
23+
FOREACH(include_directory IN LISTS include_directories)
24+
SET(clang_tidy_cxx_flags ${clang_tidy_cxx_flags};-I${include_directory})
25+
ENDFOREACH()
26+
27+
ADD_CUSTOM_TARGET(
28+
clang-tidy
29+
COMMAND
30+
clang-tidy ${sources} -- ${clang_tidy_cxx_flags}
31+
WORKING_DIRECTORY
32+
${CMAKE_CURRENT_SOURCE_DIR})
33+
34+
ADD_CUSTOM_TARGET(
35+
clang-tidy-fix
36+
COMMAND
37+
clang-tidy ${sources} -fix -fix-errors -- ${clang_tidy_cxx_flags}
38+
WORKING_DIRECTORY
39+
${CMAKE_CURRENT_SOURCE_DIR})

0 commit comments

Comments
 (0)