Skip to content

Commit 6c47c1e

Browse files
committed
Add UWP support.
1 parent 8dee296 commit 6c47c1e

File tree

4 files changed

+67
-24
lines changed

4 files changed

+67
-24
lines changed

Editor/CompileCesiumForUnityNative.cs

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ internal struct PlatformToBuild
2222
public bool isCleanBuild;
2323
}
2424

25+
internal enum LibraryCpuArchitecture
26+
{
27+
x86_64,
28+
ARM64
29+
}
30+
2531
/// <summary>
2632
/// When the user builds a Player (built game) in the Unity Editor, this class manages
2733
/// automatically compiling a suitable version of the native C++ CesiumForUnityNative
@@ -36,7 +42,7 @@ internal class LibraryToBuild
3642
{
3743
public BuildTarget Platform = BuildTarget.StandaloneWindows64;
3844
public BuildTargetGroup PlatformGroup = BuildTargetGroup.Standalone;
39-
public string Cpu = null;
45+
public LibraryCpuArchitecture? Cpu = null;
4046
public string SourceDirectory = "";
4147
public string BuildDirectory = "build";
4248
public string GeneratedDirectoryName = "generated-Unknown";
@@ -110,6 +116,7 @@ private static string GetSharedLibraryFilename(string baseName, BuildTarget targ
110116
{
111117
case BuildTarget.StandaloneWindows:
112118
case BuildTarget.StandaloneWindows64:
119+
case BuildTarget.WSAPlayer:
113120
return $"{baseName}.dll";
114121
case BuildTarget.iOS:
115122
return $"lib{baseName}.a";
@@ -144,14 +151,21 @@ private static void ConfigurePlugin(LibraryToBuild library, PluginImporter impor
144151
importer.SetCompatibleWithEditor(false);
145152
importer.SetCompatibleWithPlatform(library.Platform, true);
146153

147-
if (library.Platform == BuildTarget.Android)
154+
if (library.Platform == BuildTarget.Android ||
155+
library.Platform == BuildTarget.StandaloneOSX)
148156
{
149-
importer.SetPlatformData(BuildTarget.Android, "CPU", library.Cpu == "arm64" ? "ARM64" : library.Cpu);
157+
importer.SetPlatformData(library.Platform, "CPU", library.Cpu == LibraryCpuArchitecture.ARM64 ? "ARM64" : null);
150158
}
151-
else if (library.Platform == BuildTarget.StandaloneOSX)
159+
else if (library.Platform == BuildTarget.WSAPlayer)
152160
{
153-
if (library.Cpu != null)
154-
importer.SetPlatformData(BuildTarget.StandaloneOSX, "CPU", library.Cpu == "arm64" ? "ARM64" : library.Cpu);
161+
string wsaPlatform = null;
162+
if (library.Cpu == LibraryCpuArchitecture.ARM64)
163+
wsaPlatform = "ARM64";
164+
else if (library.Cpu == LibraryCpuArchitecture.x86_64)
165+
wsaPlatform = "X64";
166+
else
167+
UnityEngine.Debug.LogAssertion("Unsupported processor: " + library.Cpu);
168+
importer.SetPlatformData(library.Platform, "CPU", wsaPlatform);
155169
}
156170
}
157171

@@ -241,8 +255,8 @@ private static LibraryToBuild[] GetLibrariesToBuildForPlatform(BuildSummary summ
241255
}
242256
else
243257
{
244-
result.Add(GetLibraryToBuild(summary, "x86_64"));
245-
result.Add(GetLibraryToBuild(summary, "arm64"));
258+
result.Add(GetLibraryToBuild(summary, LibraryCpuArchitecture.x86_64));
259+
result.Add(GetLibraryToBuild(summary, LibraryCpuArchitecture.ARM64));
246260
}
247261
}
248262
else if (summary.platform == BuildTarget.Android)
@@ -253,9 +267,14 @@ private static LibraryToBuild[] GetLibrariesToBuildForPlatform(BuildSummary summ
253267
UnityEngine.Debug.LogWarning("Cesium for Unity only supports the ARM64 and x86_64 CPU architectures on Android. Other architectures will not work.");
254268

255269
if (PlayerSettings.Android.targetArchitectures.HasFlag(AndroidArchitecture.ARM64))
256-
result.Add(GetLibraryToBuild(summary, "arm64"));
270+
result.Add(GetLibraryToBuild(summary, LibraryCpuArchitecture.ARM64));
257271
if (PlayerSettings.Android.targetArchitectures.HasFlag(AndroidArchitecture.X86_64))
258-
result.Add(GetLibraryToBuild(summary, "x86_64"));
272+
result.Add(GetLibraryToBuild(summary, LibraryCpuArchitecture.x86_64));
273+
}
274+
else if (summary.platform == BuildTarget.WSAPlayer)
275+
{
276+
result.Add(GetLibraryToBuild(summary, LibraryCpuArchitecture.x86_64));
277+
result.Add(GetLibraryToBuild(summary, LibraryCpuArchitecture.ARM64));
259278
}
260279
else
261280
{
@@ -265,7 +284,7 @@ private static LibraryToBuild[] GetLibrariesToBuildForPlatform(BuildSummary summ
265284
return result.ToArray();
266285
}
267286

268-
public static LibraryToBuild GetLibraryToBuild(BuildSummary summary, string cpu = null)
287+
public static LibraryToBuild GetLibraryToBuild(BuildSummary summary, LibraryCpuArchitecture? cpu = null)
269288
{
270289
return GetLibraryToBuild(new PlatformToBuild()
271290
{
@@ -276,7 +295,7 @@ public static LibraryToBuild GetLibraryToBuild(BuildSummary summary, string cpu
276295
}, cpu);
277296
}
278297

279-
public static LibraryToBuild GetLibraryToBuild(PlatformToBuild platform, string cpu = null)
298+
public static LibraryToBuild GetLibraryToBuild(PlatformToBuild platform, LibraryCpuArchitecture? cpu = null)
280299
{
281300
string sourceFilename = GetSourceFilePathName();
282301
string packagePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(sourceFilename), $".."));
@@ -304,8 +323,8 @@ public static LibraryToBuild GetLibraryToBuild(PlatformToBuild platform, string
304323
{
305324
library.Toolchain = $"extern/android-toolchain.cmake";
306325
if (cpu == null)
307-
cpu = "arm64";
308-
if (cpu == "x86_64")
326+
cpu = LibraryCpuArchitecture.ARM64;
327+
if (cpu == LibraryCpuArchitecture.x86_64)
309328
library.ExtraConfigureArgs.Add("-DCMAKE_ANDROID_ARCH_ABI=x86_64");
310329
else
311330
library.ExtraConfigureArgs.Add("-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a");
@@ -323,13 +342,30 @@ public static LibraryToBuild GetLibraryToBuild(PlatformToBuild platform, string
323342
if (platform.platform == BuildTarget.StandaloneOSX)
324343
{
325344
if (cpu != null)
326-
library.ExtraConfigureArgs.Add("-DCMAKE_OSX_ARCHITECTURES=" + cpu);
345+
library.ExtraConfigureArgs.Add("-DCMAKE_OSX_ARCHITECTURES=" + cpu.ToString().ToLowerInvariant());
346+
}
347+
348+
if (platform.platform == BuildTarget.WSAPlayer)
349+
{
350+
library.ExtraConfigureArgs.Add("-DCMAKE_SYSTEM_NAME=WindowsStore");
351+
library.ExtraConfigureArgs.Add("-DCMAKE_SYSTEM_VERSION=10.0");
352+
switch (cpu)
353+
{
354+
case LibraryCpuArchitecture.x86_64:
355+
library.ExtraConfigureArgs.Add("-DCMAKE_SYSTEM_PROCESSOR=AMD64");
356+
library.ExtraConfigureArgs.Add("-DCMAKE_GENERATOR_PLATFORM=x64");
357+
break;
358+
case LibraryCpuArchitecture.ARM64:
359+
library.ExtraConfigureArgs.Add("-DCMAKE_SYSTEM_PROCESSOR=ARM64");
360+
library.ExtraConfigureArgs.Add("-DCMAKE_GENERATOR_PLATFORM=ARM64");
361+
break;
362+
}
327363
}
328364

329365
if (cpu != null)
330366
{
331-
library.InstallDirectory = Path.Combine(library.InstallDirectory, cpu);
332-
library.BuildDirectory += "-" + cpu;
367+
library.InstallDirectory = Path.Combine(library.InstallDirectory, cpu.ToString().ToLowerInvariant());
368+
library.BuildDirectory += "-" + cpu.ToString().ToLowerInvariant();
333369
}
334370

335371
return library;
@@ -345,7 +381,8 @@ private static bool IsEditor(BuildTargetGroup platformGroup, BuildTarget platfor
345381
return platformGroup == BuildTargetGroup.Unknown && platform == BuildTarget.NoTarget;
346382
}
347383

348-
private static bool IsIOS(BuildTargetGroup platformGroup, BuildTarget platform){
384+
private static bool IsIOS(BuildTargetGroup platformGroup, BuildTarget platform)
385+
{
349386
return platformGroup == BuildTargetGroup.iOS && platform == BuildTarget.iOS;
350387
}
351388

@@ -388,10 +425,12 @@ internal static void BuildNativeLibrary(LibraryToBuild library)
388425
{
389426
ProcessStartInfo startInfo = new ProcessStartInfo();
390427
startInfo.UseShellExecute = false;
391-
if (library.Platform == BuildTarget.StandaloneOSX || library.Platform == BuildTarget.iOS){
428+
if (library.Platform == BuildTarget.StandaloneOSX || library.Platform == BuildTarget.iOS)
429+
{
392430
startInfo.FileName = File.Exists("/Applications/CMake.app/Contents/bin/cmake") ? "/Applications/CMake.app/Contents/bin/cmake" : "cmake";
393431
}
394-
else {
432+
else
433+
{
395434
startInfo.FileName = "cmake";
396435
}
397436
startInfo.CreateNoWindow = true;
@@ -412,7 +451,7 @@ internal static void BuildNativeLibrary(LibraryToBuild library)
412451
$"-DREINTEROP_GENERATED_DIRECTORY={library.GeneratedDirectoryName}",
413452
};
414453
args.AddRange(library.ExtraConfigureArgs);
415-
454+
416455
if (library.Toolchain != null)
417456
args.Add($"-DCMAKE_TOOLCHAIN_FILE=\"{library.Toolchain}\"");
418457

@@ -434,8 +473,8 @@ internal static void BuildNativeLibrary(LibraryToBuild library)
434473
args.AddRange(library.ExtraBuildArgs);
435474
startInfo.Arguments = string.Join(' ', args);
436475
RunAndLog(startInfo, log, logFilename);
437-
438-
if(library.Platform == BuildTarget.iOS)
476+
477+
if (library.Platform == BuildTarget.iOS)
439478
AssetDatabase.Refresh();
440479
}
441480
}

Editor/ConfigureReinterop.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ internal partial class ConfigureReinterop
2222
public const string CppOutputPath = "../native~/Editor/generated-Android";
2323
#elif UNITY_IOS
2424
public const string CppOutputPath = "../native~/Editor/generated-iOS";
25+
#elif UNITY_WSA
26+
public const string CppOutputPath = "../native~/Runtime/generated-WSA";
2527
#elif UNITY_64
2628
public const string CppOutputPath = "../native~/Editor/generated-Standalone";
2729
#else

Runtime/ConfigureReinterop.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ internal partial class ConfigureReinterop
3030
public const string CppOutputPath = "../native~/Runtime/generated-Android";
3131
#elif UNITY_IOS
3232
public const string CppOutputPath = "../native~/Runtime/generated-iOS";
33+
#elif UNITY_WSA
34+
public const string CppOutputPath = "../native~/Runtime/generated-WSA";
3335
#elif UNITY_64
3436
public const string CppOutputPath = "../native~/Runtime/generated-Standalone";
3537
#else

0 commit comments

Comments
 (0)