hi Manuel,
i would like to clarify the compilation database format once more. i think the page 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 is broken, because the SOMEDEF is not JSON+shell escaped, but only JSON.
what do you think?
regards,
Laszlo