I am trying to use Cocoapods with some custom configurations in an iOS project.
I have 3 (Dev, Stage, Prod) and each of them has some custom GCC_PREPROCESSOR_DEFINITIONS
.
I have seen around people suggesting to us #include <path-to-pods.xcconfig>
, but this seems to the old way to do this.
I have seen Cocoapods 0.39
is automatically generating its config files based on my configurations and adding them to my targets automatically (and this is good).
This is also confirmed by this article who is talking about a "new way" to create Podfiles.
The problem is these files don't contain my configurations.
I was trying to use xcodeproj
and link_with
, but without success.
Does anyone know what is the correct way to deal with Cocoapods + custom xcconfig files?
Asked
Active
Viewed 6,359 times
11

pasine
- 11,311
- 10
- 49
- 81
-
Are you managing your own podspec or using a third party pod? – Fergal Rooney Apr 01 '16 at 16:39
-
1How is including the cocoapods xcconfig file from your own one the old way ? This seems the simplest solution to combine cocoa pods and custom config files. Did you ever find a better solution ? – deadbeef Jun 22 '16 at 13:28
1 Answers
6
The problem is that CocoaPods is based on xcconfig files and sets the actual variables. But these values cannot be used in any way when the full configuration is in xcconfig files like:
#include "../Pods/Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig"
GCC_PREPROCESSOR_DEFINITIONS = ...
In this case GCC_PREPROCESSOR_DEFINITIONS
overwrites the previous value.
Here is the way to solve it:
Update the Podfile to re-define the
GCC_PREPROCESSOR_DEFINITIONS
value withPODS_
prefix on post_install:post_install do |installer| work_dir = Dir.pwd Dir.glob("Pods/Target Support Files/Pods-Demo/*.xcconfig") do |xc_config_filename| full_path_name = "#{work_dir}/#{xc_config_filename}" xc_config = File.read(full_path_name) new_xc_config = new_xc_config.sub(/GCC_PREPROCESSOR_DEFINITIONS/, 'PODS_GCC_PREPROCESSOR_DEFINITIONS') File.open(full_path_name, 'w') { |file| file << new_xc_config } end end
Define xcconfig file in the next way:
#include "../Pods/Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig" GCC_PREPROCESSOR_DEFINITIONS = $(PODS_GCC_PREPROCESSOR_DEFINITIONS) ...
In this case GCC_PREPROCESSOR_DEFINITIONS
should contain PODS_GCC_PREPROCESSOR_DEFINITIONS
& you custom values.

sgl0v
- 1,357
- 11
- 13
-
It looks like the CocoaPods' `$(inherited)` is not picked up, so you actually have to use `GCC_PREPROCESSOR_DEFINITIONS = $(inherited) $(PODS_GCC_PREPROCESSOR_DEFINITIONS) ...`. – Iulian Onofrei Mar 12 '18 at 13:30