I am trying to pass in a compiler macro definition in Xcode that relies on a simple system shell command.
The first thing I tried was to add it to the specific file in Build Phases->Compile Sources like this:

to my surprise that didn't work, so I tried this:

This printed out the value correctly but the macro wasn't passed to the source file correctly. I figure this one didn't work because it creates a separate shell instance and thus the environment variable is not persisted to the compilation phase.
I tried doing a Google search and looking around StackOverflow as well, and the only promising thing I found was this, which didn't seem to have a working solution: XCode C/C++ Flags Bash Script
The code I wrote looks like this:
#define STRINGIFY(X) #X
#define TOSTRING(X) STRINGIFY(X)
#define AT __FILE__ ":" TOSTRING(__LINE__)
NSString* getBuildHash()
{
return [NSString stringWithCString:TOSTRING(GIT_COMMIT_HASH) encoding:NSASCIIStringEncoding];
}
Any help would be greatly appreciated :) Thanks!