in lib/pbxProject.js [1413:1554]
pbxProject.prototype.addTarget = function(name, type, subfolder, bundleId) {
// Setup uuid and name of new target
var targetUuid = this.generateUuid(),
targetType = type,
targetSubfolder = subfolder || name,
targetName = name.trim(),
targetBundleId = bundleId;
// Check type against list of allowed target types
if (!targetName) {
throw new Error("Target name missing.");
}
// Check type against list of allowed target types
if (!targetType) {
throw new Error("Target type missing.");
}
// Check type against list of allowed target types
if (!producttypeForTargettype(targetType)) {
throw new Error("Target type invalid: " + targetType);
}
// Build Configuration: Create
var buildConfigurationsList = [
{
name: 'Debug',
isa: 'XCBuildConfiguration',
buildSettings: {
GCC_PREPROCESSOR_DEFINITIONS: ['"DEBUG=1"', '"$(inherited)"'],
INFOPLIST_FILE: '"' + path.join(targetSubfolder, targetSubfolder + '-Info.plist' + '"'),
LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"',
PRODUCT_NAME: '"' + targetName + '"',
SKIP_INSTALL: 'YES'
}
},
{
name: 'Release',
isa: 'XCBuildConfiguration',
buildSettings: {
INFOPLIST_FILE: '"' + path.join(targetSubfolder, targetSubfolder + '-Info.plist' + '"'),
LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"',
PRODUCT_NAME: '"' + targetName + '"',
SKIP_INSTALL: 'YES'
}
}
];
// Add optional bundleId to build configuration
if (targetBundleId) {
buildConfigurationsList = buildConfigurationsList.map((elem) => {
elem.buildSettings.PRODUCT_BUNDLE_IDENTIFIER = '"' + targetBundleId + '"';
return elem;
});
}
// Build Configuration: Add
var buildConfigurations = this.addXCConfigurationList(buildConfigurationsList, 'Release', 'Build configuration list for PBXNativeTarget "' + targetName +'"');
// Product: Create
var productName = targetName,
productType = producttypeForTargettype(targetType),
productFileType = filetypeForProducttype(productType),
productFile = this.addProductFile(productName, { group: 'Copy Files', 'target': targetUuid, 'explicitFileType': productFileType}),
productFileName = productFile.basename;
// Product: Add to build file list
this.addToPbxBuildFileSection(productFile);
// Target: Create
var target = {
uuid: targetUuid,
pbxNativeTarget: {
isa: 'PBXNativeTarget',
name: '"' + targetName + '"',
productName: '"' + targetName + '"',
productReference: productFile.fileRef,
productType: '"' + producttypeForTargettype(targetType) + '"',
buildConfigurationList: buildConfigurations.uuid,
buildPhases: [],
buildRules: [],
dependencies: []
}
};
// Target: Add to PBXNativeTarget section
this.addToPbxNativeTargetSection(target)
// Product: Embed (only for "extension"-type targets)
if (targetType === 'app_extension') {
// Create CopyFiles phase in first target
this.addBuildPhase([], 'PBXCopyFilesBuildPhase', 'Copy Files', this.getFirstTarget().uuid, targetType)
// Add product to CopyFiles phase
this.addToPbxCopyfilesBuildPhase(productFile)
// this.addBuildPhaseToTarget(newPhase.buildPhase, this.getFirstTarget().uuid)
} else if (targetType === 'watch2_app') {
// Create CopyFiles phase in first target
this.addBuildPhase(
[targetName + '.app'],
'PBXCopyFilesBuildPhase',
'Embed Watch Content',
this.getFirstTarget().uuid,
targetType,
'"$(CONTENTS_FOLDER_PATH)/Watch"'
);
} else if (targetType === 'watch2_extension') {
// Create CopyFiles phase in watch target (if exists)
var watch2Target = this.getTarget(producttypeForTargettype('watch2_app'));
if (watch2Target) {
this.addBuildPhase(
[targetName + '.appex'],
'PBXCopyFilesBuildPhase',
'Embed App Extensions',
watch2Target.uuid,
targetType
);
}
}
// Target: Add uuid to root project
this.addToPbxProjectSection(target);
// Target: Add dependency for this target to other targets
if (targetType === 'watch2_extension') {
var watch2Target = this.getTarget(producttypeForTargettype('watch2_app'));
if (watch2Target) {
this.addTargetDependency(watch2Target.uuid, [target.uuid]);
}
} else {
this.addTargetDependency(this.getFirstTarget().uuid, [target.uuid]);
}
// Return target on success
return target;
};