[PATCH] D55174: Fix bug 8220 - llvm-config: Only keep flags starting by -I, -D & -stdfor --cflags, --cxxflags & --ldflags

Sylvestre Ledru via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 2 06:41:26 PST 2018


sylvestre.ledru created this revision.
sylvestre.ledru added a reviewer: tstellar.
Herald added a subscriber: llvm-commits.

This will change the behavior of for --cflags, --cxxflags & --ldflags
Currently, a lot of projects are filtering out the results.
It has been a pain for linux distro using llvm


Repository:
  rL LLVM

https://reviews.llvm.org/D55174

Files:
  tools/llvm-config/llvm-config.cpp


Index: tools/llvm-config/llvm-config.cpp
===================================================================
--- tools/llvm-config/llvm-config.cpp
+++ tools/llvm-config/llvm-config.cpp
@@ -257,6 +257,26 @@
                                   GetComponentNames, nullptr, nullptr, DirSep);
 }
 
+/// Remove all arguments beside -I, -D & -std from the args flags
+/// This is mostly done to get rid of the warnings as they should
+/// be managed by the downstream projects
+///
+/// \param flag the raw list of flags
+static std::string ignoreArguments(const char *flag) {
+  StringRef FlagStr(flag);
+  SmallVector<StringRef, 4> Opts;
+  FlagStr.trim().split(Opts, ' ');
+  std::string args = "";
+  for (StringRef Opt : Opts) {
+      if (Opt.startswith("-I") || Opt.startswith("-D") || Opt.startswith("-std")) {
+          args += Opt;
+          args += " ";
+      }
+  }
+  return args;
+}
+
+
 int main(int argc, char **argv) {
   std::vector<StringRef> Components;
   bool PrintLibs = false, PrintLibNames = false, PrintLibFiles = false;
@@ -487,11 +507,11 @@
       } else if (Arg == "--cmakedir") {
         OS << ActiveCMakeDir << '\n';
       } else if (Arg == "--cppflags") {
-        OS << ActiveIncludeOption << ' ' << LLVM_CPPFLAGS << '\n';
+          OS << ActiveIncludeOption << ' ' << ignoreArguments(LLVM_CPPFLAGS) << '\n';
       } else if (Arg == "--cflags") {
-        OS << ActiveIncludeOption << ' ' << LLVM_CFLAGS << '\n';
+        OS << ActiveIncludeOption << ' ' << ignoreArguments(LLVM_CFLAGS) << '\n';
       } else if (Arg == "--cxxflags") {
-        OS << ActiveIncludeOption << ' ' << LLVM_CXXFLAGS << '\n';
+          OS << ActiveIncludeOption << ' ' << ignoreArguments(LLVM_CXXFLAGS) << '\n';
       } else if (Arg == "--ldflags") {
         OS << ((HostTriple.isWindowsMSVCEnvironment()) ? "-LIBPATH:" : "-L")
            << ActiveLibDir << ' ' << LLVM_LDFLAGS << '\n';


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55174.176281.patch
Type: text/x-patch
Size: 1902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181202/d7af1dc1/attachment.bin>


More information about the llvm-commits mailing list