cmake4eclipse icon indicating copy to clipboard operation
cmake4eclipse copied to clipboard

String literal macro value not correctly parsed from compile_commands.json

Open baldapps opened this issue 5 years ago • 4 comments

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.

baldapps avatar May 11 '20 17:05 baldapps

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?

15knots avatar May 11 '20 17:05 15knots

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.

baldapps avatar May 11 '20 18:05 baldapps

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 .

15knots avatar May 11 '20 19:05 15knots

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.

15knots avatar May 12 '20 18:05 15knots