I want to add
-DGIT_COMMIT_INFO="`git log -1 --format='"%ad %h"' --date=format:'%Y-%m-%d %H:%M:%S'`"
to the Makefile generated by CMake.
I tried some of the answers to this questions, but for some reason none seemed to work. So I thought I would go for a more basic approach and tried to use add_compile_definitions
. However, regardless of how I use it, backslashes and extra quotation marks get added in the string written in CMakeFiles/my_project.dir/flags.make
.
When I write add_compile_definitions(GIT_COMMIT_INFO="`git log -1 --format='"%ad %h"' --date=format:'%Y-%m-%d %H:%M:%S'`")
or add_compile_definitions(GIT_COMMIT_INFO="`git log -1 --format='"%ad %h"' --date=format:'%Y-%m-%d %H:%M:%S'`")
, I get -DGIT_COMMIT_INFO=""`git log -1 --format='"%ad %h"' --date=format:'%Y-%m-%d %H:%M:%S'`""
.
I tried various ways to escape the special characters, but then I get outputs that are even further from what I want.
How can I tell CMake to not escape the backticks and not add extra double quotes?