I'm working with C++ in Visual Studio 2015 and using Git as source control. I'm writing a multi-platform application and would like my application to include the Git branch and the commit it was built from.
On platforms other than Visual Studio I put the following lines in my makefile:
GIT_CUR_COMMIT := $(shell git rev-parse --verify HEAD)
GIT_CUR_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
DEPS += -DGIT_COMMIT=\"$(GIT_CUR_COMMIT)\" -DGIT_BRANCH=\"$(GIT_CUR_BRANCH)\"
And then in my application I have code to read these preprocessor variables and expose them programmatically:
std::string getGitCommit()
{
#ifdef GIT_COMMIT
return GIT_COMMIT;
#endif
return "unavailable";
}
std::string getGitBranch()
{
#ifdef GIT_BRANCH
return GIT_BRANCH;
#endif
return "unavailable";
}
But in Visual Studio there are no makefiles. How can I define these two variables (GIT_CUR_COMMIT
and GIT_CUR_BRANCH
) at compile time and achieve the same behavior?