I am trying to replace a hard coded preprocessor
#define MY_FILE_PATH "/usr/local/myfile"
with add_definitions in cmake
add_definitions(-DMY_FILE_PATH=${MY_FILE_PATH})
and while calling cmake I use -DMY_FILE_PATH=/usr/tmp/myfile
but get all kind of errors e.g., expected primary expression before '/' token and tmp not find etc.
Is it possible to use add_definitions in my scenario or should I try configure_file.
Does add_definitions only supports integer values?
Your original code defined the macro to a string literal, but your CMake code is defining it to a sequence of tokens. In ohter words, you dropped the quotation marks.
Add them back when invoking CMake:
-DMY_FILE_PATH="/usr/tmp/myfile"
(You might have to escape them properly for your shell).