Re: environment variables during compile time
Re: environment variables during compile time
- Subject: Re: environment variables during compile time
- From: Ken Thomases <email@hidden>
- Date: Wed, 13 Jul 2011 07:30:34 -0500
On Jul 13, 2011, at 7:11 AM, Jankoen de Haan wrote:
> What would be the way to use environment variable during compile time in source code. I explicitly dont want to get the content of the vars during runtime but during compile time as if the vars are preprocessor constants.
>
> For example:
>
> int main(int argc, char *argv[])
> {
> NSLog( @"testcase %s", $PRODUCT_NAME );
> }
>
> Is something like this possible ?
I suspect you mean "build settings", not "environment variables". For example, PRODUCT_NAME is a build setting, not an environment variable. (For run-script build phases, the build setting can be exported as an environment variable, but that's irrelevant for compiling.)
You can get build settings into your code, somewhat in the manner you want. The two pieces of information you need are 1) there's a build setting for defining preprocessor macros, and 2) build settings can be defined in terms of other build settings.
So, you can add a macro definition via the Preprocessor Macros build setting, and have the value of that macro incorporate another build setting using syntax like $PRODUCT_NAME. In the code, you don't use the dollar sign -- macros are just substituted if they appear as tokens. If you want the macro to produce a C string, then it would need to include the quotes in its definition. Or, you could use a "stringify" macro.
Regards,
Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden