[cfe-dev] Standalone tools
Jacob Carlborg
doob at me.com
Sat Jan 31 12:37:05 PST 2015
On 2014-04-28 09:51, Olivier Goffart wrote:
> I have been doing that even before clang had a VFS.
>
> The idea is using cmake to put the content of the file in the binary
>
> Using this cmake script
> https://github.com/woboq/moc-ng/blob/master/src/CMakeLists.txt#L57
> and
> https://github.com/woboq/moc-ng/blob/master/src/embedded_includes.h.in
> This puts the file contents into the binary
>
> Then I added a "-I/builtins" to the command line, and used
> ToolInvocation::mapVirtualFile to expose the files:
> http://code.woboq.org/mocng/src/main.cpp.html#354
I had a look at this again and found really simple solution:
1. Include the contents of the header files in the executable
2. Create an array of CXUnsavedFile with the contents of the header
files. For the filename I use the name of the header file prefixed with
a base path that doesn't exist
3. When calling "clang_parseTranslationUnit" I pass the array from step
2 as the "unsaved_files" parameter and adding an additional argument to
the "command_line_args" parameter, "-I<path>", where "<path>" is the
base path from step 2
--
/Jacob Carlborg
More information about the cfe-dev
mailing list