Class: Pod::Target::BuildSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/target/build_settings.rb

Overview

Since:

  • 1.5.0

Direct Known Subclasses

AggregateTargetSettings, PodTargetSettings

Defined Under Namespace

Classes: AggregateTargetSettings, PodTargetSettings

Constants collapse

PLURAL_SETTINGS =

Returns The build settings that should be treated as arrays, rather than strings.

Returns:

  • (Set<String>)

    The build settings that should be treated as arrays, rather than strings.

Since:

  • 1.5.0

%w(
  ALTERNATE_PERMISSIONS_FILES
  ARCHS
  BUILD_VARIANTS
  EXCLUDED_SOURCE_FILE_NAMES
  FRAMEWORK_SEARCH_PATHS
  GCC_PREPROCESSOR_DEFINITIONS
  GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS
  HEADER_SEARCH_PATHS
  INCLUDED_SOURCE_FILE_NAMES
  INFOPLIST_PREPROCESSOR_DEFINITIONS
  LD_RUNPATH_SEARCH_PATHS
  LIBRARY_SEARCH_PATHS
  LOCALIZED_STRING_MACRO_NAMES
  OTHER_CFLAGS
  OTHER_CPLUSPLUSFLAGS
  OTHER_LDFLAGS
  OTHER_MODULE_VERIFIER_FLAGS
  OTHER_SWIFT_FLAGS
  REZ_SEARCH_PATHS
  SECTORDER_FLAGS
  SWIFT_ACTIVE_COMPILATION_CONDITIONS
  SWIFT_INCLUDE_PATHS
  SYSTEM_FRAMEWORK_SEARCH_PATHS
  SYSTEM_HEADER_SEARCH_PATHS
  USER_HEADER_SEARCH_PATHS
  WARNING_CFLAGS
  WARNING_LDFLAGS
).to_set.freeze
CONFIGURATION_BUILD_DIR_VARIABLE =

Returns The variable for the configuration build directory used when building pod targets.

Returns:

  • (String)

    The variable for the configuration build directory used when building pod targets.

Since:

  • 1.5.0

'${PODS_CONFIGURATION_BUILD_DIR}'
XCFRAMEWORKS_BUILD_DIR_VARIABLE =

Returns The variable for the configuration intermediate frameworks directory used for building pod targets that contain vendored xcframeworks.

Returns:

  • (String)

    The variable for the configuration intermediate frameworks directory used for building pod targets that contain vendored xcframeworks.

Since:

  • 1.5.0

'${PODS_XCFRAMEWORKS_BUILD_DIR}'

Public API collapse

DSL collapse

Public API collapse

Build System collapse

Code Signing collapse

Frameworks collapse

Libraries collapse

Clang collapse

Swift collapse

Linking collapse

Constructor Details

#initialize(target) ⇒ BuildSettings

Initialize a new instance

Parameters:

Since:

  • 1.5.0



177
178
179
180
# File 'lib/cocoapods/target/build_settings.rb', line 177

def initialize(target)
  @target = target
  @__memoized = {}
end

Class Attribute Details

.build_settings_namesSet<String> (readonly)

be present in the #xcconfig

Returns:

  • (Set<String>)

    a set of all the build settings names that will

Since:

  • 1.5.0



160
161
162
# File 'lib/cocoapods/target/build_settings.rb', line 160

def build_settings_names
  @build_settings_names
end

Instance Attribute Details

#targetTarget (readonly)

Returns The target this build settings object is generating build settings for.

Returns:

  • (Target)

    The target this build settings object is generating build settings for

Since:

  • 1.5.0



170
171
172
# File 'lib/cocoapods/target/build_settings.rb', line 170

def target
  @target
end

Class Method Details

.define_build_settings_method(method_name, build_setting: false, memoized: false, sorted: false, uniqued: false, compacted: false, frozen: true, from_search_paths_aggregate_targets: false, from_pod_targets_to_link: false, &implementation) ⇒ Object (private)

Creates a method that calculates a part of the build settings for the #target.

