From ad5cbcf6ba0afdc1d8d7405c2641cce8de4a360b Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Sun, 6 Oct 2019 15:01:07 +0200 Subject: try to autodetect flags needed to build Clang plugins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of having a lot of it hardcoded, which brings problems like: - Clang-to-be-10 has switched to -std=c++14, so our hardcoded c++11 makes the build fail - I cannot compile with my openSUSE-shipped clang, because it ships only libclang-cpp and not the other libClangSomething libs The possibility to explicitly set the necessary variables is still there. Change-Id: I58d401d4584fa064f1c1351a8a06ff4e29643063 Reviewed-on: https://gerrit.libreoffice.org/80300 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- compilerplugins/clang/sharedvisitor/analyzer.cxx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'compilerplugins/clang/sharedvisitor/analyzer.cxx') diff --git a/compilerplugins/clang/sharedvisitor/analyzer.cxx b/compilerplugins/clang/sharedvisitor/analyzer.cxx index 5b716f407fd4..4d8e2b2bb763 100644 --- a/compilerplugins/clang/sharedvisitor/analyzer.cxx +++ b/compilerplugins/clang/sharedvisitor/analyzer.cxx @@ -12,6 +12,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Tooling/Tooling.h" +#include "llvm/ADT/StringExtras.h" #include #include @@ -27,6 +28,7 @@ using namespace std; using namespace clang; +using namespace llvm; using namespace loplugin; @@ -241,16 +243,13 @@ int main(int argc, char** argv) } #define STRINGIFY2(a) #a #define STRINGIFY(a) STRINGIFY2(a) + SmallVector< StringRef, 20 > clangflags; + SplitString( STRINGIFY(CLANGFLAGS), clangflags ); + args.insert( args.end(), clangflags.begin(), clangflags.end()); args.insert( args.end(), { // These must match LO_CLANG_ANALYZER_PCH_CXXFLAGS in Makefile-clang.mk . - "-I" BUILDDIR "/config_host", // plugin sources use e.g. config_global.h - "-I" STRINGIFY(CLANGDIR) "/include", // clang's headers - "-I" STRINGIFY(CLANGSYSINCLUDE), // clang system headers - STDOPTION, - "-D__STDC_CONSTANT_MACROS", // Clang headers require these. - "-D__STDC_FORMAT_MACROS", - "-D__STDC_LIMIT_MACROS" + "-I" BUILDDIR "/config_host" // plugin sources use e.g. config_global.h #ifdef LO_CLANG_USE_ANALYZER_PCH , "-include-pch", // use PCH with Clang headers to speed up parsing/analysing @@ -264,9 +263,9 @@ int main(int argc, char** argv) continue; foundSomething = false; #if CLANG_VERSION >= 100000 - if( !clang::tooling::runToolOnCodeWithArgs( std::unique_ptr(new FindNamedClassAction), contents, args, argv[ i ] )) + if( !tooling::runToolOnCodeWithArgs( std::unique_ptr(new FindNamedClassAction), contents, args, argv[ i ] )) #else - if( !clang::tooling::runToolOnCodeWithArgs( new FindNamedClassAction, contents, args, argv[ i ] )) + if( !tooling::runToolOnCodeWithArgs( new FindNamedClassAction, contents, args, argv[ i ] )) #endif { cerr << "Failed to analyze: " << argv[ i ] << endl; -- cgit