xcode 通过 xcodebuild 传递编译器标志
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18106510/
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
Passing compiler flags through xcodebuild
提问by aspyct
I'm currently using xcodebuild
to automate testing for iOS.
我目前正在使用xcodebuild
自动测试 iOS。
Right now, I'm stuck on trying to pass compiler flags through Xcode directly to the compiler. These flags are: -fprofile-arcs -ftest-coverage
.
现在,我一直在尝试通过 Xcode 将编译器标志直接传递给编译器。这些标志是:-fprofile-arcs -ftest-coverage
.
I don't have the liberty of modifying the xcodeproj, that's why I want to inject these flags via the xcodebuild command.
我没有修改 xcodeproj 的自由,这就是我想通过 xcodebuild 命令注入这些标志的原因。
It would be something like:
它会是这样的:
xcodebuild -project path/to/my.xcodeproj -scheme MyApp -fprofile-arcs -ftest-coverage
Is that feasible? How?
那可行吗?如何?
回答by aspyct
Apparently most compiler flags can be expressed as constants, and these can be passed to the compiler via xcodebuild easily.
显然,大多数编译器标志都可以表示为常量,这些可以通过 xcodebuild 轻松传递给编译器。
To get them, simply select the option in the xcode build settings view, and hit command-C (copy). In my case, they were GCC_GENERATE_TEST_COVERAGE_FILES
and GCC_INSTRUMENT_PROGRAM_FLOW_ARCS
.
要获得它们,只需在 xcode 构建设置视图中选择该选项,然后点击 command-C(复制)。就我而言,它们是GCC_GENERATE_TEST_COVERAGE_FILES
和GCC_INSTRUMENT_PROGRAM_FLOW_ARCS
。
My command roughly looks like this:
我的命令大致如下:
xcodebuild GCC_GENERATE_TEST_COVERAGE_FILES=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES ...
回答by Jason Moore
To set compiler flags with xcodebuild
, you need to put them in the OTHERCFLAGS option.
要使用 设置编译器标志xcodebuild
,您需要将它们放在 OTHERCFLAGS 选项中。
For example:
例如:
xcodebuild -project path/to/my.xcodeproj -scheme MyApp \
OTHERCFLAGS="-fprofile-arcs -ftest-coverage"
回答by Bryan Musial
Yes, all of the compiler setting actually boils down to string key-value pairs. I answered a very similar question about setting preprocessor macros from the command line that is just as applicable to these settings you would like to set:
是的,所有编译器设置实际上都归结为字符串键值对。我回答了一个关于从命令行设置预处理器宏的非常相似的问题,该问题同样适用于您要设置的这些设置:
Setting a #define from the command line in xcode 4.6
I would also like to call attention to the use of ${inherited} -- using this values allows you to use the Xcode project-specified values AND append your own. Documentation for each of the build settings including those that you located via copy-paste can be found here:
我还想提请注意 ${inherited} 的使用——使用此值允许您使用 Xcode 项目指定的值并附加您自己的值。可以在此处找到每个构建设置的文档,包括您通过复制粘贴找到的那些:
Glad you were able to get it to work -- now you can really make xcodebuild do even more for you without requiring changes of the target Xcode project!
很高兴你能够让它工作——现在你真的可以让 xcodebuild 为你做更多的事情,而无需更改目标 Xcode 项目!