summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/sharedvisitor/analyzer.cxx
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2019-10-06 15:01:07 +0200
committerLuboš Luňák <l.lunak@collabora.com>2019-10-07 21:57:13 +0200
commitad5cbcf6ba0afdc1d8d7405c2641cce8de4a360b (patch)
tree4efe68b6b293d0d7b5b7d3125e030595b5ecb8f8 /compilerplugins/clang/sharedvisitor/analyzer.cxx
parentb1c14c30ba99ede85e41934b565195b0cbc69703 (diff)
try to autodetect flags needed to build Clang plugins
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 <l.lunak@collabora.com>
Diffstat (limited to 'compilerplugins/clang/sharedvisitor/analyzer.cxx')
-rw-r--r--compilerplugins/clang/sharedvisitor/analyzer.cxx17
1 files changed, 8 insertions, 9 deletions
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 <cstddef>
#include <cstring>
@@ -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<FindNamedClassAction>(new FindNamedClassAction), contents, args, argv[ i ] ))
+ if( !tooling::runToolOnCodeWithArgs( std::unique_ptr<FindNamedClassAction>(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;