[cfe-dev] Parse custom options using CommonOptionsParser
Manasij Mukherjee
manasij7479 at gmail.com
Wed Jan 21 03:17:15 PST 2015
Hi
Your code seems to work fine, what is your clang version?
Can you elaborate the problem ?
> Also the category needs to be applied
on the new option, otherwise it's not shown in the help.
That seems to be by design.
Examples of invocation:
$ ./bin/testtool ~/b.cpp -abc=1 -- -std=c++11
1
$ ./bin/testtool --help
<snip>
My tool options:
-abc -
<snip>
On Wed, Jan 21, 2015 at 3:41 PM, Christoph Viebig (lists) <
lists at christoph-viebig.de> wrote:
> Hello list,
>
> I am currently working on a libTooling project and need to read custom
> command line options for this.
>
> Unfortunately I was not able to get the following sample code from
> CommonOptionsParser [1] to run. Can you please give me an advice what
> might be the problem here?
>
> To make the sample code compiling I had to add the import of Tooling.h
> and modify the Tool.run() call to retrieve the Front-end action via
> .get() from the factory first. Also the category needs to be applied
> on the new option, otherwise it's not shown in the help.
>
> #include "clang/Frontend/FrontendActions.h"
> #include "clang/Tooling/CommonOptionsParser.h"
> #include "clang/Tooling/Tooling.h"
> #include "llvm/Support/CommandLine.h"
>
> using namespace clang::tooling;
> using namespace llvm;
>
> static cl::OptionCategory MyToolCategory("My tool options");
> static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
> static cl::extrahelp MoreHelp("\nMore help text...");
> static cl::opt<bool> YourOwnOption("abc", cl::cat(MyToolCategory));
>
> int main(int argc, const char **argv) {
> CommonOptionsParser OptionsParser(argc, argv, MyToolCategory);
> ClangTool Tool(OptionsParser.getCompilations(),
> OptionsParser.getSourcePathList());
> llvm::outs() << YourOwnOption.getValue();
> return
> Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>().get());
> }
>
> Thank you very much in advance!
>
> Best regards
> Christoph
>
> [1]
>
> http://clang.llvm.org/doxygen/classclang_1_1tooling_1_1CommonOptionsParser.html
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150121/395c45a5/attachment.html>
More information about the cfe-dev
mailing list