Commit 528cdd02 authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #3757 from CocoaPods/seg-ld-objc

[XCConfig] Only include -ObjC flag when linking against a static lib
parents 6e69aff6 ab1aeea1
...@@ -38,6 +38,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -38,6 +38,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Samuel Giddins](https://github.com/segiddins) [Samuel Giddins](https://github.com/segiddins)
[#3754](https://github.com/CocoaPods/CocoaPods/issues/3754) [#3754](https://github.com/CocoaPods/CocoaPods/issues/3754)
* Don't add the `-ObjC` linker flag if it's unnecessary.
[Samuel Giddins](https://github.com/segiddins)
[#3537](https://github.com/CocoaPods/CocoaPods/issues/3537)
## 0.38.0.beta.1 ## 0.38.0.beta.1
......
...@@ -49,8 +49,10 @@ module Pod ...@@ -49,8 +49,10 @@ module Pod
# @return [Xcodeproj::Config] # @return [Xcodeproj::Config]
# #
def generate def generate
includes_static_libs = !target.requires_frameworks?
includes_static_libs ||= target.pod_targets.flat_map(&:file_accessors).any? { |fa| !fa.vendored_libraries.empty? }
config = { config = {
'OTHER_LDFLAGS' => '$(inherited) ' + XCConfigHelper.default_ld_flags(target), 'OTHER_LDFLAGS' => '$(inherited) ' + XCConfigHelper.default_ld_flags(target, includes_static_libs),
'PODS_ROOT' => target.relative_pods_root, 'PODS_ROOT' => target.relative_pods_root,
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1', 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1',
} }
......
...@@ -31,13 +31,14 @@ module Pod ...@@ -31,13 +31,14 @@ module Pod
# while `-fobjc-arc` is included only if requested in the # while `-fobjc-arc` is included only if requested in the
# Podfile. # Podfile.
# #
def self.default_ld_flags(target) def self.default_ld_flags(target, includes_static_libraries = false)
ld_flags = '-ObjC' ld_flags = ''
ld_flags << '-ObjC' if includes_static_libraries
if target.podfile.set_arc_compatibility_flag? && if target.podfile.set_arc_compatibility_flag? &&
target.spec_consumers.any?(&:requires_arc?) target.spec_consumers.any?(&:requires_arc?)
ld_flags << ' -fobjc-arc' ld_flags << ' -fobjc-arc'
end end
ld_flags ld_flags.strip
end end
# Configures the given Xcconfig # Configures the given Xcconfig
......
Subproject commit 6d4b38764f551fcda4da634ba777640d96162b56 Subproject commit 99cf7a48d31f8d48aff0266d46ae950b4c28d804
...@@ -38,10 +38,6 @@ module Pod ...@@ -38,10 +38,6 @@ module Pod
@xcconfig.class.should == Xcodeproj::Config @xcconfig.class.should == Xcodeproj::Config
end end
it 'configures the project to load all members that implement Objective-c classes or categories' do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-ObjC'
end
it 'does not add the -fobjc-arc to OTHER_LDFLAGS by default as Xcode 4.3.2 does not support it' do it 'does not add the -fobjc-arc to OTHER_LDFLAGS by default as Xcode 4.3.2 does not support it' do
@consumer.stubs(:requires_arc?).returns(true) @consumer.stubs(:requires_arc?).returns(true)
@xcconfig.to_hash['OTHER_LDFLAGS'].should.not.include('-fobjc-arc') @xcconfig.to_hash['OTHER_LDFLAGS'].should.not.include('-fobjc-arc')
...@@ -97,6 +93,10 @@ module Pod ...@@ -97,6 +93,10 @@ module Pod
behaves_like 'AggregateXCConfig' behaves_like 'AggregateXCConfig'
it 'configures the project to load all members that implement Objective-c classes or categories' do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-ObjC'
end
it 'adds the sandbox public headers search paths to the xcconfig, with quotes, as header search paths' do it 'adds the sandbox public headers search paths to the xcconfig, with quotes, as header search paths' do
expected = "$(inherited) \"#{config.sandbox.public_headers.search_paths(:ios).join('" "')}\"" expected = "$(inherited) \"#{config.sandbox.public_headers.search_paths(:ios).join('" "')}\""
@xcconfig.to_hash['HEADER_SEARCH_PATHS'].should == expected @xcconfig.to_hash['HEADER_SEARCH_PATHS'].should == expected
...@@ -141,6 +141,10 @@ module Pod ...@@ -141,6 +141,10 @@ module Pod
behaves_like 'AggregateXCConfig' behaves_like 'AggregateXCConfig'
it "doesn't configure the project to load all members that implement Objective-c classes or categories" do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.not.include '-ObjC'
end
describe 'with a vendored-library pod' do describe 'with a vendored-library pod' do
def spec def spec
fixture_spec('monkey/monkey.podspec') fixture_spec('monkey/monkey.podspec')
...@@ -149,6 +153,10 @@ module Pod ...@@ -149,6 +153,10 @@ module Pod
it 'does not add the framework build path to the xcconfig' do it 'does not add the framework build path to the xcconfig' do
@xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should.be.nil? @xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should.be.nil?
end end
it 'configures the project to load all members that implement Objective-c classes or categories' do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-ObjC'
end
end end
it 'sets the PODS_FRAMEWORK_BUILD_PATH build variable' do it 'sets the PODS_FRAMEWORK_BUILD_PATH build variable' do
......
...@@ -19,8 +19,8 @@ module Pod ...@@ -19,8 +19,8 @@ module Pod
@xcconfig.class.should == Xcodeproj::Config @xcconfig.class.should == Xcodeproj::Config
end end
it 'configures the project to load all members that implement Objective-c classes or categories from the static library' do it 'does not configure the project to load all members that implement Objective-c classes or categories from the static library' do
@xcconfig.to_hash['OTHER_LDFLAGS'].should.include '-ObjC' @xcconfig.to_hash['OTHER_LDFLAGS'].should.not.include '-ObjC'
end end
it 'does not add the -fobjc-arc to OTHER_LDFLAGS by default as Xcode 4.3.2 does not support it' do it 'does not add the -fobjc-arc to OTHER_LDFLAGS by default as Xcode 4.3.2 does not support it' do
......
...@@ -15,6 +15,9 @@ module Pod ...@@ -15,6 +15,9 @@ module Pod
podfile = stub(:set_arc_compatibility_flag? => false) podfile = stub(:set_arc_compatibility_flag? => false)
target = stub(:podfile => podfile) target = stub(:podfile => podfile)
result = @sut.default_ld_flags(target) result = @sut.default_ld_flags(target)
result.should == ''
result = @sut.default_ld_flags(target, true)
result.should == '-ObjC' result.should == '-ObjC'
end end
...@@ -23,6 +26,9 @@ module Pod ...@@ -23,6 +26,9 @@ module Pod
spec_consumer = stub(:requires_arc? => true) spec_consumer = stub(:requires_arc? => true)
target = stub(:podfile => podfile, :spec_consumers => [spec_consumer]) target = stub(:podfile => podfile, :spec_consumers => [spec_consumer])
result = @sut.default_ld_flags(target) result = @sut.default_ld_flags(target)
result.should == '-fobjc-arc'
result = @sut.default_ld_flags(target, true)
result.should == '-ObjC -fobjc-arc' result.should == '-ObjC -fobjc-arc'
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment