Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoapods specify podspec xcconfig value for Debug only

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?

like image 500
Godfather Avatar asked Mar 24 '15 19:03

Godfather


2 Answers

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://stackoverflow.com/a/26074997/1509221

like image 191
brunobowden Avatar answered Nov 06 '22 12:11

brunobowden


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

like image 45
Christos Koninis Avatar answered Nov 06 '22 13:11

Christos Koninis