コード例 #1
0
    public static void PatchXcodeProject(string pathToBuiltProject)
    {
        PBXProject project = new PBXProject();

        string projectPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);

        projectPath = checkPBXProjectPath(projectPath);

        project.ReadFromFile(projectPath);

        string guid = project.TargetGuidByName("Unity-iPhone");

        foreach (var frameworkName in frameworksToAdd)
        {
            project.AddFrameworkToProject(guid, frameworkName, false);
        }

        bool useAsExternalProject = false;

        if (useAsExternalProject)
        {
            // this will add BridgeEngine.xcodeproj to current workspace, so we can rebuild it as dependency
            string bridgeEngineProjPath = Path.GetFullPath("../../Frameworks/BridgeEngine.xcodeproj");
            project.AddExternalProjectDependency(bridgeEngineProjPath, "BridgeEngine.xcodeproj", PBXSourceTree.Absolute);

            project.AddBuildProperty(guid, "HEADER_SEARCH_PATHS", "\"" +
                                     Path.GetFullPath("../../Frameworks/BridgeEngine/Headers") + "\"" +
                                     " \"" + Path.GetFullPath("../../Frameworks/BridgeEngine/Headers/Structure/Private") + "\"");
        }
        else
        {
            var filename = "Frameworks/BridgeEngine/Plugins/iOS/BridgeEngine.framework";

            var fileGuid = project.FindFileGuidByProjectPath(filename);
            if (fileGuid == null)
            {
                fileGuid = project.FindFileGuidByRealPath(filename);
            }
            if (fileGuid == null)
            {
                throw new System.Exception("Cannot find " + filename + " framework. EmbedFramework failed");
            }

            // this will just embed existing framework. framework should be up-to-date
            project.EmbedFramework(guid, fileGuid);

            // For Structure Partners
            project.AddBuildProperty(guid, "HEADER_SEARCH_PATHS",
                                     "\"$(SRCROOT)/Frameworks/BridgeEngine/Plugins/iOS/BridgeEngine.framework/extra-Headers\"");

            project.AddBuildProperty(guid, "HEADER_SEARCH_PATHS",
                                     "\"$(SRCROOT)/Frameworks/BridgeEngine/Plugins/iOS/BridgeEngine.framework/extra-Headers/Structure/Private\"");
        }

        project.AddFileToBuild(guid, project.AddFile("usr/lib/libz.dylib", "Frameworks/libz.dylib", PBXSourceTree.Sdk));

        string projectFolderForAsset = "Libraries/BridgeEngine/Plugins/iOS";

        Directory.CreateDirectory(Path.Combine(pathToBuiltProject, projectFolderForAsset));

        // Copy and install any assets we need for the plugin.
        foreach (var assetToCopy in assetsToCopy)
        {
            string assetPath               = "Assets/BridgeEngine/Plugins/iOS/" + assetToCopy;
            string projectPathForAsset     = Path.Combine(projectFolderForAsset, assetToCopy);
            string srcAssetPath            = Path.GetFullPath(assetPath);
            string destProjectPathForAsset = Path.Combine(pathToBuiltProject, projectPathForAsset);
            FileUtil.CopyFileOrDirectory(srcAssetPath, destProjectPathForAsset);

            string guidAsset = project.AddFile(projectPathForAsset, projectPathForAsset);
            project.AddFileToBuild(guid, guidAsset);
        }

        // The following settings lead to a quicker build
        string debugConfig   = project.BuildConfigByName(guid, "Debug");
        string releaseConfig = project.BuildConfigByName(guid, "Release");
        // string releaseForProfilingConfig = project.BuildConfigByName(guid, "ReleaseForProfiling");
        // string releaseForRunningConfig = project.BuildConfigByName(guid, "ReleaseForRunning");

        var releaseConfigurations = new string[] { releaseConfig };      //, releaseForProfilingConfig, releaseForRunningConfig};

        foreach (var config in releaseConfigurations)
        {
            project.SetBuildPropertyForConfig(config, "DEBUG_INFORMATION_FORMAT", "dwarf");
            project.SetBuildPropertyForConfig(config, "ONLY_ACTIVE_ARCH", "YES");
            project.SetBuildPropertyForConfig(config, "ENABLE_BITCODE", "NO");
            project.SetBuildPropertyForConfig(config, "GCC_PREPROCESSOR_DEFINITIONS", "$(inherited)");

#if UNITY_HAS_GOOGLEVR
            if (PlayerSettings.virtualRealitySupported)
            {
                project.AddBuildPropertyForConfig(config, "OTHER_CFLAGS", "-DUNITY_HAS_GOOGLEVR=1");
            }
#endif
        }

        // XCode7 enables BitCode for all projects by default.  Neither the Structure SDK nor Unity support BitCode at this time
        project.SetBuildPropertyForConfig(debugConfig, "ENABLE_BITCODE", "NO");
        project.SetBuildPropertyForConfig(debugConfig, "GCC_PREPROCESSOR_DEFINITIONS", "$(inherited)");

        // we need to define DEBUG=1 to build properly
        project.AddBuildPropertyForConfig(debugConfig, "GCC_PREPROCESSOR_DEFINITIONS", "DEBUG=1");

#if UNITY_HAS_GOOGLEVR
        // We need UNITY_HAS_GOOGLEVR if native GoogleVR is enabled.
        if (PlayerSettings.virtualRealitySupported)
        {
            project.AddBuildPropertyForConfig(debugConfig, "OTHER_CFLAGS", "-DUNITY_HAS_GOOGLEVR=1");
        }
#endif

        // StructurePartners uses gnu++14. This also makes GLK easier to use.
        project.SetBuildProperty(guid, "CLANG_CXX_LANGUAGE_STANDARD", "gnu++14");

        project.WriteToFile(projectPath);
    }