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

1

8

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.

Lewiss answered 1/3, 2014 at 12:17 Comment(1)
I am looking for the answer of this exact question, do you have any update?Sordino
W
6

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.

Whitver answered 10/12, 2015 at 11:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.