Xcode预处理器依赖于环境变量 [英] Xcode preprocessor dependent on environment variable
问题描述
这是可能吗?如果我在预处理器定义表中设置了我要根据环境变量设置值的方法?
在项目目标的构建设置中,您可以将这样的内容添加到预处理器宏字段中:
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屋!