Issue
I have defined a couple of variables in my CMakeLists.txt like so:
# the subject of the commit
execute_process(
COMMAND git log -1 --format=%s
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_SUBJECT
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
add_definitions("-DGIT_COMMIT_SUBJECT=${GIT_COMMIT_SUBJECT}")
How could I access the GIT_COMMIT_SUBJECT
inside my classes?
Like so:
int main(int argc, char* argv[])
{
printf("GIT_COMMIT_SUBJECT = %s \n", GIT_COMMIT_SUBJECT);
}
Solution
You can define macros as strings when building, but you need to enclose the strings in double-quotes:
add_definitions("-DGIT_COMMIT_SUBJECT=\"${GIT_COMMIT_SUBJECT}\"")
Now any use of the macro GIT_COMMIT_SUBJECT
inside the code will be replace by a literal string.
Answered By - Some programmer dude