Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ Settings are merged in the following order: `groups`, `base`, `configs` (simple
- [ ] **templateAttributes**: **[String: String]** - A list of attributes where each instance of `${attributeName}` within the templates listed in `templates` will be replaced with the value specified.
- [ ] **transitivelyLinkDependencies**: **Bool** - If this is not specified the value from the project set in [Options](#options)`.transitivelyLinkDependencies` will be used.
- [ ] **directlyEmbedCarthageDependencies**: **Bool** - If this is `true` Carthage framework dependencies will be embedded using an `Embed Frameworks` build phase instead of the `copy-frameworks` script. Defaults to `true` for all targets except iOS/tvOS/watchOS Applications.
- [ ] **requiresObjCLinking**: **Bool** - If this is `true` any targets that link to this target will have `-ObjC` added to their `OTHER_LDFLAGS`. This is required if a static library has any categories or extensions on Objective-C code. See [this guide](https://pewpewthespells.com/blog/objc_linker_flags.html#objc) for more details. Defaults to `true` if `type` is `library.static`. If you are 100% sure you don't have categories or extensions on Objective-C code (pure Swift with no use of Foundation/UIKit) you can set this to `false`, otherwise it's best to leave it alone.
- [ ] **requiresObjCLinking**: **Bool** - If this is `true` any targets that link to this target will have `-ObjC` added to their `OTHER_LDFLAGS`. This is required if a static library or framework has any categories or extensions on Objective-C code. See [this guide](https://pewpewthespells.com/blog/objc_linker_flags.html#objc) for more details. Defaults to `true` if `type` is `library.static` or `framework.static`, or if `type` is `framework` with `MACH_O_TYPE` set to `staticlib`. If you are 100% sure you don't have categories or extensions on Objective-C code (pure Swift with no use of Foundation/UIKit) you can set this to `false`, otherwise it's best to leave it alone.
- [ ] **onlyCopyFilesOnInstall**: **Bool** – If this is `true`, the `Embed Frameworks` and `Embed App Extensions` (if available) build phases will have the "Copy only when installing" chekbox checked. Defaults to `false`.
- [ ] **buildToolPlugins**: **[[Build Tool Plug-ins](#build-tool-plug-ins)]** - Commands for the build system that run automatically *during* the build.
- [ ] **preBuildScripts**: **[[Build Script](#build-script)]** - Build scripts that run *before* any other build phases
Expand Down
4 changes: 2 additions & 2 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ public class PBXProjGenerator {
let settings = Settings(buildSettings: buildSettings, configSettings: [:], groups: [])
let deploymentTargetString = buildSettings[platform.deploymentTargetSetting]?.stringValue
let deploymentTarget = deploymentTargetString == nil ? nil : try Version.parse(deploymentTargetString!)
let requiresObjCLinking = buildSettings["OTHER_LDFLAGS"]?.stringValue?.contains("-ObjC") ?? (productType == .staticLibrary)
let requiresObjCLinking = buildSettings["OTHER_LDFLAGS"]?.stringValue?.contains("-ObjC")
let dependencyTarget = Target(
name: targetObject.name,
type: productType,
Expand Down Expand Up @@ -765,7 +765,7 @@ public class PBXProjGenerator {
targetFrameworkBuildFiles.append(buildFile)

if !anyDependencyRequiresObjCLinking
&& dependencyTarget.requiresObjCLinking ?? (dependencyTarget.type == .staticLibrary) {
&& dependencyTarget.requiresObjCLinking ?? (dependencyLinkage == .static) {
anyDependencyRequiresObjCLinking = true
}
}
Expand Down
88 changes: 87 additions & 1 deletion Tests/XcodeGenKitTests/ProjectGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,57 @@ class ProjectGeneratorTests: XCTestCase {
dependencies: [Dependency(type: .target, reference: implicitlyRequiresObjCLinking.name)]
)

let targets = [requiresObjCLinking, doesntRequireObjCLinking, implicitlyRequiresObjCLinking, framework, app1, app2, app3]
let staticFramework = Target(
name: "staticFramework",
type: .staticFramework,
platform: .iOS
)
let machOStaticFramework = Target(
name: "machOStaticFramework",
type: .framework,
platform: .iOS,
settings: Settings(buildSettings: ["MACH_O_TYPE": "staticlib"])
)
let staticFrameworkOptOut = Target(
name: "staticFrameworkOptOut",
type: .staticFramework,
platform: .iOS,
requiresObjCLinking: false
)
let dynamicFramework = Target(
name: "dynamicFramework",
type: .framework,
platform: .iOS
)
let app4 = Target(
name: "app4",
type: .application,
platform: .iOS,
dependencies: [Dependency(type: .target, reference: staticFramework.name)]
)
let app5 = Target(
name: "app5",
type: .application,
platform: .iOS,
dependencies: [Dependency(type: .target, reference: machOStaticFramework.name)]
)
let app6 = Target(
name: "app6",
type: .application,
platform: .iOS,
dependencies: [Dependency(type: .target, reference: staticFrameworkOptOut.name)]
)
let app7 = Target(
name: "app7",
type: .application,
platform: .iOS,
dependencies: [Dependency(type: .target, reference: dynamicFramework.name)]
)

let targets = [
requiresObjCLinking, doesntRequireObjCLinking, implicitlyRequiresObjCLinking, framework, app1, app2, app3,
staticFramework, machOStaticFramework, staticFrameworkOptOut, dynamicFramework, app4, app5, app6, app7,
]

let project = Project(
basePath: fixturePath + "TestProject",
Expand Down Expand Up @@ -1302,6 +1352,42 @@ class ProjectGeneratorTests: XCTestCase {
try expect(app1OtherLinkerSettings.contains("-ObjC")) == true
try expect(app2OtherLinkerSettings.contains("-ObjC")) == false
try expect(app3OtherLinkerSettings.contains("-ObjC")) == true
let app4OtherLinkerSettings = try buildSettings(for: app4)["OTHER_LDFLAGS"]?.arrayValue ?? []
let app5OtherLinkerSettings = try buildSettings(for: app5)["OTHER_LDFLAGS"]?.arrayValue ?? []
let app6OtherLinkerSettings = try buildSettings(for: app6)["OTHER_LDFLAGS"]?.arrayValue ?? []
let app7OtherLinkerSettings = try buildSettings(for: app7)["OTHER_LDFLAGS"]?.arrayValue ?? []

try expect(app4OtherLinkerSettings.contains("-ObjC")) == true
try expect(app5OtherLinkerSettings.contains("-ObjC")) == true
try expect(app6OtherLinkerSettings.contains("-ObjC")) == false
try expect(app7OtherLinkerSettings.contains("-ObjC")) == false
}

$0.it("sets -ObjC for targets that depend on a static framework in an external project") {
let externalPath = try Path.uniqueTemporary()
defer { try? externalPath.delete() }

let externalProject = Project(
basePath: externalPath,
name: "ExternalProject",
targets: [Target(name: "ExternalStaticFramework", type: .staticFramework, platform: .iOS)]
)
let xcodeProject = try ProjectGenerator(project: externalProject).generateXcodeProject(userName: "someUser")
try FileWriter(project: externalProject).writeXcodeProject(xcodeProject)

var target = app
target.dependencies = [Dependency(type: .target, reference: "ExternalProject/ExternalStaticFramework")]
let project = Project(
name: "test",
targets: [target],
projectReferences: [
ProjectReference(name: "ExternalProject", path: (externalPath + "ExternalProject.xcodeproj").string),
]
)

let pbxProj = try project.generatePbxProj()
let buildConfig = try unwrap(pbxProj.targets(named: target.name).first?.buildConfigurationList?.buildConfigurations.first)
try expect(buildConfig.buildSettings["OTHER_LDFLAGS"]?.arrayValue?.contains("-ObjC") ?? false) == true
}

$0.it("filter sources with inferDestinationFiltersByPath") {
Expand Down
Loading