@@ -933,6 +933,93 @@ pbxProject.prototype.hasFile = function(filePath) {
933933 return false ;
934934}
935935
936+ pbxProject . prototype . addTarget = function ( name , type ) {
937+
938+ // Setup uuid and name of new target
939+ var targetUuid = this . generateUuid ( ) ,
940+ targetType = type ,
941+ targetName = name . trim ( ) ;
942+
943+ // Check type against list of allowed target types
944+ if ( ! producttypeForTargettype ( targetType ) ) {
945+ console . error ( 'Invalid target type: ' + targetType ) ;
946+ return false
947+ }
948+
949+ // Build Configuration: Create
950+ var buildConfigurationsList = [
951+ {
952+ name : 'Debug' ,
953+ isa : 'XCBuildConfiguration' ,
954+ buildSettings : {
955+ GCC_PREPROCESSOR_DEFINITIONS : [ '"DEBUG=1"' , '"$(inherited)"' ] ,
956+ INFOPLIST_FILE : targetName + '-Info.Plist' ,
957+ LD_RUNPATH_SEARCH_PATHS : '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"' ,
958+ PRODUCT_NAME : targetName ,
959+ SKIP_INSTALL : 'YES'
960+ }
961+ } ,
962+ {
963+ name : 'Release' ,
964+ isa : 'XCBuildConfiguration' ,
965+ buildSettings : {
966+ INFOPLIST_FILE : targetName + '-Info.Plist' ,
967+ LD_RUNPATH_SEARCH_PATHS : '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"' ,
968+ PRODUCT_NAME : targetName ,
969+ SKIP_INSTALL : 'YES'
970+ }
971+ }
972+ ] ;
973+
974+ // Build Configuration: Add
975+ var buildConfigurations = this . addXCConfigurationList ( buildConfigurationsList , 'Release' , 'Build configuration list for PBXNativeTarget "' + targetName + '"' ) ,
976+ buildConfigurationsUuid = buildConfigurations . uuid ;
977+
978+ // Product: Create
979+ var productName = targetName ,
980+ productType = producttypeForTargettype ( targetType ) ,
981+ productFile = this . addProductFile ( productName , { 'explicitFileType' : productType } ) ,
982+ productFileName = productFile . basename ;
983+
984+ // Product: Embed in first target (only for "extension"-type targets)
985+ if ( targetType === 'app_extension' ) {
986+ var embedPhase ;
987+ var embedFile ;
988+
989+ // TODO: Add embedding via "PBXCopyFilesBuildPhase" build phase
990+ } ;
991+
992+ // Target: Create
993+ var target = {
994+ uuid : targetUuid ,
995+ pbxNativeTarget : {
996+ isa : 'PBXNativeTarget' ,
997+ name : targetName ,
998+ productName : targetName ,
999+ productReference : productFile . fileRef ,
1000+ productType : '"' + producttypeForTargettype ( targetType ) + '"' ,
1001+ buildConfigurationList : buildConfigurationsUuid ,
1002+ buildPhases : [ ] ,
1003+ buildRules : [ ] ,
1004+ dependencies : [ ]
1005+ }
1006+ } ;
1007+
1008+ // Target: Add to PBXNativeTarget section
1009+ this . addToPbxNativeTargetSection ( target )
1010+
1011+ // Target: Add uuid to root project
1012+ this . addToPbxProjectSection ( target ) ;
1013+
1014+ // Target: Add dependency for this target to first (main) target
1015+ this . addTargetDependency ( this . getFirstTarget ( ) . uuid , [ target . uuid ] ) ;
1016+
1017+
1018+ // Return target on success
1019+ return target ;
1020+
1021+ } ;
1022+
9361023// helper recursive prop search+replace
9371024function propReplace ( obj , prop , value ) {
9381025 var o = { } ;
0 commit comments