0

In Unity, the excellent post processor makes it very easy to, say, add a build flag

on an iOS project...

public class BuildPostProcessor
{
    public static void OnPostProcessBuild(BuildTarget target, string path) ...

            PBXProject project = new PBXProject();
            string sPath = PBXProject.GetPBXProjectPath(path);

A "PBXProject" is literally "the .pbxproj file", that is to say, a plist text file.

It's then incredibly easy to for example

project.AddBuildProperty(g, "SOME_FLAG", "--whoa");

or add a framework, etc.

What about Mac desktop builds?

That's great for iOS builds, but how the heck do you "AddBuildProperty" on an OSX desktop project?

It seems there is NO "StandaloneProject" or similar structure.

How is this done?

I need to add OTHER_CODE_SIGN_FLAGS --deep. Presently I have to create the Xcode project and do it by hand every time. Surely there is a way to use Unity's excellent AddBuildProperty or similar calls, with, a desktop project?

Fattie
  • 27,874
  • 70
  • 431
  • 719
  • It turns out that presently, Unity just don't expose any post-processing handling for mac desktop ... sigh – Fattie Dec 18 '20 at 13:05

1 Answers1

0

Here's one messy way to get it done:

using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;

public class BuildPostProcessor
{

    [PostProcessBuildAttribute(1)]
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        if (target == BuildTarget.StandaloneOSX)
        {
            string macStylePath = path + "/project.pbxproj";

            string s = File.ReadAllText(macStylePath);
            s = s.Replace(
                "CODE_SIGN_STYLE = Automatic;",
                "CODE_SIGN_STYLE = Automatic;\n\t\t\tOTHER_CODE_SIGN_FLAGS = --deep;");

            File.Delete(macStylePath);
            File.WriteAllText(macStylePath, s);
            Debug.Log("OnPostProcessBuild ... added that flag'");
        }
    }
}

There's no really clean way to get at the guts of those files, so just do a grep on a relevant item, where you want to add something. It works.

Fattie
  • 27,874
  • 70
  • 431
  • 719