@@ -15,7 +15,8 @@ struct ProjectGenerator {
1515 private enum Constants {
1616 static let `extension` = " xcodeproj "
1717 }
18-
18+
19+
1920 // MARK: - Properties
2021
2122 let package : PackageInfo
@@ -24,19 +25,32 @@ struct ProjectGenerator {
2425 let dir = AbsolutePath ( self . package . projectBuildDirectory. path)
2526 return buildXcodeprojPath ( outputDir: dir, projectName: self . package . package . name)
2627 }
27-
28+
29+
2830 // MARK: - Initialisation
2931
3032 init ( package : PackageInfo ) {
3133 self . package = package
3234 }
33-
35+
36+
3437 // MARK: - Generation
3538
3639 /// Writes out the Xcconfig file
37- func writeXcconfig ( ) throws {
40+ func writeDistributionXcconfig ( ) throws {
3841 try makeDirectories ( self . projectPath)
39- try open ( AbsolutePath ( self . package . distributionBuildXcconfig. path) ) { stream in
42+
43+ let path = AbsolutePath ( self . package . distributionBuildXcconfig. path)
44+ try open ( path) { stream in
45+ if let absolutePath = self . package . overridesXcconfig? . path {
46+ stream (
47+ """
48+ #include " \( AbsolutePath ( absolutePath) . relative ( to: AbsolutePath ( path. dirname) ) . pathString) "
49+
50+ """
51+ )
52+ }
53+
4054 stream (
4155 """
4256 BUILD_LIBRARY_FOR_DISTRIBUTION=YES
@@ -59,19 +73,44 @@ struct ProjectGenerator {
5973 graph: self . package . graph,
6074 extraDirs: [ ] ,
6175 extraFiles: [ ] ,
62- options: XcodeprojOptions ( xcconfigOverrides: AbsolutePath ( self . package . distributionBuildXcconfig . path) ) ,
76+ options: XcodeprojOptions ( xcconfigOverrides: ( self . package . overridesXcconfig ? . path) . flatMap { AbsolutePath ( $0 ) } ) ,
6377 diagnostics: self . package . diagnostics
6478 )
6579
6680 return project
6781 }
82+
6883}
6984
7085
7186// MARK: - Saving Xcode Projects
7287
7388extension Xcode . Project {
7489
90+ /// This is the group that is normally created in Xcodeproj.xcodeProject() when you specify an xcconfigOverride
91+ var configGroup : Xcode . Group {
92+ let name = " Configs "
93+
94+ if let group = self . mainGroup. subitems. lazy. compactMap ( { $0 as? Xcode . Group } ) . first ( where: { $0. name == name } ) {
95+ return group
96+ }
97+
98+ // doesn't exist - lets creat it
99+ return self . mainGroup. addGroup ( path: " " , name: name)
100+ }
101+
102+ func enableDistribution ( targets: [ String ] , xcconfig: RelativePath ) throws {
103+ let group = self . configGroup
104+ let ref = group. addFileReference (
105+ path: xcconfig. pathString,
106+ name: xcconfig. basename
107+ )
108+
109+ for target in self . targets where targets. contains ( target. name) {
110+ target. buildSettings. xcconfigFileRef = ref
111+ }
112+ }
113+
75114 func save ( to path: AbsolutePath ) throws {
76115 try open ( path. appending ( component: " project.pbxproj " ) ) { stream in
77116 // Serialize the project model we created to a plist, and return
0 commit comments