diff --git a/Source/Engine/Audio/Audio.Build.cs b/Source/Engine/Audio/Audio.Build.cs index e0bb24ed3..64df9f7dc 100644 --- a/Source/Engine/Audio/Audio.Build.cs +++ b/Source/Engine/Audio/Audio.Build.cs @@ -54,8 +54,8 @@ public class Audio : EngineModule options.SourcePaths.Add(Path.Combine(Globals.EngineRoot, "Source", "Platforms", "PS5", "Engine", "Audio")); options.CompileEnv.PreprocessorDefinitions.Add("AUDIO_API_PS5"); break; - case TargetPlatform.Mac: - useNone = true; // TODO: Audio support on Mac + case TargetPlatform.Mac: + useOpenAL = true; break; default: throw new InvalidPlatformException(options.Platform.Target); } @@ -85,6 +85,12 @@ public class Audio : EngineModule options.OutputFiles.Add(Path.Combine(depsRoot, "libopenal.a")); options.Libraries.Add("OpenSLES"); break; + case TargetPlatform.Mac: + options.OutputFiles.Add(Path.Combine(depsRoot, "libopenal.a")); + options.Libraries.Add("CoreAudio.framework"); + options.Libraries.Add("AudioUnit.framework"); + options.Libraries.Add("AudioToolbox.framework"); + break; default: throw new InvalidPlatformException(options.Platform.Target); } } diff --git a/Source/Platforms/Mac/Binaries/ThirdParty/x64/libopenal.a b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libopenal.a new file mode 100644 index 000000000..7d293b971 --- /dev/null +++ b/Source/Platforms/Mac/Binaries/ThirdParty/x64/libopenal.a @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16e3a75cde5920b0eabc918e74691aa934775cbb22ac28bb0673cebabc998fae +size 1106264 diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs b/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs index 50061dfaf..6e9a38a75 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs @@ -34,6 +34,11 @@ namespace Flax.Deps.Dependencies TargetPlatform.Linux, TargetPlatform.Android, }; + case TargetPlatform.Mac: + return new[] + { + TargetPlatform.Mac, + }; default: return new TargetPlatform[0]; } } @@ -63,7 +68,7 @@ namespace Flax.Deps.Dependencies } // Deploy Win64 binaries - var depsFolder = GetThirdPartyFolder(options, TargetPlatform.Windows, TargetArchitecture.x64); + var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.x64); Utilities.FileCopy(Path.Combine(root, "bin", "Win64", "soft_oal.dll"), Path.Combine(depsFolder, "OpenAL32.dll")); Utilities.FileCopy(Path.Combine(root, "libs", "Win64", "OpenAL32.lib"), Path.Combine(depsFolder, "OpenAL32.lib")); @@ -106,7 +111,7 @@ namespace Flax.Deps.Dependencies // Build for Linux Utilities.Run("cmake", "-G \"Unix Makefiles\" -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DLIBTYPE=STATIC " + config + " ..", null, buildDir, Utilities.RunOptions.None, envVars); Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.None, envVars); - var depsFolder = GetThirdPartyFolder(options, TargetPlatform.Linux, TargetArchitecture.x64); + var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.x64); foreach (var file in binariesToCopy) Utilities.FileCopy(Path.Combine(buildDir, file), Path.Combine(depsFolder, file)); break; @@ -140,9 +145,36 @@ namespace Flax.Deps.Dependencies SetupDirectory(buildDir, true); // Build - RunCmake(buildDir, TargetPlatform.Android, TargetArchitecture.ARM64, ".. -DLIBTYPE=STATIC -DCMAKE_BUILD_TYPE=Release " + config); + RunCmake(buildDir, platform, TargetArchitecture.ARM64, ".. -DLIBTYPE=STATIC -DCMAKE_BUILD_TYPE=Release " + config); Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.None); - var depsFolder = GetThirdPartyFolder(options, TargetPlatform.Android, TargetArchitecture.ARM64); + var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.ARM64); + foreach (var file in binariesToCopy) + Utilities.FileCopy(Path.Combine(buildDir, file), Path.Combine(depsFolder, file)); + break; + } + case TargetPlatform.Mac: + { + var binariesToCopy = new[] + { + "libopenal.a", + }; + var config = "-DALSOFT_REQUIRE_COREAUDIO=ON -DALSOFT_EMBED_HRTF_DATA=YES"; + + // Get the source + var packagePath = Path.Combine(root, "package.zip"); + File.Delete(packagePath); + Downloader.DownloadFileFromUrlToPath("https://openal-soft.org/openal-releases/openal-soft-" + version + ".tar.bz2", packagePath); + Utilities.Run("tar", "xjf " + packagePath.Replace('\\', '/'), null, root, Utilities.RunOptions.None); + + // Use separate build directory + root = Path.Combine(root, "openal-soft-" + version); + var buildDir = Path.Combine(root, "build"); + SetupDirectory(buildDir, true); + + // Build for Mac + RunCmake(buildDir, platform, TargetArchitecture.x64, ".. -DLIBTYPE=STATIC -DCMAKE_BUILD_TYPE=Release " + config); + Utilities.Run("cmake", "--build .", null, buildDir, Utilities.RunOptions.None); + var depsFolder = GetThirdPartyFolder(options, platform, TargetArchitecture.x64); foreach (var file in binariesToCopy) Utilities.FileCopy(Path.Combine(buildDir, file), Path.Combine(depsFolder, file)); break;