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?
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 with PODS_
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With