class Xcake::Target

This class is used to describe a target for a Xcode project; This forms part of the DSL and is usually stored in files named ‘Cakefile`.

Attributes

build_phases[RW]

@return [Array<BuildPhase>] the list

of build phases for the project.
build_rules[RW]

@return [Array<BuildRule>] the list

of build rules for the project.
deployment_target[RW]

@return [String] the minimum deployment version

for the target's platform.
exclude_files[RW]

@return [Array or String] files to exclude for the target.

Supports regular expressions

@example

spec.exclude_files = ["Classes/**/unused.{h,m}"]
include_files[W]

@return [Array or String] files to include for the target.

Supports regular expressions,
Defaults to: ["./<Target Name>/*\*/\*.*"]

@note Xcake defaults to including files in the folder with the same name as

the targt

@example

spec.include_files = "Classes/**/*.{h,m}"
language[RW]

@return [String] the language for the target.

Can be `:objc`, `:swift`.
linked_targets[RW]

@return [Array<Target>] targets to link to, use this

when you want to use a library or framework target
in another target
name[RW]

@return [String] the name of the target.

pinned_build_phases[RW]

@return [Array<BuildPhase>] the list

of build phases to place first for the project.
platform[RW]

@return [String] the platform for the target.

Can be `:ios`, `:osx`, `:tvos`, `:watchos`.
schemes[RW]

@return [Array<Scheme>] schemes for the target

system_frameworks[W]

@return [Array<String>] system frameworks to include for the target

Defaults to:
 - ["Foundation", "UIKit"] for iOS
 - ["Cocoa"] for OSX

@example

spec.system_frameworks = ["Foundation"]
system_libraries[RW]

@return [Array<String>] system libraries to include for the target

@example

spec.system_libraries = ["z", "sqlite3"]
target_dependencies[RW]

@return [Array<Target>] targets to use as dependencies

type[RW]

@return [String] the type of the target.

Can be `:application`, `:dynamic_library`,
`framework` or `:static_library`.

Public Class Methods

new(project) { |self| ... } click to toggle source

@param [Project] project

the project the target belongs to.

@param [Proc] block

an optional block that configures the target through the DSL.

@example Creating a Target.

Target.new(project) do |t|
  t.name "test"
end
# File lib/xcake/dsl/target.rb, line 197
def initialize(project)
  @pinned_build_phases = []
  @build_phases = []
  @build_rules = []
  @exclude_files = []
  @linked_targets = []
  @system_libraries = []
  @target_dependencies = []
  @schemes = []
  @project = project

  yield(self) if block_given?
end

Public Instance Methods

build_rule(name, file_type, output_files, output_files_compiler_flags, script, &block) click to toggle source

Creates a new build rule for the target

@param [String] name

the name to use for the build rule

@param [Proc] block

an optional block that configures the build rule through the DSL.

@return [BuildRule] the new xcode build rule

# File lib/xcake/dsl/target/sugar.rb, line 86
def build_rule(name, file_type, output_files, output_files_compiler_flags, script, &block)
  rule = BuildRule.new(&block)
  rule.name = name
  rule.file_type = file_type
  rule.output_files = output_files
  rule.output_files_compiler_flags = output_files_compiler_flags
  rule.script = script
  build_rules << rule
  rule
end
copy_files_build_phase(name, &block) click to toggle source

Creates a new Copy Files build phase for the target

@param [String] name

the name to use for the build phase

@param [Proc] block

an optional block that configures the build phase through the DSL.

@return [CopyFilesBuildPhase] the new xcode build phase

# File lib/xcake/dsl/target/sugar.rb, line 16
def copy_files_build_phase(name, &block)
  phase = CopyFilesBuildPhase.new(&block)
  phase.name = name
  build_phases << phase
  phase
end
default_debug_settings() click to toggle source
# File lib/xcake/dsl/target/configurable.rb, line 13
def default_debug_settings
  Xcake::Constants
    .common_build_settings(:debug,
                           platform,
                           deployment_target.to_s,
                           type,
                           language)
    .merge!(default_settings)
    .merge('SWIFT_OPTIMIZATION_LEVEL' => '-Onone')
end
default_release_settings() click to toggle source
# File lib/xcake/dsl/target/configurable.rb, line 24
def default_release_settings
  Xcake::Constants
    .common_build_settings(:release,
                           platform,
                           deployment_target.to_s,
                           type,
                           language)
    .merge!(default_settings)
end
default_settings() click to toggle source
# File lib/xcake/dsl/target/configurable.rb, line 7
def default_settings
  {
    'INFOPLIST_FILE' => "#{name}/Supporting Files/Info.plist"
  }
end
headers_build_phase(&block) click to toggle source

Creates a new Copy Headers build phase for the target

@param [Proc] block

an optional block that configures the build phase through the DSL.

@return [HeadersBuildPhase] the new xcode build phase

# File lib/xcake/dsl/target/sugar.rb, line 31
def headers_build_phase(&block)
  phase = HeadersBuildPhase.new(&block)
  build_phases << phase
  phase
end
include_files() click to toggle source

@!group getters

# File lib/xcake/dsl/target.rb, line 229
def include_files
  # Import files in folder with same name as target by default
  @include_files ||= ["./#{@name}/**/*.*"]
end
info_plist_paths() click to toggle source
# File lib/xcake/dsl/target.rb, line 239
def info_plist_paths
  all_configurations.map { |config| config.settings['INFOPLIST_FILE'] }.uniq
end
parent_configurable() click to toggle source
# File lib/xcake/dsl/target/configurable.rb, line 3
def parent_configurable
  @project
end
pre_shell_script_build_phase(name, script, &block) click to toggle source

Creates a new Shell Script build phase for the target before all of the other build phases

@param [String] name

the name to use for the build phase

@param [Proc] block

an optional block that configures the build phase through the DSL.

@return [ShellScriptBuildPhase] the new xcode build phase

# File lib/xcake/dsl/target/sugar.rb, line 48
def pre_shell_script_build_phase(name, script, &block)
  phase = ShellScriptBuildPhase.new(&block)
  phase.name = name
  phase.script = script
  pinned_build_phases << phase
  phase
end
scheme(name, &block) click to toggle source

Creates a new scheme for the target

@param [String] name

the name of the new scheme

@return [Scheme] the scheme

the newly created scheme
# File lib/xcake/dsl/target.rb, line 221
def scheme(name, &block)
  scheme = Scheme.new(name, &block)
  schemes << scheme
  scheme
end
shell_script_build_phase(name, script, &block) click to toggle source

Creates a new Shell Script build phase for the target

@param [String] name

the name to use for the build phase

@param [Proc] block

an optional block that configures the build phase through the DSL.

@return [ShellScriptBuildPhase] the new xcode build phase

# File lib/xcake/dsl/target/sugar.rb, line 67
def shell_script_build_phase(name, script, &block)
  phase = ShellScriptBuildPhase.new(&block)
  phase.name = name
  phase.script = script
  build_phases << phase
  phase
end
system_frameworks() click to toggle source
# File lib/xcake/dsl/target.rb, line 234
def system_frameworks
  # Use default frameworks by default
  @system_frameworks ||= default_system_frameworks_for(platform)
end
to_s() click to toggle source

@!group Conversion

# File lib/xcake/dsl/target.rb, line 245
def to_s
  "Target<#{name}>"
end

Protected Instance Methods

default_system_frameworks_for(platform) click to toggle source

Returns an array of default system frameworks to use for a given platform.

@param [Symbol] platform

platform the frameworks are for.

@return [Array<String>] system frameworks to use

# File lib/xcake/dsl/target.rb, line 260
def default_system_frameworks_for(platform)
  case platform
  when :ios
    %w(Foundation UIKit)
  when :osx
    %w(Cocoa)
  when :tvos
    %w(Foundation UIKit)
  when :watchos
    %w(Foundation UIKit WatchKit)
  else
    abort 'Platform not supported!'
  end
end