Xcode预处理器依赖于环境变量 [英] Xcode preprocessor dependent on environment variable

查看:226
本文介绍了Xcode预处理器依赖于环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个配置,我想通过一个环境变量动态地控制一个预处理器定义的值。



这是可能吗?如果我在预处理器定义表中设置了我要根据环境变量设置值的方法?

解决方案

在项目目标的构建设置中,您可以将这样的内容添加到预处理器宏字段中:

  DEV_USERNAME =$ {USER}

当然, USER 变量可以被任何可用于Xcode构建系统的环境变量所替代。要获取这些列表,您可以向目标添加运行脚本,并启用在构建日志中显示环境变量复选框。



然后可以使用 DEV_USERNAME 您的代码中的预处理器宏。如果你想使用它作为一个字符串,你可以stringify它:

  #define xstr(s)str s)
#define str(s)#s

xstr(DEV_USERNAME)

这将给你用双引号包围的用户名。


I have a configuration that I'd like to dynamically control a preprocessor defined value through an environment variable.

Is this possible? if it is how do I set in the preprocessor define table that I want to set the value based on the environment variable?

解决方案

In the "Build Settings" of a target of your project, you can add something like that to the "Preprocessor Macros" field:

DEV_USERNAME="${USER}"

Of course, the USER variable can be replaced by any environment variable available to Xcode build system. To get a list of those, you can add a run script to your target and enable the checkmark "Show environment variables in build log."

You can then use the DEV_USERNAME preprocessor macro in your code. And if you want to use it as a string, you can "stringify" it:

#define xstr(s) str(s)
#define str(s) #s

xstr(DEV_USERNAME)

This will give you the username surrounded by double quotes.

这篇关于Xcode预处理器依赖于环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