/// <summary> /// GGCPreprocessor設定(選填) /// </summary> protected void AddGGCPreprocessor() { Debug.Log("Start AddGGCPreprocessor"); PBXProject aPBXProject = GetPBXProject(); string aTargetGUID = aPBXProject.TargetGuidByName(cOutputProj); string aDebugConfGUID = aPBXProject.BuildConfigByName(aTargetGUID, "Debug"); string aReleaseConfGUID = aPBXProject.BuildConfigByName(aTargetGUID, "Release"); aPBXProject.AddBuildProperty(aTargetGUID, "GCC_PREPROCESSOR_DEFINITIONS", "PLATFORM_IOS=1"); aPBXProject.AddBuildPropertyForConfig(aDebugConfGUID, "GCC_PREPROCESSOR_DEFINITIONS", "DEBUG=1"); aPBXProject.AddBuildPropertyForConfig(aReleaseConfGUID, "GCC_PREPROCESSOR_DEFINITIONS", "RELEASE=1"); File.WriteAllText(mPBXProjFullPath, aPBXProject.WriteToString()); }
static void SetBuildFlagsFromDict(this PBXProject proj, string configGuid, IEnumerable <KeyValuePair <string, string> > data) { foreach (var kv in data) { proj.AddBuildPropertyForConfig(configGuid, kv.Key, kv.Value); } }
public static void OnPostprocessiOSBuild(BuildTarget target, string iBuiltProjectPath) { UtilsLog.Info("PostProcessor", "OnPostprocessiOSBuild()::Target:{0} ProPath:{1}", target.ToString(), iBuiltProjectPath); #if UNITY_EDITOR if (target != BuildTarget.iOS) { return; } const string funcBlock = "PostProcessor.OnPostprocessiOSBuild()"; BuildLogger.OpenBlock(funcBlock); const string TargetProjectName = "Unity-iPhone"; BuildSettings _buildSetting = BuildSettings.GetInstance(BuildSettings.AssetFileDir); if (null == _buildSetting) { return; } // 取得设定情报列表 XCSettingItem[] settings = _buildSetting.GetXCSettingInfo(TargetProjectName); if ((settings == null) || (settings.Length <= 0)) { BuildLogger.CloseBlock(); return; } string pbxprojPath = PBXProject.GetPBXProjectPath(iBuiltProjectPath); PBXProject project = new PBXProject(); project.ReadFromString(File.ReadAllText(pbxprojPath)); string targetGUID = project.TargetGuidByName(TargetProjectName); // BuildMode(debug/release/store) string debugConfigGUID = project.BuildConfigByName(targetGUID, "Debug"); string releaseConfigGUID = project.BuildConfigByName(targetGUID, "Release"); foreach (XCSettingItem item in settings) { switch (item.Type) { case TXCSettingInfoType.ReplaceSource: { foreach (string value in item.Value.LValue) { ReplaceSource(iBuiltProjectPath, value); BuildLogger.LogMessage("Replace Source {0} -> {1}", value, iBuiltProjectPath); } } break; case TXCSettingInfoType.FrameWorks: { foreach (string frameWork in item.Value.LValue) { #if UNITY_2017_1_OR_NEWER if (project.ContainsFramework(targetGUID, frameWork) == false) { #else if (project.HasFramework(frameWork) == false) { #endif project.AddFrameworkToProject(targetGUID, frameWork, false); BuildLogger.LogMessage("Add FrameWork -> {0}", frameWork); } } } break; case TXCSettingInfoType.Libraries: { foreach (string library in item.Value.LValue) { string fileGuid = project.AddFile("usr/lib/" + library, "Frameworks/" + library, PBXSourceTree.Sdk); project.AddFileToBuild(targetGUID, fileGuid); BuildLogger.LogMessage("Add Library -> {0}", library); } } break; case TXCSettingInfoType.IncludeFiles: { foreach (string file in item.Value.LValue) { string addFilePath = null; PreSetFileToProject(iBuiltProjectPath, file, ref addFilePath); if (string.IsNullOrEmpty(addFilePath) == false) { string fileGUID = project.AddFile(addFilePath, addFilePath, PBXSourceTree.Source); project.AddFileToBuild(targetGUID, fileGUID); BuildLogger.LogMessage("Add File -> {0}", file); } } } break; case TXCSettingInfoType.IncludeFolders: { foreach (string folder in item.Value.LValue) { string copyTo = null; string addDirReference = null; PreSetFolderToProject(iBuiltProjectPath, folder, ref copyTo, ref addDirReference); if ((string.IsNullOrEmpty(copyTo) == false) && (string.IsNullOrEmpty(addDirReference) == false)) { project.AddFolderReference(copyTo, addDirReference, PBXSourceTree.Source); BuildLogger.LogMessage("Add Folder -> {0}", folder); } } } break; case TXCSettingInfoType.Bool: { // Debug if (TXCBool.Yes == item.Debug.BValue) { project.SetBuildPropertyForConfig(debugConfigGUID, item.Key, "YES"); } else { project.SetBuildPropertyForConfig(debugConfigGUID, item.Key, "NO"); } BuildLogger.LogMessage("Add Bool(Debug) -> Key:{0} Value:{1}", item.Key, item.Debug.BValue.ToString()); // Release if (TXCBool.Yes == item.Release.BValue) { project.SetBuildPropertyForConfig(releaseConfigGUID, item.Key, "YES"); } else { project.SetBuildPropertyForConfig(releaseConfigGUID, item.Key, "NO"); } BuildLogger.LogMessage("Add Bool(Release) -> Key:{0} Value:{1}", item.Key, item.Release.BValue.ToString()); } break; case TXCSettingInfoType.String: { // Debug project.SetBuildPropertyForConfig(debugConfigGUID, item.Key, item.Debug.SValue); BuildLogger.LogMessage("Add String(Debug) -> Key:{0} Value:{1}", item.Key, item.Debug.SValue); // Release project.SetBuildPropertyForConfig(releaseConfigGUID, item.Key, item.Release.SValue); BuildLogger.LogMessage("Add String(Release) -> Key:{0} Value:{1}", item.Key, item.Release.SValue); } break; case TXCSettingInfoType.List: { // Debug foreach (string value in item.Debug.LValue) { project.AddBuildPropertyForConfig(debugConfigGUID, item.Key, value); BuildLogger.LogMessage("Add List(Debug) -> Key:{0} Item:{1}", item.Key, value); } // Release foreach (string value in item.Release.LValue) { project.AddBuildPropertyForConfig(releaseConfigGUID, item.Key, value); BuildLogger.LogMessage("Add List(Release) -> Key:{0} Item:{1}", item.Key, value); } } break; default: break; } } File.WriteAllText(pbxprojPath, project.WriteToString()); BuildLogger.CloseBlock(); #endif }
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); }
private static void AddPreprocessorDefinitions(PBXProject project, string targetGuid) { string configGuid = project.BuildConfigByName(targetGuid, "Debug"); project.AddBuildPropertyForConfig(configGuid, "GCC_PREPROCESSOR_DEFINITIONS", "ENABLE_INSTABUG"); }
public static void OnPostprocessiOSBuild(BuildTarget iTarget, string iBuiltProjectPath) { Loger.BuildStart("PostProcessor::OnPostprocessiOSBuild()"); Loger.Info($"Target:{iTarget} ProPath:{iBuiltProjectPath}"); // iOS if (iTarget != BuildTarget.iOS) { Loger.BuildEnd(); return; } const string targetProjectName = "Unity-iPhone"; var buildSetting = BuildSettings.GetInstance(BuildSettings.AssetFileDir); if (null == buildSetting) { return; } // 取得设定情报列表 var settings = buildSetting.GetXcSettingInfo(targetProjectName); if (settings == null || settings.Length <= 0) { Loger.BuildEnd(); return; } var pbxprojPath = PBXProject.GetPBXProjectPath(iBuiltProjectPath); var project = new PBXProject(); project.ReadFromString(File.ReadAllText(pbxprojPath)); var targetGuid = project.TargetGuidByName(targetProjectName); // BuildMode(debug/release/store) var debugGuid = project.BuildConfigByName(targetGuid, "Debug"); var releaseGuid = project.BuildConfigByName(targetGuid, "Release"); var releaseForProfilingGuid = project.BuildConfigByName(targetGuid, "ReleaseForProfiling"); var releaseForRunningGuid = project.BuildConfigByName(targetGuid, "ReleaseForRunning"); foreach (var item in settings) { switch (item.type) { case TxcSettingInfoType.ReplaceSource: { var list = item.Value.Values; if (list != null) { foreach (var value in list) { ReplaceSource(iBuiltProjectPath, Convert.ToString(value)); Loger.BuildLog($"Replace Source {value} -> {iBuiltProjectPath}"); } } } break; case TxcSettingInfoType.FrameWorks: { var list = item.Value.Values; if (list != null) { foreach (var frameWork in list) { var strTmp = Convert.ToString(frameWork); #if UNITY_2017_1_OR_NEWER if (project.ContainsFramework(targetGuid, strTmp) == false) { #else if (project.HasFramework(strTmp) == false) { #endif project.AddFrameworkToProject(targetGuid, strTmp, false); Loger.BuildLog($"Add FrameWork -> {strTmp}"); } } } } break; case TxcSettingInfoType.Libraries: { var list = item.Value.Values; if (list != null) { foreach (var library in list) { var strTmp = Convert.ToString(library); var fileGuid = project.AddFile("usr/lib/" + strTmp, "Frameworks/" + strTmp, PBXSourceTree.Sdk); project.AddFileToBuild(targetGuid, fileGuid); Loger.BuildLog($"Add Library -> {strTmp}"); } } } break; case TxcSettingInfoType.IncludeFiles: { var list = item.Value.Values; if (list != null) { foreach (var file in list) { var strTmp = Convert.ToString(file); string addFilePath = null; PreSetFileToProject(iBuiltProjectPath, strTmp, ref addFilePath); if (string.IsNullOrEmpty(addFilePath)) { continue; } var fileGuid = project.AddFile(addFilePath, addFilePath); project.AddFileToBuild(targetGuid, fileGuid); Loger.BuildLog($"Add File -> {strTmp}"); } } } break; case TxcSettingInfoType.IncludeFolders: { var list = item.Value.Values; if (list != null) { foreach (var folder in list) { var strTmp = Convert.ToString(folder); string copyTo = null; string addDirReference = null; PreSetFolderToProject(iBuiltProjectPath, strTmp, ref copyTo, ref addDirReference); if (string.IsNullOrEmpty(copyTo) || string.IsNullOrEmpty(addDirReference)) { continue; } project.AddFolderReference(copyTo, addDirReference); Loger.BuildLog($"Add Folder -> {strTmp}"); } } } break; case TxcSettingInfoType.Bool: { var debugValue = (TxcBool)item.Debug.Value; // Debug project.SetBuildPropertyForConfig(debugGuid, item.key, TxcBool.Yes == debugValue ? "YES" : "NO"); Loger.BuildLog($"Add Bool(Debug) -> Key:{item.key} Value:{(TxcBool.Yes == debugValue ? "YES" : "NO")}"); // Release var releaseValue = (TxcBool)item.Release.Value; project.SetBuildPropertyForConfig(releaseGuid, item.key, TxcBool.Yes == releaseValue ? "YES" : "NO"); Loger.BuildLog($"Add Bool(Release) -> Key:{item.key} Value:{(TxcBool.Yes == releaseValue ? "YES" : "NO")}"); // ReleaseForProfiling var releaseForProfilingValue = (TxcBool)item.ReleaseForProfiling.Value; project.SetBuildPropertyForConfig(releaseForProfilingGuid, item.key, TxcBool.Yes == releaseForProfilingValue ? "YES" : "NO"); Loger.BuildLog($"Add Bool(ReleaseForProfiling) -> Key:{item.key} Value:{(TxcBool.Yes == releaseValue ? "YES" : "NO")}"); // ReleaseForRunning var releaseForRunningValue = (TxcBool)item.ReleaseForRunning.Value; project.SetBuildPropertyForConfig(releaseForRunningGuid, item.key, TxcBool.Yes == releaseForRunningValue ? "YES" : "NO"); Loger.BuildLog($"Add Bool(ReleaseForRunning) -> Key:{item.key} Value:{(TxcBool.Yes == releaseValue ? "YES" : "NO")}"); } break; case TxcSettingInfoType.Enum: { // Debug var debugValue = $"{item.Debug.Value}"; if (false == string.IsNullOrEmpty(debugValue)) { project.SetBuildPropertyForConfig(debugGuid, item.key, debugValue); Loger.BuildLog($"Add String(Debug) -> Key:{item.key} Value:{debugValue}"); } // Release var releaseValue = $"{item.Release.Value}"; if (false == string.IsNullOrEmpty(releaseValue)) { project.SetBuildPropertyForConfig(releaseGuid, item.key, releaseValue); Loger.BuildLog($"Add String(Release) -> Key:{item.key} Value:{releaseValue}"); } // ReleaseForProfiling var releaseForProfilingValue = $"{item.ReleaseForProfiling.Value}"; if (false == string.IsNullOrEmpty(releaseForProfilingValue)) { project.SetBuildPropertyForConfig(releaseForProfilingGuid, item.key, releaseForProfilingValue); Loger.BuildLog($"Add String(ReleaseForProfiling) -> Key:{item.key} Value:{releaseForProfilingValue}"); } // ReleaseForRunning var releaseForRunningValue = $"{item.ReleaseForRunning.Value}"; if (false == string.IsNullOrEmpty(releaseForRunningValue)) { project.SetBuildPropertyForConfig(releaseForRunningGuid, item.key, releaseForRunningValue); Loger.BuildLog($"Add String(ReleaseForRunning) -> Key:{item.key} Value:{releaseForRunningValue}"); } } break; case TxcSettingInfoType.String: { // Debug var debugValue = item.Debug.Value as string; if (false == string.IsNullOrEmpty(debugValue)) { project.SetBuildPropertyForConfig(debugGuid, item.key, debugValue); Loger.BuildLog($"Add String(Debug) -> Key:{item.key} Value:{debugValue}"); } // Release var releaseValue = item.Release.Value as string; if (false == string.IsNullOrEmpty(releaseValue)) { project.SetBuildPropertyForConfig(releaseGuid, item.key, releaseValue); Loger.BuildLog($"Add String(Release) -> Key:{item.key} Value:{releaseValue}"); } // ReleaseForProfiling var releaseForProfilingValue = item.ReleaseForProfiling.Value as string; if (false == string.IsNullOrEmpty(releaseForProfilingValue)) { project.SetBuildPropertyForConfig(releaseForProfilingGuid, item.key, releaseForProfilingValue); Loger.BuildLog($"Add String(ReleaseForProfiling) -> Key:{item.key} Value:{releaseForProfilingValue}"); } // ReleaseForRunning var releaseForRunningValue = item.ReleaseForRunning.Value as string; if (false == string.IsNullOrEmpty(releaseForRunningValue)) { project.SetBuildPropertyForConfig(releaseForRunningGuid, item.key, releaseForRunningValue); Loger.BuildLog($"Add String(ReleaseForProfiling) -> Key:{item.key} Value:{releaseForRunningValue}"); } } break; case TxcSettingInfoType.List: { // Debug var debugValue = item.Debug.Value as List <string>; if (null != debugValue) { foreach (var value in debugValue) { project.AddBuildPropertyForConfig(debugGuid, item.key, value); Loger.BuildLog($"Add List(Debug) -> Key:{item.key} Item:{value}"); } } // Release var releaseValue = item.Release.Value as List <string>; if (null != releaseValue) { foreach (var value in releaseValue) { project.AddBuildPropertyForConfig(releaseGuid, item.key, value); Loger.BuildLog($"Add List(Release) -> Key:{item.key} Item:{value}"); } } // ReleaseForProfiling var releaseForProfilingValue = item.ReleaseForProfiling.Value as List <string>; if (null != releaseForProfilingValue) { foreach (var value in releaseForProfilingValue) { project.AddBuildPropertyForConfig(releaseForProfilingGuid, item.key, value); Loger.BuildLog($"Add List(ReleaseForProfiling) -> Key:{item.key} Item:{value}"); } } // ReleaseForRunning var releaseForRunningValue = item.ReleaseForRunning.Value as List <string>; if (null != releaseForRunningValue) { foreach (var value in releaseForRunningValue) { project.AddBuildPropertyForConfig(releaseForRunningGuid, item.key, value); Loger.BuildLog($"Add List(ReleaseForRunning) -> Key:{item.key} Item:{value}"); } } } break; case TxcSettingInfoType.None: break; default: Loger.BuildEnd(); throw new ArgumentOutOfRangeException(); } } File.WriteAllText(pbxprojPath, project.WriteToString()); Loger.BuildEnd(); }