Cocoapods specify podspec xcconfig value for Debug only
Asked Answered
G

2

9

I am using cocoapods and want to specify a value in the pod's podspec using the xcconfig parameter that would be specific to Debug mode.

currently, using :

s.xcconfig = { "GCC_PREPROCESSOR_DEFINITIONS" => "MY_DEFINE=1" }

will set the value for both Debug and Release modes. Also tried using :

s.xcconfig = { "GCC_PREPROCESSOR_DEFINITIONS[config=Debug]" => "MY_DEFINE=1" }

but, altho this sets it in the pod's preprocessor macros, it doesn't seem to register during execution of the code, unlike when not using the [config=Debug] tag. Is there a way to limit it to Debug mode only?

Gapes answered 24/3, 2015 at 19:42 Comment(0)
T
5

You should create two separate podspec's each with different xcconfig and then use configurations to link to each of them:

pod 'my-podspec-debug', :configurations => ['Debug']
pod 'my-podspec-release', :configurations => ['Release']

See this old answer: https://mcmap.net/q/399841/-cocoapods-dependency-only-on-debug-release-build

Tightrope answered 22/7, 2015 at 2:3 Comment(1)
I have been looking for a solution to this for a while. Does this mean two separate pods will have to be registered in the spec repo? Or can you have two podspecs within a master spec?Baeda
I
3

You can achieve what you need by adding this in your podspec file:

 s.xcconfig = { "GCC_PREPROCESSOR_DEFINITIONS" => "$(GCC_PREPROCESSOR_DEFINITIONS_$(CONFIGURATION))",  
                "GCC_PREPROCESSOR_DEFINITIONS_Debug" => "MY_DEFINE=1" }

You can use Variable Substitution to assign a value to GCC_PREPROCESSOR_DEFINITIONS based on an other variable that its name your create based on the on the build configuration name(i.e. GCC_PREPROCESSOR_DEFINITIONS_$(CONFIGURATION)).

You can read more here https://pewpewthespells.com/blog/xcconfig_guide.html#VariableSubstitution

Imminence answered 3/8, 2018 at 6:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.