module Xcodeproj::Project::ProjectHelper

def self.build_phases_for_target_type(type)

Returns:
  • (Array) - The list of build phase class names for the target type.

Parameters:
  • type (Symbol) --
def self.build_phases_for_target_type(type)
  case type
  when :static_library, :dynamic_library
    %w(Headers Sources Frameworks)
  when :framework
    %w(Headers Sources Frameworks Resources)
  when :command_line_tool
    %w(Sources Frameworks)
  else
    %w(Sources Frameworks Resources)
  end.map { |phase| "PBX#{phase}BuildPhase" }
end

def self.common_build_settings(type, platform = nil, deployment_target = nil, target_product_type = nil, language = :objc)

Returns:
  • (Hash) - The common build settings

Parameters:
  • language (Symbol) --
  • target_product_type (Symbol) --
  • deployment_target (String) --
  • platform (Symbol) --
  • type (Symbol) --
def self.common_build_settings(type, platform = nil, deployment_target = nil, target_product_type = nil, language = :objc)
  target_product_type = (Constants::PRODUCT_TYPE_UTI.find { |_, v| v == target_product_type } || [target_product_type || :application])[0]
  common_settings = Constants::COMMON_BUILD_SETTINGS
  # Use intersecting settings for all key sets as base
  settings = deep_dup(common_settings[:all])
  # Match further common settings by key sets
  keys = [type, platform, target_product_type, language].compact
  key_combinations = (1..keys.length).flat_map { |n| keys.combination(n).to_a }
  key_combinations.each do |key_combination|
    settings.merge!(deep_dup(common_settings[key_combination] || {}))
  end
  if deployment_target
    case platform
    when :ios
      settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
      settings['CLANG_ENABLE_OBJC_WEAK'] = 'NO' if deployment_target < '5'
    when :osx
      settings['MACOSX_DEPLOYMENT_TARGET'] = deployment_target
      settings['CLANG_ENABLE_OBJC_WEAK'] = 'NO' if deployment_target < '10.7'
    when :tvos
      settings['TVOS_DEPLOYMENT_TARGET'] = deployment_target
    when :watchos
      settings['WATCHOS_DEPLOYMENT_TARGET'] = deployment_target
    end
  end
  settings
end

def self.configuration_list(project, platform = nil, deployment_target = nil, target_product_type = nil, language = nil)

Returns:
  • (XCConfigurationList) - the generated configuration list.

Parameters:
  • language (Symbol) --
  • target_product_type (Symbol) --
  • deployment_target (String) --
  • platform (Symbol) --
  • project (Project) --
def self.configuration_list(project, platform = nil, deployment_target = nil, target_product_type = nil, language = nil)
  cl = project.new(XCConfigurationList)
  cl.default_configuration_is_visible = '0'
  cl.default_configuration_name = 'Release'
  release_conf = project.new(XCBuildConfiguration)
  release_conf.name = 'Release'
  release_conf.build_settings = common_build_settings(:release, platform, deployment_target, target_product_type, language)
  debug_conf = project.new(XCBuildConfiguration)
  debug_conf.name = 'Debug'
  debug_conf.build_settings = common_build_settings(:debug, platform, deployment_target, target_product_type, language)
  cl.build_configurations << release_conf
  cl.build_configurations << debug_conf
  existing_configurations = cl.build_configurations.map(&:name)
  project.build_configurations.each do |configuration|
    next if existing_configurations.include?(configuration.name)
    new_config = project.new(XCBuildConfiguration)
    new_config.name = configuration.name
    new_config.build_settings = common_build_settings(configuration.type, platform, deployment_target, target_product_type, language)
    cl.build_configurations << new_config
  end
  cl
end

def self.deep_dup(object)

Returns:
  • (Object) - The deep copy of the object.

Parameters:
  • object (Object) --
def self.deep_dup(object)
  case object
  when Hash
    new_hash = {}
    object.each do |key, value|
      new_hash[key] = deep_dup(value)
    end
    new_hash
  when Array
    object.map { |value| deep_dup(value) }
  else
    object.dup
  end
