/// <summary> /// Writes properties to the XCode framework /// </summary> /// <param name="pbxProject"></param> /// <param name="targetGUID"></param> /// <param name="pbxProjectPath"></param> /// <param name="pluginPath"></param> private static void WritePropertiesToFramework(PBXProject pbxProject, string targetGUID, string pbxProjectPath, string pluginPath, bool forceAlwaysEmbedSwiftStandardLibraries) { string privateModuleFilename = _privateModuleFilename; string pluginRelativePath = pluginPath.Substring(10, pluginPath.Length - 10); // remove 'Libraries/' // we look for manual path overrides MMNVPath pathDefinition = Resources.Load <MMNVPath>("MMNVPathDefinition"); if (pathDefinition != null) { if (pathDefinition.ModuleFileName != "") { privateModuleFilename = pathDefinition.ModuleFileName; } if (pathDefinition.PluginRelativePath != "") { pluginRelativePath = pathDefinition.PluginRelativePath; } } Debug.Log("[MMNVBuildPostProcessor] module relative path in Unity project: " + pluginRelativePath); // Full Path to copy from string module_map_filepath = pluginPath + privateModuleFilename; Debug.Log("[MMNVBuildPostProcessor] Adding properties to XCode framework, module path : " + module_map_filepath); pbxProject.AddFrameworkToProject(targetGUID, "CoreHaptics.framework", false); pbxProject.AddBuildProperty(targetGUID, "SWIFT_VERSION", "5.1"); pbxProject.SetBuildProperty(targetGUID, "ENABLE_BITCODE", "NO"); if (forceAlwaysEmbedSwiftStandardLibraries) { pbxProject.SetBuildProperty(targetGUID, "EMBEDDED_CONTENT_CONTAINS_SWIFT", "YES"); pbxProject.SetBuildProperty(targetGUID, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES"); } pbxProject.AddBuildProperty(targetGUID, "CLANG_ENABLE_MODULES", "YES"); pbxProject.AddBuildProperty(targetGUID, "SWIFT_INCLUDE_PATHS", pluginPath); pbxProject.AddBuildProperty(targetGUID, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks"); // we add a module reference to the pbx project string file_guid = pbxProject.AddFile(module_map_filepath, module_map_filepath, PBXSourceTree.Source); pbxProject.AddFileToBuild(targetGUID, file_guid); File.WriteAllText(pbxProjectPath, pbxProject.WriteToString()); // we copy the module file to the project string privateModuleFilepath = Application.dataPath + SEPARATOR + pluginRelativePath + SEPARATOR + privateModuleFilename; string projFileDir = System.IO.Path.GetDirectoryName(pbxProjectPath); string destination = projFileDir + SEPARATOR + ".." + SEPARATOR + module_map_filepath; if (!Directory.Exists(Path.GetDirectoryName(destination))) { Debug.Log("[MMNVBuildPostProcessor] Creating directory " + destination); Directory.CreateDirectory(Path.GetDirectoryName(destination)); } Debug.Log("[MMNVBuildPostProcessor] Copy module file to project : " + privateModuleFilepath + " -> " + destination); System.IO.File.Copy(privateModuleFilepath, destination); }
/// <summary> /// Grabs the MMNVPathDefinition asset /// </summary> public static void GetMMNVPath() { if (_mmnvPath == null) { _mmnvPath = Resources.Load <MMNVPath>("MMNVPathDefinition"); } if (_mmnvPath != null) { _forceSwiftForFramework = _mmnvPath.ForceAlwaysEmbedSwiftSLForFramework; _forceSwiftForMainTarget = _mmnvPath.ForceAlwaysEmbedSwiftSLForMainTarget; } }
public static void ConfigureXCodeProjectForNativePlugin(string xcodeProjectPath) { string pluginPath = GetPluginPath(); // we check if we can find a manual path override MMNVPath pathDefinition = Resources.Load <MMNVPath>("MMNVPathDefinition"); bool forceAlwaysEmbedSwiftStandardLibraries = false; bool alsoWriteToMainProject = false; if (pathDefinition != null) { if (pathDefinition.PluginPath != "") { pluginPath = pathDefinition.PluginPath; } forceAlwaysEmbedSwiftStandardLibraries = pathDefinition.ForceAlwaysEmbedSwiftStandardLibraries; alsoWriteToMainProject = pathDefinition.AlsoWriteToMainProject; } string pbxProjectPath = PBXProject.GetPBXProjectPath(xcodeProjectPath); PBXProject pbxProject = new PBXProject(); pbxProject.ReadFromString(File.ReadAllText(pbxProjectPath)); #if UNITY_2019_3_OR_NEWER string targetGUID = pbxProject.GetUnityFrameworkTargetGuid(); WritePropertiesToFramework(pbxProject, targetGUID, pbxProjectPath, pluginPath, forceAlwaysEmbedSwiftStandardLibraries); if (alsoWriteToMainProject) { targetGUID = pbxProject.GetUnityMainTargetGuid(); WritePropertiesToMainTarget(pbxProject, targetGUID, pbxProjectPath, pluginPath, forceAlwaysEmbedSwiftStandardLibraries); } #else string unityTargetName = PBXProject.GetUnityTargetName(); string targetGUID = pbxProject.TargetGuidByName(unityTargetName); WritePropertiesToProject(pbxProject, targetGUID, pbxProjectPath, pluginPath, forceAlwaysEmbedSwiftStandardLibraries); #endif File.WriteAllText(pbxProjectPath, pbxProject.WriteToString()); Debug.Log("[MMNVBuildPostProcessor] Post process complete."); }