0

The question is: the CocoaPods generates the xcconfig file for my project and I want to include my xcconfig file as a dependency into it. Am I able to do in for example in post_install hook? I've only found that the XCBuildConfiguration has build_settings hash, but as far as I understood I can add or change only keys and not include statements with that hash.

1 Answers1

0

Following the instructions from this answer I was able to update xcconfig and I use this code to include my xcconfig file into pod's generated:

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        next unless target.name.include?("Pods-CNISDK")
        puts "Updating #{target.name}"
        target.build_configurations.each do |config|
          xcconfig_path = config.base_configuration_reference.real_path
          # read from xcconfig to build_settings dictionary
          build_settings = Hash[*File.read(xcconfig_path).lines.map{|x| x.split(/\s*=\s*/, 2)}.flatten]
          # write build_settings dictionary to xcconfig
          File.open(xcconfig_path, "w") do |file|
            file.puts "#include \"../configurations/Warnings.xcconfig\"\n"
            build_settings.each do |key,value|
              file.puts "#{key} = #{value}"
            end
          end
        end
      end
    end
Community
  • 1
  • 1