views:

96

answers:

2

I have a plist that is processed with a precompiled header file and in it there is the "variable" VERSION_STRING used a few times in such fields as CFBundleGetInfoString, ie the value for the key CFBundleGetInfoString is: MyProduct VERSION_STRING Copyright © 2009 MyCorp

In MyHeader.h (which is the set as the Info.plist prefix header I would like to be able to build VERSION_STRING into the form MAJOR.MINOR.PATCH.BUILD where I have

#define MAJOR 1
#define MINOR 0
#define PATCH 0
#define BUILD 23

For some reason I seem to be incapable of doing this. I might just be having one of those moments

A: 

Take your plist file and rename it with an extra extension (perhaps a P?). Add #include "MyHeader.h" to the beginning of the file, and preprocess it in your build with the C preprocessor (usually cpp). You may need to filter out extra # lines, but I don't see why it wouldn't work.

By default, cpp should output to stdout, so adding a command like this might work fine:

cpp myplist.plist.P | grep -v '^#' > myplist.plist
greyfade
As part of the build process you can tell Xcode to automatically include a header file when preprocessing the Info.plist file, which is what I'm doing. The problem I've having is with properly assembling the VERSION_STRING from its components.
g-Off
I have to confess I have very little experience with XCode. Forgive my ignorance of its features. Could you demonstrate how you have tried to build your `VERSION_STRING`?
greyfade
No worries. The current string that exists is:#define VERSION_NUM 1.0.0.BUILD_NUMWhere BUILD_NUM is defined as a number. This currently results in just 1.0.0.BUILD_NUM and BUILD_NUM is *not* replaced with the build number.I would also like to replace the 1.0.0 part with the major/minor/patch defines.
g-Off
How about this, then: `#define VERSION_NUM 1.0.0.##BUILD_NUM`
greyfade
A: 

Turns out there is actually an Apple Tech Note on this and a solution to the very problem I was having. So, for anyone that may come across this and is having the same problems I was check out Technical Note TN2175: Preprocessing Info.plist files in Xcode Using the C Preprocessor

g-Off