Parameters:

  • method_name (Symbol, String)

    The name of the method to define

  • build_setting (Boolean) (defaults to: false)

    Whether the method name should be added (upcased) to build_setting_names

  • memoized (Boolean) (defaults to: false)

    Whether the method should be memoized

  • sorted (Boolean) (defaults to: false)

    Whether the return value should be sorted

  • uniqued (Boolean) (defaults to: false)

    Whether the return value should be uniqued

  • compacted (Boolean) (defaults to: false)

    Whether the return value should be compacted

  • frozen (Boolean) (defaults to: true)

    Whether the return value should be frozen

  • from_search_paths_aggregate_targets (Boolean, Symbol) (defaults to: false)

    If truthy, the method from Aggregate that should be used to concatenate build settings from AggregateTarget#search_paths_aggregate_target

  • from_pod_targets_to_link (Symbol) (defaults to: false)

    If truthy, the _to_import values from BuildSettings#pod_targets_to_link will be concatenated

  • implementation (Block)

Since:

  • 1.5.0



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/cocoapods/target/build_settings.rb', line 100

def self.define_build_settings_method(method_name, build_setting: false,
                                      memoized: false, sorted: false, uniqued: false, compacted: false, frozen: true,
                                      from_search_paths_aggregate_targets: false, from_pod_targets_to_link: false,
                                      &implementation)

  memoized_key = "#{self}##{method_name}"

  (@build_settings_names ||= Set.new) << method_name.to_s.upcase if build_setting

  raw_method_name = :"_raw_#{method_name}"
  define_method(raw_method_name, &implementation)
  private(raw_method_name)

  dup_before_freeze = frozen && (from_pod_targets_to_link || from_search_paths_aggregate_targets || uniqued || sorted)

  define_method(method_name) do
    if memoized
      retval = @__memoized.fetch(memoized_key, :not_found)
      return retval if :not_found != retval
    end

    retval = send(raw_method_name)
    if retval.nil?
      @__memoized[memoized_key] = retval if memoized
      return
    end

    retval = retval.dup if dup_before_freeze && retval.frozen?

    retval.concat(pod_targets_to_link.flat_map { |pod_target| pod_target.build_settings_for_spec(pod_target.root_spec, :configuration => configuration_name).public_send("#{method_name}_to_import") }) if from_pod_targets_to_link
    retval.concat(search_paths_aggregate_target_pod_target_build_settings.flat_map(&from_search_paths_aggregate_targets)) if from_search_paths_aggregate_targets

    retval.compact! if compacted
    retval.uniq! if uniqued
    retval.sort! if sorted
    retval.freeze if frozen

    @__memoized[memoized_key] = retval if memoized

    retval
  end
end

.xcframework_intermediate_dir(xcframework) ⇒ String

Returns the path to the directory containing the xcframework slice.

Parameters:

  • xcframework (XCFramework)

    the xcframework slice that will be copied to the intermediates dir

Returns:

  • (String)

    the path to the directory containing the xcframework slice

Since:

  • 1.5.0



148
149
150
# File 'lib/cocoapods/target/build_settings.rb', line 148

def self.xcframework_intermediate_dir(xcframework)
  "#{XCFRAMEWORKS_BUILD_DIR_VARIABLE}/#{xcframework.target_name}"
end

Instance Method Details

#_ld_runpath_search_paths(requires_host_target: false, test_bundle: false, uses_swift: false) ⇒ Array<String> (private)

Returns the LD_RUNPATH_SEARCH_PATHS needed for dynamically linking the #target.

Parameters:

  • requires_host_target (Boolean) (defaults to: false)
  • test_bundle (Boolean) (defaults to: false)

Returns:

  • (Array<String>)

    the LD_RUNPATH_SEARCH_PATHS needed for dynamically linking the #target

Since:

  • 1.5.0



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/cocoapods/target/build_settings.rb', line 355