end

def self.new_aggregate_target(project, name, platform, deployment_target)

Returns:
  • (PBXAggregateTarget) - the target.

Parameters:
  • deployment_target (String) --
  • platform (Symbol) --
  • name (String) --
  • project (Project) --
def self.new_aggregate_target(project, name, platform, deployment_target)
  target = project.new(PBXAggregateTarget)
  project.targets << target
  target.name = name
  target.build_configuration_list = configuration_list(project, platform, deployment_target)
  target
end

def self.new_legacy_target(project, name, build_tool_path = '/usr/bin/make', build_arguments_string = '$(ACTION)',

Returns:
  • (PBXLegacyTarget) - the target.

Parameters:
  • pass_build_settings_in_environment (String) --
  • build_working_directory (String) --
  • build_arguments_string (String) --
  • build_tool_path (String) --
  • name (String) --
  • project (Project) --
def self.new_legacy_target(project, name, build_tool_path = '/usr/bin/make', build_arguments_string = '$(ACTION)',
                           build_working_directory = nil, pass_build_settings_in_environment = '1')
  target = project.new(PBXLegacyTarget)
  project.targets << target
  target.name = name
  target.build_configuration_list = configuration_list(project)
  target.build_tool_path = build_tool_path
  target.build_arguments_string = build_arguments_string
  target.build_working_directory = build_working_directory
  target.pass_build_settings_in_environment = pass_build_settings_in_environment
  target
end

def self.new_resources_bundle(project, name, platform, product_group)

Returns:
  • (PBXNativeTarget) - the target.

Parameters:
  • product_group (PBXGroup) --
  • platform (Symbol) --
  • name (String) --
  • project (Project) --
def self.new_resources_bundle(project, name, platform, product_group)
  # Target
  target = project.new(PBXNativeTarget)
  project.targets << target
  target.name = name
  target.product_name = name
  target.product_type = Constants::PRODUCT_TYPE_UTI[:bundle]
  # Configuration List
  cl = project.new(XCConfigurationList)
  cl.default_configuration_is_visible = '0'
  cl.default_configuration_name = 'Release'
  release_conf = project.new(XCBuildConfiguration)
  release_conf.name = 'Release'
  release_conf.build_settings = common_build_settings(nil, platform, nil, target.product_type)
  debug_conf = project.new(XCBuildConfiguration)
  debug_conf.name = 'Debug'
  debug_conf.build_settings = common_build_settings(nil, platform, nil, target.product_type)
  cl.build_configurations << release_conf
  cl.build_configurations << debug_conf
  target.build_configuration_list = cl
  # Product
  product = product_group.new_bundle(name)
  target.product_reference = product
  # Build phases
  build_phases_for_target_type(:bundle).each { |phase| target.build_phases << project.new(phase) }
  target
end

def self.new_target(project, type, name, platform, deployment_target, product_group, language)

Returns:
  • (PBXNativeTarget) - the target.

Parameters:
  • language (Symbol) --
  • product_group (PBXGroup) --
  • deployment_target (String) --
  • platform (Symbol) --
  • name (String) --
  • type (Symbol) --
  • project (Project) --
def self.new_target(project, type, name, platform, deployment_target, product_group, language)
  # Target
  target = project.new(PBXNativeTarget)
  project.targets << target
  target.name = name
  target.product_name = name
  target.product_type = Constants::PRODUCT_TYPE_UTI[type]
  target.build_configuration_list = configuration_list(project, platform, deployment_target, type, language)
  # Product
  product = product_group.new_product_ref_for_target(name, type)
  target.product_reference = product
  # Build phases
  build_phases_for_target_type(type).each { |phase| target.build_phases << project.new(phase) }
  # Frameworks
  unless type == :static_library
    framework_name = (platform == :osx) ? 'Cocoa' : 'Foundation'
    target.add_system_framework(framework_name)
  end
  target
end