[cfe-dev] compilation database question
Laszlo Nagy via cfe-dev
cfe-dev at lists.llvm.org
Mon Aug 17 04:58:10 PDT 2015
hi Manuel,
i would like to clarify the compilation database format once more. i think
the page <http://clang.llvm.org/docs/JSONCompilationDatabase.html> has a
wrong example which might be misleading. i'm developing an application
which tries to generate compilation database as output, so it would be nice
to clarify the documentation a bit.
here comes a simple test program.
void test(const char * const message) { }
int main() { test(MESSAGE); return 0; }
this can be compiled from shell with this command:
$ clang -E test.c -DMESSAGE=\"hi\ there\" | grep -v ^#
void test(const char * const message) { }
int main() { test("hi there"); return 0; }
to create a cmake file to compile this:
project(testing C)
cmake_minimum_required(VERSION 2.8)
add_definitions(-DMESSAGE="hi there")
add_executable(a.out test.c)
from the console log i can see another compilation command. to see it does
the same i checked manually...
$ clang -E -DMESSAGE="\"hi there\"" test.c | grep -v ^#
void test(const char * const message) { }
int main() { test("hi there"); return 0; }
the cmake generated compile_commands.json looks like this:
[{
"directory": "/tmp",
"command": "/usr/bin/cc -DMESSAGE=\"\\\"hi there\\\"\" -o
CMakeFiles/exec.dir/test.c.o -c /tmp/test.c",
"file": "/tmp/test.c"
}]
and it works with the clang tools (clang-check, clang-modernize,
clang-tidy) the other working version would be this
[{
"directory": "/tmp",
"command": "/usr/bin/cc -DMESSAGE=\\\"hi\\ there\\\" -o
CMakeFiles/a.out.dir/test.c.o -c /tmp/test.c",
"file": "/tmp/test.c"
}]
so, the example
<http://clang.llvm.org/docs/JSONCompilationDatabase.html#format> is broken,
because the SOMEDEF is not JSON+shell escaped, but only JSON.
what do you think?
regards,
Laszlo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150817/496dc851/attachment.html>
More information about the cfe-dev
mailing list