def _ld_runpath_search_paths(requires_host_target: false, test_bundle: false, uses_swift: false)
  paths = []
  if uses_swift
    paths << '/usr/lib/swift'
    paths << '$(PLATFORM_DIR)/Developer/Library/Frameworks' if test_bundle
  end
  if target.platform.symbolic_name == :osx
    paths << "'@executable_path/../Frameworks'"
    paths << if test_bundle
               "'@loader_path/../Frameworks'"
             else
               "'@loader_path/Frameworks'"
             end
    paths << '${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}' if uses_swift
  else
    paths << "'@executable_path/Frameworks'"
    paths << "'@loader_path/Frameworks'"
    paths << "'@executable_path/../../Frameworks'" if requires_host_target
  end
  paths
end

#add_inherited_to_plural(hash) ⇒ Hash<String => String> (private)

Returns:

  • (Hash<String => String>)

Since:

  • 1.5.0



407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/cocoapods/target/build_settings.rb', line 407

def add_inherited_to_plural(hash)
  Hash[hash.map do |key, value|
    next [key, '$(inherited)'] if value.nil?
    if PLURAL_SETTINGS.include?(key)
      raise ArgumentError, "#{key} is a plural setting, cannot have #{value.inspect} as its value" unless value.is_a? Array

      value = "$(inherited) #{quote_array(value)}"
    else
      raise ArgumentError, "#{key} is not a plural setting, cannot have #{value.inspect} as its value" unless value.is_a? String
    end

    [key, value]
  end]
end

#clang_warn_quoted_include_in_framework_headerBoolean

Xcode 12 turns on this warning by default which is problematic for CocoaPods-generated imports which use double-quoted paths. The clang_warn_quoted_include_in_framework_header build setting for the #target.

The return value from this method will be: clang_warn_quoted_include_in_framework_header, build_setting.

Returns:

  • (Boolean)


344
345
346
# File 'lib/cocoapods/target/build_settings.rb', line 344

define_build_settings_method :clang_warn_quoted_include_in_framework_header, :build_setting => true do
  'NO'
end

#code_sign_identityString

The code_sign_identity build setting for the #target.

The return value from this method will be: code_sign_identity, build_setting.

Returns:

  • (String)


236
237
238
239
240
# File 'lib/cocoapods/target/build_settings.rb', line 236

define_build_settings_method :code_sign_identity, :build_setting => true do
  return unless target.build_as_dynamic?
  return unless target.platform.to_sym == :osx
  ''
end

#framework_search_pathsArray<String>

The framework_search_paths build setting for the #target.

The return value from this method will be: framework_search_paths, build_setting, memoized.

Returns:

  • (Array<String>)


257
258
259
# File 'lib/cocoapods/target/build_settings.rb', line 257

define_build_settings_method :framework_search_paths, :build_setting => true, :memoized => true do
  framework_search_paths_to_import_developer_frameworks(frameworks + weak_frameworks)
end

#framework_search_paths_to_import_developer_frameworks(frameworks) ⇒ Array<String>

Returns the FRAMEWORK_SEARCH_PATHS needed to import developer frameworks.

Parameters:

  • frameworks (Array<String>)

    The list of framework names

Returns:

  • (Array<String>)

    the FRAMEWORK_SEARCH_PATHS needed to import developer frameworks

Since:

  • 1.5.0



266
267
268
269
270
271
272
# File 'lib/cocoapods/target/build_settings.rb', line 266

def framework_search_paths_to_import_developer_frameworks(frameworks)
  if frameworks.include?('XCTest') || frameworks.include?('SenTestingKit')
    %w[ $(PLATFORM_DIR)/Developer/Library/Frameworks ]
  else
    []
  end
end

#frameworksArray<String>

The frameworks build setting for the #target.

The return value from this method will be: frameworks.

Returns:

  • (Array<String>)


247
248
249
# File 'lib/cocoapods/target/build_settings.rb', line 247

define_build_settings_method :frameworks do
  []
end

#gcc_preprocessor_definitionsArray<String>

The gcc_preprocessor_definitions build setting for the #target.

The return value from this method will be: gcc_preprocessor_definitions, build_setting.

Returns:

  • (Array<String>)


