Found a workaround, maybe not that elegant:
Since pod install
merges all compiler flags into one, I had to remove the GCC_PREPROCESSOR_DEFINITIONS
from the library's podspec
file. But without this definition, my library does not build.
In Xcode this can be fixed easily by adding the definition to each library's target. But when I use my library in an application, the Pods project is generated out of the Podspec which doesn't include the required flag.
The solution is to use the post_install
hook in the application's Podfile to manipulate the generated xcconfig of the Pods project.
post_install do |installer|
file_names = ['./Pods/Pods-ServerA.xcconfig',
'./Pods/Pods-ServerB.xcconfig']
# rename existing pre-processor definitions
file_names.each do |file_name|
text = File.read(file_name)
File.open(file_name, 'w') { |f| f.puts text.gsub(/GCC_PREPROCESSOR_DEFINITIONS/, "GCC_PREPROCESSOR_DEFINITIONS_SHARED")}
end
# merge existing and required definition for ServerA
File.open('./Pods/Pods-ServerA.xcconfig', 'a') { |f|
f.puts "\nGCC_PREPROCESSOR_DEFINITIONS=$(GCC_PREPROCESSOR_DEFINITIONS_SHARED) ServerA=1"
}
# merge existing and required definition for ServerB
File.open('./Pods/Pods-ServerB.xcconfig', 'b') { |f|
f.puts "\nGCC_PREPROCESSOR_DEFINITIONS=$(GCC_PREPROCESSOR_DEFINITIONS_SHARED) ServerB=1"
}
end
The code is a bit verbose since I'm not familiar with Ruby but it works. It should be easily possible to automate this renaming-append process as long as variable and library follow a naming scheme.