using UnityEngine;
namespace StansAssets.IOS.XCode
{
///
/// The main enter point for the XCode project setup.
///
public static class XCodeProject
{
///
/// Capability Settings.
///
public static XCodeCapabilitySettings Capability => XCodeProjectSettings.Instance.Capability;
///
/// Project Settings.
///
public static XCodeProjectSettings Settings => XCodeProjectSettings.Instance;
///
/// Sets a build property to the given value in all build configurations.
///
/// The name of the build property. Example: "ENABLE_BITCODE"
/// The value of the build property. Example: "NO"
public static void SetBuildProperty(string name, string value)
{
SetBuildProperty(new XCodeProjectProperty(name, value));
}
///
/// Sets a build property to the given value in all build configurations.
///
/// Property object instance.
public static void SetBuildProperty(XCodeProjectProperty property)
{
foreach (var p in XCodeProjectSettings.Instance.BuildProperties)
if (p.Name.Equals(property.Name))
{
XCodeProjectSettings.Instance.BuildProperties.Remove(p);
break;
}
XCodeProjectSettings.Instance.BuildProperties.Add(property);
}
///
/// Removes the build property.
///
/// Build property.
public static void RemoveBuildProperty(XCodeProjectProperty property)
{
RemoveBuildProperty(property.Name);
}
///
/// Removes the build property.
///
/// Property name.
public static void RemoveBuildProperty(string name)
{
foreach (var p in XCodeProjectSettings.Instance.BuildProperties)
if (p.Name.Equals(name))
{
XCodeProjectSettings.Instance.BuildProperties.Remove(p);
break;
}
}
//--------------------------------------
// Info.plist
//--------------------------------------
///
/// Method will add or replace new to the Info.plist keys
///
/// Info.plist key name
public static void SetInfoPlistKey(InfoPlistKey key)
{
var infoPlistKey = GetInfoPlistKey(key.Name);
if (infoPlistKey != null) XCodeProjectSettings.Instance.PlistVariables.Remove(infoPlistKey);
XCodeProjectSettings.Instance.PlistVariables.Add(key);
}
///
/// Get's instance by it's name
///
/// Info.plist key name
public static InfoPlistKey GetInfoPlistKey(string name)
{
foreach (var v in XCodeProjectSettings.Instance.PlistVariables)
if (v.Name.Equals(name))
return v;
return null;
}
///
/// Returns true if this key already exists inside Info.plist
///
/// Info.plist key name
public static bool ContainsKey(string name)
{
return GetInfoPlistKey(name) != null;
}
///
/// Removes Info.plist key
///
/// Info.plist key
public static void RemoveInfoPlistKey(InfoPlistKey key)
{
RemoveInfoPlistKey(key.Name);
}
///
/// Removes Info.plist key
///
/// Info.plist key name
public static void RemoveInfoPlistKey(string name)
{
var key = GetInfoPlistKey(name);
if (key != null) XCodeProjectSettings.Instance.RemoveVariable(key, XCodeProjectSettings.Instance.PlistVariables);
}
///
/// Adds compiler or linker flag to the build configuration
///
/// flag name.
/// flag type.
public static void AddFlag(string name, XCodeFlagType type)
{
foreach (var flag in XCodeProjectSettings.Instance.Flags)
if (flag.Type == type && flag.Name.Equals(name))
return;
var newFlag = new XCodeProjectFlag();
newFlag.Name = name;
newFlag.Type = XCodeFlagType.LinkerFlag;
XCodeProjectSettings.Instance.Flags.Add(newFlag);
}
///
/// Removes the flag.
///
/// Flag name.
public static void RemoveFlag(string name)
{
foreach (var flag in XCodeProjectSettings.Instance.Flags)
if (flag.Name.Equals(name))
{
XCodeProjectSettings.Instance.Flags.Remove(flag);
return;
}
}
///
/// Adds a system framework dependency.
///
/// The function assumes system frameworks are located in System/Library/Frameworks folder
/// in the SDK source tree. The framework is added to Frameworks logical folder in the project.
///
/// The name of the framework.
/// True if the framework is optional (i.e. weakly linked), false if the framework is required.
public static void AddFramework(XCodeFrameworkName frameworkName, bool weak = false)
{
AddFramework(new XCodeFramework(frameworkName, weak));
}
///
/// Adds a system framework dependency.
///
/// The function assumes system frameworks are located in System/Library/Frameworks folder
/// in the SDK source tree. The framework is added to Frameworks logical folder in the project.
///
/// framework configuration object
public static void AddFramework(XCodeFramework framework)
{
foreach (var item in XCodeProjectSettings.Instance.Frameworks)
if (item.FrameworkName == framework.FrameworkName)
{
XCodeProjectSettings.Instance.Frameworks.Remove(item);
break;
}
XCodeProjectSettings.Instance.Frameworks.Add(framework);
}
///
/// Removes the framework.
///
/// Framework type
public static void RemoveFramework(XCodeFrameworkName frameworkName)
{
foreach (var item in XCodeProjectSettings.Instance.Frameworks)
if (item.FrameworkName == frameworkName)
{
XCodeProjectSettings.Instance.Frameworks.Remove(item);
break;
}
}
///
/// Adds a system library dependency.
///
/// The function assumes system library are located in System/Library/Frameworks folder
/// in the SDK source tree. The library is added to Frameworks logical folder in the project.
///
/// The name of the library.
/// True if the framework is optional (i.e. weakly linked), false if the framework is required.
public static void AddLibrary(XCodeLibraryName libraryName, bool weak = false)
{
AddLibrary(new XCodeLibrary(libraryName, weak));
}
///
/// Adds a system library dependency.
///
/// The function assumes system library are located in System/Library/Frameworks folder
/// in the SDK source tree. The library is added to Frameworks logical folder in the project.
///
/// library configuration object
public static void AddLibrary(XCodeLibrary library)
{
foreach (var item in XCodeProjectSettings.Instance.Libraries)
if (item.Name == library.Name)
{
XCodeProjectSettings.Instance.Libraries.Remove(item);
break;
}
XCodeProjectSettings.Instance.Libraries.Add(library);
}
///
/// Removes the library.
///
/// Library type.
public static void RemoveLibrary(XCodeLibraryName libraryName)
{
foreach (var item in XCodeProjectSettings.Instance.Libraries)
if (item.Name == libraryName)
{
XCodeProjectSettings.Instance.Libraries.Remove(item);
break;
}
}
///
/// Method that allow to check if certain asset was already added to the Xcode project.
///
/// A reference to the asset.
/// Returns `true` if asset is added and `false` otherwise.
public static bool HasFile(Object asset)
{
foreach (var assetFile in XCodeProjectSettings.Instance.Files)
if (assetFile.Asset.Equals(asset))
return true;
return false;
}
///
/// Adds asset copy step.
///
/// A reference to the asset that will be copied.
/// The Xcode project related path of where to copy the file. Will copy in the project root by default.
public static void AddFile(Object asset, string xCodePath = "")
{
var file = new XCodeAsset();
file.Asset = asset;
file.XCodePath = xCodePath;
AddFile(file);
}
///
/// Adds asset copy step.
///
/// Asset model to copy.
public static void AddFile(XCodeAsset asset)
{
foreach (var assetFile in XCodeProjectSettings.Instance.Files)
if (assetFile.Asset.Equals(asset.Asset))
{
XCodeProjectSettings.Instance.Files.Remove(assetFile);
break;
}
XCodeProjectSettings.Instance.Files.Add(asset);
}
}
}