288
289
290
# File 'lib/cocoapods/target/build_settings.rb', line 288

define_build_settings_method :gcc_preprocessor_definitions, :build_setting => true do
  %w( COCOAPODS=1 )
end

#initialize_copy(other) ⇒ Object

Since:

  • 1.5.0



182
183
184
185
# File 'lib/cocoapods/target/build_settings.rb', line 182

def initialize_copy(other)
  super
  @__memoized = {}
end

#librariesArray<String>

The libraries build setting for the #target.

The return value from this method will be: libraries.

Returns:

  • (Array<String>)


279
280
281
# File 'lib/cocoapods/target/build_settings.rb', line 279

define_build_settings_method :libraries do
  []
end

#load_xcframework(target_name, path) ⇒ Xcode::XCFramework (private)

Returns the xcframework at the given path.

Parameters:

  • target_name (String)

    the name of the target this xcframework belongs to

  • path (Pathname, String)

    the path to the xcframework bundle

Returns:

Since:

  • 1.5.0



523
524
525
# File 'lib/cocoapods/target/build_settings.rb', line 523

def load_xcframework(target_name, path)
  Xcode::XCFramework.new(target_name, path)
end

#merge_spec_xcconfig_into_xcconfig(spec_xcconfig_hash, xcconfig) ⇒ Xcodeproj::Config (private)

Merges the spec-defined xcconfig into the derived xcconfig, overriding any singular settings and merging plural settings.

Parameters:

  • spec_xcconfig_hash (Hash<String,String>)

    the merged xcconfig defined in the spec.

  • xcconfig (Xcodeproj::Config)

    the config to merge into.

Returns:

  • (Xcodeproj::Config)

    the merged config.

Since:

  • 1.5.0



489
490
491
492
493
494
# File 'lib/cocoapods/target/build_settings.rb', line 489

def merge_spec_xcconfig_into_xcconfig(spec_xcconfig_hash, xcconfig)
  plural_configs, singlular_configs = spec_xcconfig_hash.partition { |k, _v| PLURAL_SETTINGS.include?(k) }.map { |a| Hash[a] }
  xcconfig.attributes.merge!(singlular_configs)
  xcconfig.merge!(plural_configs)
  xcconfig
end

#merged_xcconfigs(xcconfig_values_by_consumer_by_key, attribute, overriding: {}) ⇒ Hash<String, String> (private)

