Generating a VERSION_STRING from major/minor/patch/build defines for use in a plist
-
18-09-2019 - |
Question
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
Solution
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
OTHER TIPS
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