Add targetName to paramter to getBuildProperty (#109)

* Add targetName to parameter to getBuildProperty
* Update lib/pbxProject.js

Co-authored-by: Tim Brust <github@timbrust.de>
diff --git a/lib/pbxProject.js b/lib/pbxProject.js
index d39bf8d..068548a 100644
--- a/lib/pbxProject.js
+++ b/lib/pbxProject.js
@@ -2068,11 +2068,34 @@
 
 
 
-pbxProject.prototype.getBuildProperty = function(prop, build) {
+pbxProject.prototype.getBuildProperty = function(prop, build, targetName) {
     var target;
+    let validConfigs = [];
+
+    if (targetName) {
+        const target = this.pbxTargetByName(targetName);
+        const targetBuildConfigs = target && target.buildConfigurationList;
+
+        const xcConfigList = this.pbxXCConfigurationList();
+
+        // Collect the UUID's from the configuration of our target
+        for (const configName in xcConfigList) {
+            if (!COMMENT_KEY.test(configName) && targetBuildConfigs === configName) {
+                const buildVariants = xcConfigList[configName].buildConfigurations;
+
+                for (const item of buildVariants) {
+                    validConfigs.push(item.value);
+                }
+
+                break;
+            }
+        }
+    }
+    
     var configs = this.pbxXCBuildConfigurationSection();
     for (var configName in configs) {
         if (!COMMENT_KEY.test(configName)) {
+            if (targetName && !validConfigs.includes(configName)) continue;
             var config = configs[configName];
             if ( (build && config.name === build) || (build === undefined) ) {
                 if (config.buildSettings[prop] !== undefined) {
diff --git a/test/pbxProject.js b/test/pbxProject.js
index 96efc26..aca2927 100644
--- a/test/pbxProject.js
+++ b/test/pbxProject.js
@@ -214,6 +214,34 @@
     }
 }
 
+exports['getBuildProperty function'] = {
+    setUp:function(callback) {
+        callback();
+    },
+    tearDown:function(callback) {
+        fs.writeFileSync(bcpbx, original_pbx, 'utf-8');
+        callback();
+    },
+    'should change all targets in .pbxproj with multiple targets': function (test) {
+        var myProj = new pbx('test/parser/projects/multitarget.pbxproj');
+        myProj.parse(function(err, hash) {
+            myProj.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', 'comcompanytest');
+            myProj.writeSync();
+            test.ok(myProj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER') === 'comcompanytest');
+            test.done();
+        });
+    },
+    'should change only one target in .pbxproj with multiple targets': function (test) {
+        var myProj = new pbx('test/parser/projects/multitarget.pbxproj');
+        myProj.parse(function(err, hash) {
+            myProj.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', 'comcompanytest', null, 'MultiTargetTest');
+            myProj.writeSync();
+            test.ok(myProj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', undefined, 'MultiTargetTest') === 'comcompanytest');
+            test.done();
+        });
+    }
+}
+
 exports['addBuildProperty function'] = {
     setUp:function(callback) {
         callback();