Parameters:

  • xcconfig_values_by_consumer_by_key (Hash)
  • attribute (#to_s)

    The name of the attribute being merged

Returns:

  • (Hash<String, String>)

Since:

  • 1.5.0



449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/cocoapods/target/build_settings.rb', line 449

def merged_xcconfigs(xcconfig_values_by_consumer_by_key, attribute, overriding: {})
  xcconfig_values_by_consumer_by_key.each_with_object(overriding.dup) do |(key, values_by_consumer), xcconfig|
    uniq_values = values_by_consumer.values.uniq
    values_are_bools = uniq_values.all? { |v| v.is_a?(String) && v =~ /\A(yes|no)\z/i }
    if values_are_bools
      # Boolean build settings
      if uniq_values.count > 1
        UI.warn "Can't merge #{attribute} for pod targets: " \
          "#{values_by_consumer.keys.map(&:name)}. Boolean build " \
          "setting #{key} has different values."
      else
        xcconfig[key] = uniq_values.first
      end
    elsif PLURAL_SETTINGS.include? key
      # Plural build settings
      if xcconfig.key?(key)
        overridden = xcconfig[key]
        uniq_values.prepend(overridden)
      end
      xcconfig[key] = uniq_values.uniq.join(' ')
    elsif uniq_values.count > 1
      # Singular build settings
      UI.warn "Can't merge #{attribute} for pod targets: " \
        "#{values_by_consumer.keys.map(&:name)}. Singular build " \
        "setting #{key} has different values."
    else
      xcconfig[key] = uniq_values.first
    end
  end
end

#module_map_filesArray<String>

The module_map_files build setting for the #target.

The return value from this method will be: module_map_files.

Returns:

  • (Array<String>)


303
304
305
# File 'lib/cocoapods/target/build_settings.rb', line 303

define_build_settings_method :module_map_files do
  []
end

#other_cflagsArray<String>

The other_cflags build setting for the #target.

The return value from this method will be: other_cflags, build_setting, memoized.

Returns:

  • (Array<String>)


293
294
295
# File 'lib/cocoapods/target/build_settings.rb', line 293

define_build_settings_method :other_cflags, :build_setting => true, :memoized => true do
  module_map_files.map { |f| "-fmodule-map-file=#{f}" }
end

#other_ldflagsArray<String>

The other_ldflags build setting for the #target.

The return value from this method will be: other_ldflags, build_setting, memoized.

Returns:

  • (Array<String>)


379
380
381
382
383
384
385
386
387
388
389
# File 'lib/cocoapods/target/build_settings.rb', line 379

define_build_settings_method :other_ldflags, :build_setting => true, :memoized => true do
  ld_flags = []
  ld_flags << '-ObjC' if requires_objc_linker_flag?
  if requires_fobjc_arc?
    ld_flags << '-fobjc-arc'
  end
  libraries.each { |l| ld_flags << %(-l"#{l}") }
  frameworks.each { |f| ld_flags << '-framework' << %("#{f}") }
  weak_frameworks.each { |f| ld_flags << '-weak_framework' << %("#{f}") }
  ld_flags
end

#other_module_verifier_flagsArray<String>

The other_module_verifier_flags build setting for the #target.

The return value from this method will be: other_module_verifier_flags, build_setting, memoized.

Returns:

  • (Array<String>)


298
299
300
# File 'lib/cocoapods/target/build_settings.rb', line 298

define_build_settings_method :other_module_verifier_flags, :build_setting => true, :memoized => true do
  []
end

#other_swift_flagsArray<String>

The other_swift_flags build setting for the #target.

The return value from this method will be: other_swift_flags, build_setting, memoized.

Returns:

  • (Array<String>)


320
321
322
323
324
325
# File 'lib/cocoapods/target/build_settings.rb', line 320

define_build_settings_method :other_swift_flags, :build_setting => true, :memoized => true do
  return unless target.uses_swift? || other_swift_flags_without_swift?
  flags = %w(-D COCOAPODS)
  flags.concat module_map_files.flat_map { |f| ['-Xcc', "-fmodule-map-file=#{f}"] }
  flags
end

#other_swift_flags_without_swift?Boolean

Returns Whether OTHER_SWIFT_FLAGS should be generated when the target does not use swift.

Returns:

  • (Boolean)

    Whether OTHER_SWIFT_FLAGS should be generated when the target does not use swift.

Since:

  • 1.5.0



315
316
317
# File 'lib/cocoapods/target/build_settings.rb', line 315

def other_swift_flags_without_swift?
  false
end

#pods_build_dirString

The pods_build_dir build setting for the #target.

The return value from this method will be: pods_build_dir, build_setting.

Returns:

  • (String)


213
214
215
# File 'lib/cocoapods/target/build_settings.rb', line 213

define_build_settings_method :pods_build_dir, :build_setting => true do
  '${BUILD_DIR}'
end

#pods_configuration_build_dirString

The pods_configuration_build_dir build setting for the #target.

The return value from this method will be: pods_configuration_build_dir, build_setting.

Returns:

  • (String)


218
219
220
# File 'lib/cocoapods/target/build_settings.rb', line 218

define_build_settings_method :pods_configuration_build_dir, :build_setting => true do
  '${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)'
end

#pods_xcframeworks_build_dirObject

The pods_xcframeworks_build_dir build setting for the #target.

The return value from this method will be: pods_xcframeworks_build_dir, build_setting.



222
223
224
# File 'lib/cocoapods/target/build_settings.rb', line 222

define_build_settings_method :pods_xcframeworks_build_dir, :build_setting => true do
  '$(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates'
end

#quote_array(array) ⇒ Array<String> (private)

Parameters:

  • array (Array<String>)

Returns:

  • (Array<String>)

Since:

  • 1.5.0



426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/cocoapods/target/build_settings.rb', line 426

def quote_array(array)
  array.map do |element|
    case element
    when /\A([\w-]+?)=(.+)\z/
      key = Regexp.last_match(1)
      value = Regexp.last_match(2)
      value = %("#{value}") if value =~ /[^\w\d]/
      %(#{key}=#{value})
    when /[\$\[\]\ ]/
      %("#{element}")
    else
      element
    end
  end.join(' ')
end

#requires_fobjc_arc?Boolean

The requires_fobjc_arc? build setting for the #target.

The return value from this method will be: requires_fobjc_arc?.

Returns:

  • (Boolean)


337
338
339
# File 'lib/cocoapods/target/build_settings.rb', line 337

define_build_settings_method :requires_fobjc_arc? do
  false
end

#requires_objc_linker_flag?Boolean

The requires_objc_linker_flag? build setting for the #target.

The return value from this method will be: requires_objc_linker_flag?.

Returns:

  • (Boolean)


332
333
334
# File 'lib/cocoapods/target/build_settings.rb', line 332

define_build_settings_method :requires_objc_linker_flag? do
  false
end

#save_as(path) ⇒ Xcodeproj::Config

Saves the generated xcconfig to the given path

Parameters:

  • path (String, Pathname)

    The path the xcconfig will be saved to

Returns:

  • (Xcodeproj::Config)

See Also:

Since:

  • 1.5.0



204
205
206
# File 'lib/cocoapods/target/build_settings.rb', line 204

def save_as(path)
  xcconfig.save_as(path)
end

#select_maximal_pod_targets(pod_targets) ⇒ Array<PodTarget> (private)

Filters out pod targets whose specs are a subset of another target's.

Parameters:

Returns:

Since:

  • 1.5.0



503
504
505
506
507
508
509
510
511
512
513
514
515
# File 'lib/cocoapods/target/build_settings.rb', line 503

def select_maximal_pod_targets(pod_targets)
  subset_targets = []
  pod_targets.uniq.group_by(&:pod_name).each do |_pod_name, targets|
    targets.combination(2) do |a, b|
      if (a.specs - b.specs).empty?
        subset_targets << a
      elsif (b.specs - a.specs).empty?
        subset_targets << b
      end
    end
  end
  pod_targets - subset_targets
end

#to_hHash<String => String|Array<String>> (private)

Returns:

  • (Hash<String => String|Array<String>>)

Since:

  • 1.5.0



398
399
400
401
402
403
404
# File 'lib/cocoapods/target/build_settings.rb', line 398

def to_h
  hash = {}
  self.class.build_settings_names.sort.each do |setting|
    hash[setting] = public_send(setting.downcase)
  end
  hash
end

#use_recursive_script_inputs_in_script_phasesString

The use_recursive_script_inputs_in_script_phases build setting for the #target.

The return value from this method will be: use_recursive_script_inputs_in_script_phases, build_setting.

Returns:

  • (String)


227
228
229
# File 'lib/cocoapods/target/build_settings.rb', line 227

define_build_settings_method :use_recursive_script_inputs_in_script_phases, :build_setting => true do
  'YES'
end

#weak_frameworksArray<String>

The weak_frameworks build setting for the #target.

The return value from this method will be: weak_frameworks.

Returns:

  • (Array<String>)


252
253
254
# File 'lib/cocoapods/target/build_settings.rb', line 252

define_build_settings_method :weak_frameworks do
  []
end

#xcconfigXcodeproj::Config Also known as: generate

The xcconfig build setting for the #target.

The return value from this method will be: xcconfig, memoized.

Returns:

  • (Xcodeproj::Config)


188
189
190
191
# File 'lib/cocoapods/target/build_settings.rb', line 188

define_build_settings_method :xcconfig, :memoized => true do
  settings = add_inherited_to_plural(to_h)
  Xcodeproj::Config.new(settings)
end