Skip to content

Commit b2cecb8

Browse files
committed
add CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS cmake config
1 parent b43991f commit b2cecb8

File tree

8 files changed

+34
-14
lines changed

8 files changed

+34
-14
lines changed

clang-tools-extra/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ include(GNUInstallDirs)
55

66
option(CLANG_TIDY_ENABLE_STATIC_ANALYZER
77
"Include static analyzer checks in clang-tidy" ON)
8+
option(CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
9+
"Enable query-based custom checks in clang-tidy" ON)
810

911
if(CLANG_INCLUDE_TESTS)
1012
umbrella_lit_testsuite_begin(check-clang-tools)

clang-tools-extra/clang-tidy/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ set(ALL_CLANG_TIDY_CHECKS
8686
clangTidyCERTModule
8787
clangTidyConcurrencyModule
8888
clangTidyCppCoreGuidelinesModule
89-
clangTidyCustomModule
9089
clangTidyDarwinModule
9190
clangTidyFuchsiaModule
9291
clangTidyGoogleModule
@@ -103,6 +102,10 @@ set(ALL_CLANG_TIDY_CHECKS
103102
clangTidyReadabilityModule
104103
clangTidyZirconModule
105104
)
105+
106+
if(CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS)
107+
list(APPEND ALL_CLANG_TIDY_CHECKS clangTidyCustomModule)
108+
endif()
106109
if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
107110
list(APPEND ALL_CLANG_TIDY_CHECKS clangTidyMPIModule)
108111
endif()

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
350350
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS)
351351
: Context(Context), OverlayFS(std::move(OverlayFS)),
352352
CheckFactories(new ClangTidyCheckFactories) {
353+
#if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
353354
custom::registerCustomChecks(Context.getOptions(), *CheckFactories);
355+
#endif
354356
for (ClangTidyModuleRegistry::entry E : ClangTidyModuleRegistry::entries()) {
355357
std::unique_ptr<ClangTidyModule> Module = E.instantiate();
356358
Module->addCheckFactories(*CheckFactories);
@@ -421,7 +423,9 @@ ClangTidyASTConsumerFactory::createASTConsumer(
421423
.getCurrentWorkingDirectory();
422424
if (WorkingDir)
423425
Context.setCurrentBuildDirectory(WorkingDir.get());
426+
#if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
424427
custom::registerCustomChecks(Context.getOptions(), *CheckFactories);
428+
#endif
425429
std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
426430
CheckFactories->createChecksForLanguage(&Context);
427431

@@ -661,7 +665,9 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
661665
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions(), Opts),
662666
AllowEnablingAnalyzerAlphaCheckers);
663667
ClangTidyCheckFactories Factories;
668+
#if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
664669
custom::registerCustomChecks(Context.getOptions(), Factories);
670+
#endif
665671
for (const ClangTidyModuleRegistry::entry &Module :
666672
ClangTidyModuleRegistry::entries()) {
667673
Module.instantiate()->addCheckFactories(Factories);

clang-tools-extra/clang-tidy/ClangTidyForceLinker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ extern volatile int CppCoreGuidelinesModuleAnchorSource;
5454
static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
5555
CppCoreGuidelinesModuleAnchorSource;
5656

57+
#if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
5758
// This anchor is used to force the linker to link the CustomModule.
5859
extern volatile int CustomModuleAnchorSource;
5960
static int LLVM_ATTRIBUTE_UNUSED CustomModuleAnchorDestination =
6061
CustomModuleAnchorSource;
62+
#endif
6163

6264
// This anchor is used to force the linker to link the DarwinModule.
6365
extern volatile int DarwinModuleAnchorSource;

clang-tools-extra/clang-tidy/clang-tidy-config.h.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
#define CLANG_TIDY_CONFIG_H
77

88
#cmakedefine01 CLANG_TIDY_ENABLE_STATIC_ANALYZER
9+
#cmakedefine01 CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
910

1011
#endif
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
set(LLVM_LINK_COMPONENTS
2-
support
1+
if(CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS)
2+
set(LLVM_LINK_COMPONENTS
3+
support
34
)
45

5-
add_clang_library(clangTidyCustomModule STATIC
6-
CustomTidyModule.cpp
7-
QueryCheck.cpp
6+
add_clang_library(clangTidyCustomModule STATIC
7+
CustomTidyModule.cpp
8+
QueryCheck.cpp
89

9-
LINK_LIBS
10-
clangTidy
11-
clangTidyUtils
10+
LINK_LIBS
11+
clangTidy
12+
clangTidyUtils
1213

13-
DEPENDS
14-
ClangDriverOptions
14+
DEPENDS
15+
ClangDriverOptions
1516
)
1617

17-
clang_target_link_libraries(clangTidyCustomModule
18-
PRIVATE
19-
clangQuery
18+
clang_target_link_libraries(clangTidyCustomModule
19+
PRIVATE
20+
clangQuery
2021
)
22+
endif()

clang-tools-extra/docs/clang-tidy/Contributing.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ If CMake is configured with ``CLANG_TIDY_ENABLE_STATIC_ANALYZER=NO``,
3333
:program:`clang-tidy` will not be built with support for the
3434
``clang-analyzer-*`` checks or the ``mpi-*`` checks.
3535

36+
If CMake is configured with ``CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS=NO``,
37+
:program:`clang-tidy` will not be built with support for query based checks.
38+
3639

3740
.. _AST Matchers: https://clang.llvm.org/docs/LibASTMatchers.html
3841
.. _PPCallbacks: https://clang.llvm.org/doxygen/classclang_1_1PPCallbacks.html

clang-tools-extra/unittests/clang-tidy/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ target_link_libraries(ClangTidyTests
5454
PRIVATE
5555
clangTidy
5656
clangTidyAndroidModule
57+
clangTidyCustomModule
5758
clangTidyGoogleModule
5859
clangTidyMiscModule
5960
clangTidyLLVMModule

0 commit comments

Comments
 (0)