在Xcode项目中,构建设置为不同的构建配置定义了不同的预处理器宏(例如:“Debug”和“Release”)
例如:
对于“调试”配置:
GCC_PREPROCESSOR_DEFinitioNS = DEBUG=1
对于“发布”配置:
GCC_PREPROCESSOR_DEFinitioNS = NDEBUG NS_BLOCK_ASSERTIONS
如何将这些设置映射到相应的POD规范?
例如:
spec.compiler_flags = '-DDEBUG=1'
和
spec.compiler_flags = '-DNDEBUG -DNS_BLOCK_ASSERTIONS'
不幸的是,官方文档通常更令人困惑和不清楚,而不是真正有用:
Build settings
Build settings
In this group are listed the attributes related to the configuration of the build environment that should be used to build the library.
If not defined in a subspec the attributes of this group inherit the value of the parent.
Examples:
spec.compiler_flags = ‘-DOS_OBJECT_USE_OBJC=0’,‘-Wno-format’
直观地说,我会做这样的事情:
configuration :Debug do spec.compiler_flags = '-DDEBUG=1' end configuration :Release do spec.compiler_flags = '-DNDEBUG -DNS_BLOCK_ASSERTIONS' end
然而,这是猜测.
解决方法
我太急于跳到这个解决方案,实际上,这个不起作用.
虽然Conditional Variable Assignment的xcconfig语法确实为架构和平台设置了有条件的值,但它在配置方面的工作方式不同.
由于这种差异,这个解决方案与CocoaPods的xcconfig继承机制并不相符.
很明显,也就是我,我不能成功地在podspec中使用条件变量赋值进行配置.
使用Conditional Variable Assignment的xcconfig语法,您可以实现:
s.pod_target_xcconfig = { 'GCC_PREPROCESSOR_DEFinitioNS[config=Debug]' => '-DDEBUG=1','GCC_PREPROCESSOR_DEFinitioNS[config=Release]' => '-DNDEBUG -DNS_BLOCK_ASSERTIONS' }
然而,如another SO question所述,有一个小的副作用,其中生成的构建设置将以某种方式在Pod.xcconfig中定义多次.