Skip to content

Commit f48a349

Browse files
committed
style(clang-tidy): modularize clang-tidy config
Read blogs and played around with [CMAKE_CXX_CLANG_TIDY](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_CLANG_TIDY.html). Also read source code to understand the clang-tidy config of chromium, llvm and other projects. We can provide complete context including headers to the clang-tidy tool for static analyzer by running it while building the code. This also makes static analysis first-class citizen of the project, reporting errors before making commits. For example, `misc-internal-linkage` check was reporting mostly false positives prior to this. With this, it also considered the headers, where methods/functions were declared constant. Refer #1752 And we should also incrementally add the checks. Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
1 parent 890fbbc commit f48a349

File tree

5 files changed

+20
-159
lines changed

5 files changed

+20
-159
lines changed

.clang-tidy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
# See https://clang.llvm.org/extra/clang-tidy/index.html
3+
# First disable all default checks (with -*)
4+
Checks: '-*'

CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ option(SOURCEMETA_CORE_CONTRIB_GOOGLEBENCHMARK "Build the GoogleBenchmark librar
2222

2323
include(Sourcemeta)
2424

25+
if(PROJECT_IS_TOP_LEVEL)
26+
sourcemeta_target_clang_format(SOURCES
27+
src/*.h src/*.cc
28+
benchmark/*.h benchmark/*.cc
29+
test/*.h test/*.cc)
30+
sourcemeta_find_clang_tidy() # Locates CLANG_TIDY program
31+
endif()
32+
33+
# Add clang-tidy to the targets. Clang-tidy uses the .clang-tidy file for configuration.
34+
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_BIN}" "--allow-no-checks")
2535
# Don't force downstream consumers on it
2636
if(PROJECT_IS_TOP_LEVEL)
2737
sourcemeta_enable_simd()
@@ -91,13 +101,6 @@ if(SOURCEMETA_CORE_DOCS)
91101
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/website")
92102
endif()
93103

94-
if(PROJECT_IS_TOP_LEVEL)
95-
sourcemeta_target_clang_format(SOURCES
96-
src/*.h src/*.cc
97-
benchmark/*.h benchmark/*.cc
98-
test/*.h test/*.cc)
99-
sourcemeta_target_clang_tidy(SOURCES src/*.cc)
100-
endif()
101104

102105
# Testing
103106

cmake/common/targets/clang-tidy.cmake

Lines changed: 0 additions & 130 deletions
This file was deleted.

cmake/common/targets/clang-tidy.config

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/.clang-tidy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
# See https://clang.llvm.org/extra/clang-tidy/index.html
3+
Checks: 'concurrency-*'
4+
InheritParentConfig: true
5+
WarningsAsErrors: '*'
6+
FormatStyle: none

0 commit comments

Comments
 (0)