views:

10

answers:

1

I'm porting a project to be built with MacOS. We compile the current source revision number into our code which is used to track version compatibility between files and libraries at a code level.

-DSRC_REVISION=12345

In our existing build system 12345 is output (as text) by a script called by make and turned into a build option each time make is run.

How might I do the same in XCode.

+1  A: 

Can you just use a #define in a .h file instead of doing a -D on the compile?

Change your script to write a "version.h" consisting of:

#define SRC_REVISION 12345

and then include that file in each of your source files (or set it up as a prefix header so you don't have to explicitly include it in every file).

David Gelhar
That would work except that its not automatic: i) whoever is driving XCode needs to know there's a script to run, ii) they need to remember to run the script each time they update the source tree.
Resolved this by add "Add" > "New Build Phase" > "New Run Script Build Phase" to build version.h. Thanks.