1

My code

set(MY_VERSION "01.00")
set(MY_MINOR_VERSION "02")
set(ALL_VERSION ${MY_VERSION}-${MY_MINOR_VERSION})
add_definitions(-DVERSION="${ALL_VERSION}")

in the compile_commands.json I see:

-DVERSION=\\\"01.00-02\\\"

In my IDE the macro is not correctly parsed but it's a side effect actually. My question: am I doing the correct thing? I would expect something like:

-DVERSION=\"01.00-02\"
greywolf82
  • 21,813
  • 18
  • 54
  • 108
  • 1
    CMake has [known limitation](https://cmake.org/cmake/help/latest/prop_dir/COMPILE_DEFINITIONS.html) in what symbols can be used for compile definitions passed to the compiler via command line. In your case you may omit double quotes around the macro value but [stringify](https://stackoverflow.com/questions/2653214/stringification-of-a-macro-value) it in the C/C++ code. See also that [my answer](https://stackoverflow.com/a/61633185/3440745) to the related question. – Tsyvarev May 11 '20 at 17:53
  • [add_compile_definitions()](https://cmake.org/cmake/help/latest/command/add_compile_definitions.html#command:add_compile_definitions) - CMake will automatically escape the value correctly for the native build system (note that CMake language syntax may require escapes to specify some values). – vsh May 12 '20 at 13:56
  • It seems not supported in cmake 2.8.11 – greywolf82 May 12 '20 at 14:14

0 Answers0