Xcode:如何使用多个 xcconfig 文件设置调试环境?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1402641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:49:39  来源:igfitidea点击:

Xcode: How to set debug environment with multiple xcconfig files?

xcodexcconfig

提问by Martin Cote

I'm using Xcode 3.2 with xcconfigfiles. The files are organized by target. For example, I have a debug.xcconfigfile and a release.xcconfigone. Both uses common settings, so I added a shared.xcconfigfile which is included by both.

我正在将 Xcode 3.2 与xcconfig文件一起使用。文件按目标组织。例如,我有一个debug.xcconfig文件和release.xcconfig一个。两者都使用通用设置,所以我添加了一个shared.xcconfig包含在两者中的文件。

The shared.xcconfigfile looks like this:

shared.xcconfig文件如下所示:

GCC_C_LANGUAGE_STANDARD = c99
GCC_WARN_ABOUT_RETURN_TYPE = YES
GCC_WARN_UNUSED_VARIABLE = YES
GCC_PREPROCESSOR_DEFINITIONS = SOME_COMMON_DEFINITIONS

The debug.xcconfigfile looks like this:

debug.xcconfig文件如下所示:

#include "Shared.xcconfig"
GCC_OPTIMIZATION_LEVEL = 0

Now, I would like to add a DEBUGpreprocessor definition in the debug.xcconfigfile. As shown in this question, the following method is supposed to work:

现在,我想DEBUGdebug.xcconfig文件中添加一个预处理器定义。如this question所示,以下方法应该有效:

GCC_PREPROCESSOR_DEFINITIONS = "$(GCC_PREPROCESSOR_DEFINITIONS) DEBUG"

This doesn't work in Xcode 3.2. The Xcode documentation also explicitly mention that modifying variables is not possible, you can only overwrite them.

这在 Xcode 3.2 中不起作用。Xcode 文档也明确提到修改变量是不可能的,你只能覆盖它们。

How would you guys solve this problem?

大家会怎么解决这个问题?

回答by fbrereto

The way we have tackled this in the past is to have each layer compose a subset of the definitions, then bring them all together at the leaf-level xcconfig.

我们过去解决这个问题的方法是让每一层组成定义的一个子集,然后在叶级 xcconfig 将它们组合在一起。

In shared.xcconfig:

shared.xcconfig

GCC_PREPROCESSOR_DEFINITIONS_SHARED = qFoo qBar qBaz

In debug.xcconfig:

debug.xcconfig

GCC_PREPROCESSOR_DEFINITIONS_DEBUG = qDebug
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_SHARED) $(GCC_PREPROCESSOR_DEFINITIONS_DEBUG)

(The advantage to making the subset variables verbose is that they are lexicographically similar to the value they are used to compose, making them easier to find in the config file.)

(使子集变量变得冗长的优点是它们在字典上与它们用来组合的值相似,使它们更容易在配置文件中找到。)

回答by jankoen

You could also use the following format in a .xcconfig file. (works in xcode 4, not tested in xcode 3 ). Its only an example, seems to works for all settings.

您还可以在 .xcconfig 文件中使用以下格式。(适用于 xcode 4,未在 xcode 3 中测试)。它只是一个例子,似乎适用于所有设置。

ARCHS=i386 x86_64
ARCHS[config=Debug]=i386
ARCHS[config=Release]=i386 x86_64

回答by Laxman Battini

Following should work :

以下应该工作:

xcodebuild GCC_PREPROCESSOR_DEFINITIONS='$(value) BAR=1'

回答by Reid Ellis

How about using $(inherited)?

使用 $(inherited) 怎么样?

GCC_PREPROCESSOR_DEFINITIONS = $(inherited) DEBUG

GCC_PREPROCESSOR_DEFINITIONS = $(继承)调试