ios - Compilation flags using bash in Xcode -


i trying pass in compiler macro definition in xcode relies on simple system shell command.

the first thing tried add specific file in build phases->compile sources this:

enter image description here

to surprise didn't work, tried this:

enter image description here

this printed out value correctly macro wasn't passed source file correctly. figure 1 didn't work because creates separate shell instance , environment variable not persisted compilation phase.

i tried doing google search , looking around stackoverflow well, , promising thing found this, didn't seem have working solution: xcode c/c++ flags bash script

the code wrote looks this:

#define stringify(x) #x #define tostring(x) stringify(x) #define @ __file__ ":" tostring(__line__)  nsstring* getbuildhash() {     return [nsstring stringwithcstring:tostring(git_commit_hash) encoding:nsasciistringencoding]; } 

any appreciated :) thanks!

here's idea might help:

in shell script (the "run script" in build phases), instead of setting environment variable, write value file that's included in project. make easier can use build phase launch shell script work.

for example, can have header file contains define (or static variable): #define kobjcflags @"my_flags". script inject , replace value each time runs (use regex replace content of string).

since it's part of project can import , use wherever need. also, doesn't have header file - can plain text file or plist can read code.


Comments