WwiseUEPlatform.Build.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. using UnrealBuildTool;
  16. using System;
  17. using System.IO;
  18. using System.Collections.Generic;
  19. #if UE_5_3_OR_LATER
  20. using Microsoft.Extensions.Logging;
  21. #elif UE_5_0_OR_LATER
  22. using EpicGames.Core;
  23. #else
  24. using Tools.DotNETCommon;
  25. #endif
  26. // Platform-specific files implement this interface, returning their particular dependencies, defines, etc.
  27. public abstract class WwiseUEPlatform
  28. {
  29. protected ReadOnlyTargetRules Target;
  30. protected string ThirdPartyFolder;
  31. #if UE_5_3_OR_LATER
  32. private ILogger Logger => Target.Logger;
  33. #endif
  34. public WwiseUEPlatform(ReadOnlyTargetRules in_Target, string in_ThirdPartyFolder)
  35. {
  36. Target = in_Target;
  37. ThirdPartyFolder = in_ThirdPartyFolder;
  38. }
  39. public bool IsWwiseTargetSupported()
  40. {
  41. var platformPath = Path.Combine(ThirdPartyFolder, AkPlatformLibDir);
  42. var hasPlatform = Directory.Exists(platformPath);
  43. var supportedTargetType = Target.Type != TargetRules.TargetType.Server && Target.Type != TargetRules.TargetType.Program;
  44. #if UE_5_3_OR_LATER
  45. if (!supportedTargetType)
  46. {
  47. Logger.LogInformation("Wwise SoundEngine is disabled: Using the null SoundEngine instead. Unsupported {Target} target type for Wwise SoundEngine", Target.Type.ToString());
  48. }
  49. else if (!hasPlatform)
  50. {
  51. Logger.LogInformation("Wwise SoundEngine is disabled: Using the null SoundEngine instead. Could not find the {Platform} platform folder in ThirdParty", AkPlatformLibDir.ToString());
  52. }
  53. #else
  54. if (!supportedTargetType)
  55. {
  56. Log.TraceInformation("Wwise SoundEngine is disabled: Using the null SoundEngine instead. Unsupported {0} target type for Wwise SoundEngine", Target.Type.ToString());
  57. }
  58. else if (!hasPlatform)
  59. {
  60. Log.TraceInformation("Wwise SoundEngine is disabled: Using the null SoundEngine instead. Could not find the {0} platform folder in ThirdParty", AkPlatformLibDir.ToString());
  61. }
  62. #endif
  63. return hasPlatform && supportedTargetType;
  64. }
  65. public static WwiseUEPlatform GetWwiseUEPlatformInstance(ReadOnlyTargetRules Target, string VersionNumber, string ThirdPartyFolder)
  66. {
  67. var WwiseUEPlatformType = System.Type.GetType(
  68. VersionNumber == "Null" ? "WwiseUEPlatform_Null" :
  69. "WwiseUEPlatform_" + VersionNumber + "_" + Target.Platform.ToString());
  70. if (WwiseUEPlatformType == null)
  71. {
  72. throw new BuildException("Wwise does not support platform " + Target.Platform.ToString() + " on " + VersionNumber);
  73. }
  74. var PlatformInstance = Activator.CreateInstance(WwiseUEPlatformType, Target, ThirdPartyFolder) as WwiseUEPlatform;
  75. if (PlatformInstance == null)
  76. {
  77. throw new BuildException("Wwise could not instantiate platform " + Target.Platform.ToString() + " on " + VersionNumber);
  78. }
  79. return PlatformInstance;
  80. }
  81. protected static List<string> GetAllLibrariesInFolder(string LibFolder, string Extension, bool RemoveLibPrefix = true, bool GetFullPath = false)
  82. {
  83. List<string> ret = null;
  84. var FoundLibs = Directory.GetFiles(LibFolder, "*."+Extension);
  85. if (GetFullPath)
  86. {
  87. ret = new List<string>(FoundLibs);
  88. }
  89. else
  90. {
  91. ret = new List<string>();
  92. foreach (var Library in FoundLibs)
  93. {
  94. var LibName = Path.GetFileNameWithoutExtension(Library);
  95. if (RemoveLibPrefix && LibName.StartsWith("lib"))
  96. {
  97. LibName = LibName.Remove(0, 3);
  98. }
  99. ret.Add(LibName);
  100. }
  101. }
  102. ret.Sort();
  103. return ret;
  104. }
  105. /// <summary>
  106. /// Wwise Target Configuration based on Unreal Target Configuration.
  107. /// </summary>
  108. public string WwiseConfiguration
  109. {
  110. get
  111. {
  112. switch (Target.Configuration)
  113. {
  114. case UnrealTargetConfiguration.Debug:
  115. case UnrealTargetConfiguration.DebugGame:
  116. return "Debug";
  117. case UnrealTargetConfiguration.Development:
  118. default:
  119. return "Profile";
  120. case UnrealTargetConfiguration.Test:
  121. case UnrealTargetConfiguration.Shipping:
  122. return "Release";
  123. }
  124. }
  125. }
  126. /// <summary>
  127. /// Wwise Library's Configuration folder (e.g.: ThirdParty/Platform/ConfigurationDir/lib).
  128. /// </summary>
  129. public virtual string WwiseConfigurationDir
  130. {
  131. get
  132. {
  133. return WwiseConfiguration;
  134. }
  135. }
  136. /// <summary>
  137. /// Wwise Library's DSP folder (e.g.: ThirdParty/Platform/DspDir/bin).
  138. /// </summary>
  139. public virtual string WwiseDspDir
  140. {
  141. get
  142. {
  143. return WwiseConfiguration;
  144. }
  145. }
  146. public abstract string GetLibraryFullPath(string LibName, string LibPath);
  147. public abstract bool SupportsAkAutobahn { get; }
  148. public abstract bool SupportsCommunication { get; }
  149. public abstract bool SupportsDeviceMemory { get; }
  150. public abstract string AkPlatformLibDir { get; }
  151. public abstract string DynamicLibExtension { get; }
  152. public virtual bool SupportsOpus { get { return true; } }
  153. public virtual List<string> GetPublicLibraryPaths()
  154. {
  155. return new List<string>
  156. {
  157. Path.Combine(ThirdPartyFolder, AkPlatformLibDir, WwiseConfigurationDir, "lib")
  158. };
  159. }
  160. public virtual List<string> GetRuntimeDependencies()
  161. {
  162. string PluginsDir = WwiseDspDir;
  163. List<string> Result = GetAllLibrariesInFolder(Path.Combine(ThirdPartyFolder, AkPlatformLibDir, WwiseDspDir, "bin"), DynamicLibExtension, false, true);
  164. return Result;
  165. }
  166. public abstract List<string> GetAdditionalWwiseLibs();
  167. public abstract List<string> GetPublicSystemLibraries();
  168. public abstract List<string> GetPublicDelayLoadDLLs();
  169. public abstract List<string> GetPublicDefinitions();
  170. public abstract Tuple<string, string> GetAdditionalPropertyForReceipt(string ModuleDirectory);
  171. public abstract List<string> GetPublicFrameworks();
  172. public virtual List<string> GetSanitizedAkLibList(List<string> AkLibs)
  173. {
  174. List<string> SanitizedLibs = new List<string>();
  175. foreach(var lib in AkLibs)
  176. {
  177. foreach(var libPath in GetPublicLibraryPaths())
  178. {
  179. SanitizedLibs.Add(GetLibraryFullPath(lib, libPath));
  180. }
  181. }
  182. return SanitizedLibs;
  183. }
  184. }