source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

install! 'cocoapods', :deterministic_uuids => false

# Location of gRPC's repo root relative to this file.
GRPC_LOCAL_SRC = '../../../../..'

# Install the dependencies in the main target plus all test targets.
target 'CFStreamTests' do
  pod 'gRPC-Core/CFStream-Implementation', :path => GRPC_LOCAL_SRC
  pod 'BoringSSL-GRPC', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c", :inhibit_warnings => true
end

pre_install do |installer|
  # This is the gRPC-Core podspec object, as initialized by its podspec file.
  grpc_core_spec = installer.pod_targets.find{|t| t.name == 'gRPC-Core'}.root_spec

  # Copied from gRPC-Core.podspec, except for the adjusted src_root:
  src_root = "$(PODS_ROOT)/../#{GRPC_LOCAL_SRC}"
  grpc_core_spec.pod_target_xcconfig = {
    'GRPC_SRC_ROOT' => src_root,
    'HEADER_SEARCH_PATHS' => '"$(inherited)" "$(GRPC_SRC_ROOT)/include"',
    'USER_HEADER_SEARCH_PATHS' => '"$(GRPC_SRC_ROOT)"',
    # If we don't set these two settings, `include/grpc/support/time.h` and
    # `src/core/lib/gpr/string.h` shadow the system `<time.h>` and `<string.h>`, breaking the
    # build.
    'USE_HEADERMAP' => 'NO',
    'ALWAYS_SEARCH_USER_PATHS' => 'NO',
  }
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['GCC_TREAT_WARNINGS_AS_ERRORS'] = 'YES'
    end

    # CocoaPods creates duplicated library targets of gRPC-Core when the test targets include
    # non-default subspecs of gRPC-Core. All of these library targets start with prefix 'gRPC-Core'
    # and require the same error suppresion.
    if target.name.start_with?('gRPC-Core')
      target.build_configurations.each do |config|
        # TODO(zyc): Remove this setting after the issue is resolved
        # GPR_UNREACHABLE_CODE causes "Control may reach end of non-void
        # function" warning
        config.build_settings['GCC_WARN_ABOUT_RETURN_TYPE'] = 'NO'
      end
    end
  end
end
