include(CMakeDependentOption)
+option(CLANG_TIDY_ENABLE_STATIC_ANALYZER
+ "Include static analyzer checks in clang-tidy" ON)
+
add_subdirectory(clang-apply-replacements)
add_subdirectory(clang-reorder-fields)
add_subdirectory(modularize)
Support
)
+configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/clang-tidy-config.h.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/clang-tidy-config.h)
+include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
+
add_clang_library(clangTidy
ClangTidy.cpp
ClangTidyCheck.cpp
clangToolingCore
)
-if(CLANG_ENABLE_STATIC_ANALYZER)
+if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
clang_target_link_libraries(clangTidy
PRIVATE
clangStaticAnalyzerCore
add_subdirectory(llvmlibc)
add_subdirectory(misc)
add_subdirectory(modernize)
-if(CLANG_ENABLE_STATIC_ANALYZER)
+if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
add_subdirectory(mpi)
endif()
add_subdirectory(objc)
clangTidyReadabilityModule
clangTidyZirconModule
)
-if(CLANG_ENABLE_STATIC_ANALYZER)
+if(CLANG_TIDY_ENABLE_STATIC_ANALYZER)
list(APPEND ALL_CLANG_TIDY_CHECKS clangTidyMPIModule)
endif()
set(ALL_CLANG_TIDY_CHECKS ${ALL_CLANG_TIDY_CHECKS} PARENT_SCOPE)
#include "ClangTidyModuleRegistry.h"
#include "ClangTidyProfiling.h"
#include "ExpandModularHeadersPPCallbacks.h"
+#include "clang-tidy-config.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Config/config.h"
#include "clang/Format/Format.h"
#include "clang/Frontend/ASTConsumers.h"
#include "clang/Frontend/CompilerInstance.h"
#include <algorithm>
#include <utility>
-#if CLANG_ENABLE_STATIC_ANALYZER
+#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
#include "clang/Analysis/PathDiagnostic.h"
#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
-#endif // CLANG_ENABLE_STATIC_ANALYZER
+#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER
using namespace clang::ast_matchers;
using namespace clang::driver;
namespace tidy {
namespace {
-#if CLANG_ENABLE_STATIC_ANALYZER
+#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
static const char *AnalyzerCheckNamePrefix = "clang-analyzer-";
class AnalyzerDiagnosticConsumer : public ento::PathDiagnosticConsumer {
private:
ClangTidyContext &Context;
};
-#endif // CLANG_ENABLE_STATIC_ANALYZER
+#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER
class ErrorReporter {
public:
}
}
-#if CLANG_ENABLE_STATIC_ANALYZER
+#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
static void setStaticAnalyzerCheckerOpts(const ClangTidyOptions &Opts,
AnalyzerOptionsRef AnalyzerOptions) {
StringRef AnalyzerPrefix(AnalyzerCheckNamePrefix);
}
return List;
}
-#endif // CLANG_ENABLE_STATIC_ANALYZER
+#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER
std::unique_ptr<clang::ASTConsumer>
ClangTidyASTConsumerFactory::CreateASTConsumer(
if (!Checks.empty())
Consumers.push_back(Finder->newASTConsumer());
-#if CLANG_ENABLE_STATIC_ANALYZER
+#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
AnalyzerOptionsRef AnalyzerOptions = Compiler.getAnalyzerOpts();
AnalyzerOptions->CheckersAndPackages = getAnalyzerCheckersAndPackages(
Context, Context.canEnableAnalyzerAlphaCheckers());
new AnalyzerDiagnosticConsumer(Context));
Consumers.push_back(std::move(AnalysisConsumer));
}
-#endif // CLANG_ENABLE_STATIC_ANALYZER
+#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER
return std::make_unique<ClangTidyASTConsumer>(
std::move(Consumers), std::move(Profiling), std::move(Finder),
std::move(Checks));
CheckNames.emplace_back(CheckFactory.getKey());
}
-#if CLANG_ENABLE_STATIC_ANALYZER
+#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
for (const auto &AnalyzerCheck : getAnalyzerCheckersAndPackages(
Context, Context.canEnableAnalyzerAlphaCheckers()))
CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first);
-#endif // CLANG_ENABLE_STATIC_ANALYZER
+#endif // CLANG_TIDY_ENABLE_STATIC_ANALYZER
llvm::sort(CheckNames);
return CheckNames;
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYFORCELINKER_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYFORCELINKER_H
-#include "clang/Config/config.h"
+#include "clang-tidy-config.h"
#include "llvm/Support/Compiler.h"
namespace clang {
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
ModernizeModuleAnchorSource;
-#if CLANG_ENABLE_STATIC_ANALYZER && \
+#if CLANG_TIDY_ENABLE_STATIC_ANALYZER && \
!defined(CLANG_TIDY_DISABLE_STATIC_ANALYZER_CHECKS)
// This anchor is used to force the linker to link the MPIModule.
extern volatile int MPIModuleAnchorSource;
--- /dev/null
+/* This generated file is for internal use. Do not include it from headers. */
+
+#ifdef CLANG_TIDY_CONFIG_H
+#error clang-tidy-config.h can only be included once
+#else
+#define CLANG_TIDY_CONFIG_H
+
+#cmakedefine01 CLANG_TIDY_ENABLE_STATIC_ANALYZER
+
+#endif
* `clang-check`_ with the ``-ast-dump`` (and optionally ``-ast-dump-filter``)
provides a convenient way to dump AST of a C++ program.
-If CMake is configured with ``CLANG_ENABLE_STATIC_ANALYZER``,
+If CMake is configured with ``CLANG_TIDY_ENABLE_STATIC_ANALYZER=NO``,
:program:`clang-tidy` will not be built with support for the
``clang-analyzer-*`` checks or the ``mpi-*`` checks.
string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
llvm_canonicalize_cmake_booleans(
- CLANG_ENABLE_STATIC_ANALYZER
+ CLANG_TIDY_ENABLE_STATIC_ANALYZER
LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA
)
if platform.system() not in ['Windows']:
config.available_features.add('ansi-escape-sequences')
-if config.clang_staticanalyzer:
+if config.clang_tidy_staticanalyzer:
config.available_features.add('static-analyzer')
# Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if
config.clang_libs_dir = "@SHLIBDIR@"
config.python_executable = "@Python3_EXECUTABLE@"
config.target_triple = "@TARGET_TRIPLE@"
-config.clang_staticanalyzer = @CLANG_ENABLE_STATIC_ANALYZER@
+config.clang_tidy_staticanalyzer = @CLANG_TIDY_ENABLE_STATIC_ANALYZER@
config.libclang_include_clang_tools_extra = @LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA@
# Support substitution of the tools and libs dirs with user parameters. This is
"Build the Clang tools. If OFF, just generate build targets." ON)
option(CLANG_ENABLE_ARCMT "Build ARCMT." ON)
-option(CLANG_ENABLE_STATIC_ANALYZER "Build static analyzer." ON)
+option(CLANG_ENABLE_STATIC_ANALYZER
+ "Include static analyzer in clang binary." ON)
option(CLANG_ENABLE_PROTO_FUZZER "Build Clang protobuf fuzzer." OFF)
set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
+set(CLANG_TIDY_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
set(CLANG_VENDOR Android CACHE STRING "")
set(CMAKE_BUILD_TYPE RELEASE CACHE STRING "")
add_subdirectory(DirectoryWatcher)
add_subdirectory(Index)
add_subdirectory(IndexSerialization)
-if(CLANG_ENABLE_STATIC_ANALYZER)
- add_subdirectory(StaticAnalyzer)
-endif()
+add_subdirectory(StaticAnalyzer)
add_subdirectory(Format)
add_subdirectory(Testing)
import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
+import("//llvm/utils/gn/build/write_cmake_config.gni")
+import("enable.gni")
+
+config("clang-tidy-config_Config") {
+ visibility = [ ":clang-tidy-config" ]
+ include_dirs = [ "$target_gen_dir" ]
+}
+
+write_cmake_config("clang-tidy-config") {
+ input = "clang-tidy-config.h.cmake"
+ output = "$target_gen_dir/clang-tidy-config.h"
+ values = []
+
+ if (clang_tidy_enable_static_analyzer) {
+ values += [ "CLANG_TIDY_ENABLE_STATIC_ANALYZER=1" ]
+ } else {
+ values += [ "CLANG_TIDY_ENABLE_STATIC_ANALYZER=" ]
+ }
+
+ # Let targets depending on this find the generated file.
+ public_configs = [ ":clang-tidy-config_Config" ]
+}
static_library("clang-tidy") {
output_name = "clangTidy"
configs += [ "//llvm/utils/gn/build:clang_code" ]
deps = [
+ ":clang-tidy-config",
"//clang/include/clang/StaticAnalyzer/Checkers",
"//clang/lib/AST",
"//clang/lib/ASTMatchers",
"//llvm/lib/Support",
]
- if (clang_enable_static_analyzer) {
+ if (clang_tidy_enable_static_analyzer) {
deps += [
"//clang/lib/StaticAnalyzer/Core",
"//clang/lib/StaticAnalyzer/Frontend",
"//clang-tools-extra/clang-tidy/readability",
"//clang-tools-extra/clang-tidy/zircon",
]
- if (clang_enable_static_analyzer) {
+ if (clang_tidy_enable_static_analyzer) {
deps += [ "//clang-tools-extra/clang-tidy/mpi" ]
}
}
--- /dev/null
+declare_args() {
+ # Whether to include the static analyzer in the clang-tidy binary.
+ clang_tidy_enable_static_analyzer = true
+}
deps = [
"//clang-tools-extra/clang-tidy",
"//clang-tools-extra/clang-tidy:all-checks",
+ "//clang-tools-extra/clang-tidy:clang-tidy-config",
"//clang/lib/AST",
"//clang/lib/ASTMatchers",
"//clang/lib/Basic",
+import("//clang-tools-extra/clang-tidy/enable.gni")
import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
import("//clang/tools/libclang/include_clang_tools_extra.gni")
import("//llvm/triples.gni")
"Python3_EXECUTABLE=$python_path",
]
- if (clang_enable_static_analyzer) {
- extra_values += [ "CLANG_ENABLE_STATIC_ANALYZER=1" ]
+ if (clang_tidy_enable_static_analyzer) {
+ extra_values += [ "CLANG_TIDY_ENABLE_STATIC_ANALYZER=1" ]
} else {
- extra_values += [ "CLANG_ENABLE_STATIC_ANALYZER=0" ]
+ extra_values += [ "CLANG_TIDY_ENABLE_STATIC_ANALYZER=0" ]
}
if (libclang_include_clang_tools_extra) {