Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 3151167

Browse files
authored
Make tidy target use .clang-tidy config, enable clang-tidy on win32 (#218)
* Make tidy target use .clang-tidy config, enable clang-tidy on win32 * Check for clang-tidy-7, remove config value that is provided as arg to clang-tidy * Remove RawStringFormats config since it is not working and not used
1 parent ac78577 commit 3151167

File tree

3 files changed

+48
-75
lines changed

3 files changed

+48
-75
lines changed

.clang-format

+2-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ DerivePointerAlignment: false
5454
DisableFormat: false
5555
ExperimentalAutoDetectBinPacking: false
5656
FixNamespaceComments: true
57-
ForEachMacros:
57+
ForEachMacros:
5858
- foreach
5959
- Q_FOREACH
6060
- BOOST_FOREACH
6161
IncludeBlocks: Preserve
62-
IncludeCategories:
62+
IncludeCategories:
6363
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
6464
Priority: 2
6565
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
@@ -89,10 +89,6 @@ PenaltyBreakString: 1000
8989
PenaltyExcessCharacter: 1000000
9090
PenaltyReturnTypeOnItsOwnLine: 60
9191
PointerAlignment: Right
92-
RawStringFormats:
93-
- Delimiter: pb
94-
Language: TextProto
95-
BasedOnStyle: google
9692
ReflowComments: true
9793
SortIncludes: true
9894
SortUsingDeclarations: true

.clang-tidy

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
11
---
2-
Checks: "-*,\
3-
-llvm-header-guard,\
4-
-llvm-include-order,\
5-
-llvm-namespace-comment,\
6-
-readability-else-after-return,\
7-
-misc-macro-parentheses,\
8-
-clang-analyzer-alpha.core.CastToStruct,\
9-
-modernize-raw-string-literal,\
10-
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,\
11-
-cppcoreguidelines-pro-bounds-constant-array-index,\
12-
-cppcoreguidelines-pro-bounds-pointer-arithmetic,\
13-
-cppcoreguidelines-pro-type-member-init,\
14-
-cppcoreguidelines-pro-type-reinterpret-cast,\
15-
-cppcoreguidelines-pro-type-vararg,\
16-
-google-readability-namespace-comments,\
17-
-google-readability-braces-around-statements,-readability-braces-around-statements,\
18-
-google-readability-todo,\
19-
-google-runtime-int,\
20-
-google-runtime-references,\
21-
"
2+
Checks: '*,-llvm-header-guard,-llvm-include-order,-llvm-namespace-comment,-readability-else-after-return,-misc-macro-parentheses,-clang-analyzer-alpha.core.CastToStruct,-modernize-raw-string-literal,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-vararg,-google-readability-namespace-comments,-google-readability-braces-around-statements,-readability-braces-around-statements,-google-readability-todo,-google-runtime-int,-google-runtime-references,-fuchsia-default-arguments'
223
...

cmake/clang-dev-tools.cmake

+45-49
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,50 @@
11
if(WIN32)
2-
# CMAKE_EXPORT_COMPILE_COMMANDS is not working on Windows
3-
message(STATUS "clang-tidy is not supported on Windows")
2+
if (NOT CMAKE_GENERATOR STREQUAL "Ninja")
3+
set(NOT_SUPPORTED_MESSAGE "clang-tidy is only supported with Ninja generator on Microsoft Windows.")
4+
message(STATUS "${NOT_SUPPORTED_MESSAGE}")
5+
6+
# For the target not to fail:
7+
add_custom_target(tidy COMMAND echo "${NOT_SUPPORTED_MESSAGE}")
8+
return()
9+
else()
10+
find_package (Python COMPONENTS Interpreter)
11+
12+
if(NOT Python_Interpreter_FOUND)
13+
set(PYTHON_MISSING_MESSAGE "Python interpreter not found, it is required for run-clang-tidy.py")
14+
message(STATUS "${PYTHON_MISSING_MESSAGE}")
15+
add_custom_target(tidy COMMAND echo "${PYTHON_MISSING_MESSAGE}")
16+
return()
17+
endif()
18+
endif()
19+
endif()
20+
21+
find_program(CLANG_TIDY NAMES run-clang-tidy-7.py run-clang-tidy.py)
422

5-
# For the target not to fail:
6-
add_custom_target(tidy COMMAND echo "not supported on Windows")
23+
if(NOT CLANG_TIDY)
24+
message(STATUS "Did not find clang-tidy, target tidy is disabled.")
25+
message(STATUS "If clang-tidy is installed, make sure run-clang-tidy.py and clang-tidy is in PATH")
726

27+
# For the target not to fail:
28+
add_custom_target(tidy COMMAND echo "Clang-tidy is not installed")
829
else()
9-
find_program(CLANG_TIDY NAMES run-clang-tidy.py run-clang-tidy-6.0.py)
10-
if(NOT CLANG_TIDY)
11-
12-
message(STATUS "Did not find clang-tidy, target tidy is disabled.")
13-
message(STATUS "If clang-tidy is installed, make sure run-clang-tidy.py is in PATH")
14-
15-
# For the target not to fail:
16-
add_custom_target(tidy COMMAND echo "Clang-tidy is not installed")
17-
18-
else()
19-
message(STATUS "Found clang-tidy, use \"make tidy\" to run it.")
20-
21-
# This will create build/compile_commands.json
22-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
23-
24-
set(CLANG_TIDY_CHECKS "*")
25-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-llvm-header-guard")
26-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-llvm-include-order")
27-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-llvm-namespace-comment")
28-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-readability-else-after-return")
29-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-misc-macro-parentheses")
30-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-clang-analyzer-alpha.core.CastToStruct")
31-
# Modernize
32-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-modernize-raw-string-literal")
33-
# CPP Core Guidelines
34-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-bounds-array-to-pointer-decay")
35-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-bounds-constant-array-index")
36-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-bounds-pointer-arithmetic")
37-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-type-member-init") # as of https://llvm.org/bugs/show_bug.cgi?id=31039
38-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-type-reinterpret-cast")
39-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-cppcoreguidelines-pro-type-vararg")
40-
# Google
41-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-readability-namespace-comments")
42-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-readability-braces-around-statements,-readability-braces-around-statements")
43-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-readability-todo")
44-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-runtime-int")
45-
set(CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS},-google-runtime-references")
46-
set(CLANG_TIDY_CHECKS "-checks='${CLANG_TIDY_CHECKS}'")
47-
48-
add_custom_target(tidy
49-
COMMAND ${CLANG_TIDY} ${CLANG_TIDY_CHECKS}
50-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build/
51-
)
52-
endif()
30+
message(STATUS "Found clang-tidy, use \"cmake --build . --target tidy\" to run it.")
31+
32+
# This will create build/compile_commands.json
33+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
34+
35+
# Configuration of rules are picked up from .clang-tidy
36+
message(STATUS "Picking up clang-tidy rules from ${CMAKE_SOURCE_DIR}/.clang-tidy")
37+
set(CLANG_TIDY_ARGS "-header-filter=.*")
38+
39+
if (WIN32)
40+
add_custom_target(tidy
41+
COMMAND ${Python_EXECUTABLE} ${CLANG_TIDY} ${CLANG_TIDY_ARGS} .
42+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
43+
)
44+
else()
45+
add_custom_target(tidy
46+
COMMAND ${CLANG_TIDY} ${CLANG_TIDY_ARGS} .
47+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
48+
)
49+
endif()
5350
endif()
54-

0 commit comments

Comments
 (0)