String literal macro value not correctly parsed from compile_commands.json
Consider a very simple project with a CMakeLists.txt file: cmake_minimum_required(VERSION 2.8) set(MY_VERSION 01.00) set(MY_MINOR_VERSION 1) set(MY_COMP ${MY_VERSION}-${MY_MINOR_VERSION}) cmake_policy(SET CMP0048 NEW) project(FOO CXX) add_executable(FOO main.cpp) add_definitions(-DFOO_VERSION="${MY_COMP}")
In the compile_commands.json I see with three slashes:
-DFOO_VERSION=\"01.00-1\"
In Eclipse I see
int main() {
std::cout << FOO_VERSION << std::endl; <------Bad character sequence encountered:
return 0;
}
So it seems when the macro is parsed in Eclipse an extra slash is taken into account. No problem executing the simple program.
Bad character sequence encountered
Where does that message come from? Is it an error message of the C++ compiler? Or is it displayed when you hover over the macro name?
Compiler Is not involved, it's a message you see while you hover with the mouse on the macro name. It's a parser/indexer Eclipse message.
I can see that the vaule of FOO_VERSIOn comes in as \"01.00-1\".
Should be "01.00-1".
So either the json parser is buggy or the generated compile_commands.json .
According to json.org only a single backslash is required to escape a quotation mark. Cmake generates three backslashes instead.
So please file a change request on the cmake site since other tools might suffer from that issue, too.