Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Associate POD Spec attributes to different Build Settings from their Xcode Configuration (e.g. Release, Debug)

I'm trying to create a POD spec for an existing library project.

In the Xcode project, the build settings define different Preprocessor macros for different Build Configurations (e.g.: "Debug" and "Release")

For example:

For the "Debug" Configuration:

GCC_PREPROCESSOR_DEFINITIONS = DEBUG=1 

For the "Release" Configuration:

GCC_PREPROCESSOR_DEFINITIONS = NDEBUG NS_BLOCK_ASSERTIONS

How do I map these settings to the corresponding POD spec?

For example:

spec.compiler_flags = '-DDEBUG=1'

and

spec.compiler_flags = '-DNDEBUG -DNS_BLOCK_ASSERTIONS'

Unfortunately, the official documentation in general is mostly more confusing and unclear, than really helpful:

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'

Intuitively, I would do something like this:

configuration :Debug do
    spec.compiler_flags = '-DDEBUG=1'
end

configuration :Release do
    spec.compiler_flags = '-DNDEBUG -DNS_BLOCK_ASSERTIONS'
end

However, that's guessing.

like image 935
CouchDeveloper Avatar asked Mar 01 '14 12:03

CouchDeveloper


People also ask

How do I change the build settings in Xcode?

Choose the project in the Project Navigator on the left. Select the Configurations target from the Targets section and click the Build Settings tab at the top. The Build Settings tab shows the build settings for the Configurations target. It's possible to expand this list with build settings that you define.


1 Answers

Update

I was too quick to jump to this solution, and actually, this one does not work.

While Conditional Variable Assignment of xcconfig syntax does set a value conditionally for architecture and platform, it works differently for configuration. Due to this difference, this solution doesn't get along with CocoaPods' xcconfig inheritance mechanics.

OP of this SO question apparently, and also I, could not successfuly use Conditional Variable Assignment for configuration in podspec.


Using Conditional Variable Assignment of xcconfig syntax, you can achieve it:

s.pod_target_xcconfig = {
    'GCC_PREPROCESSOR_DEFINITIONS[config=Debug]' => '-DDEBUG=1',
    'GCC_PREPROCESSOR_DEFINITIONS[config=Release]' => '-DNDEBUG -DNS_BLOCK_ASSERTIONS'
}

Yet, there is a small side effect, as mentioned in another SO question, where resulting build settings will be defined multiple times in Pod.xcconfig somehow.

like image 84
Shigerello Avatar answered Sep 27 '22 19:09

Shigerello