Mac impl progress

This commit is contained in:
Wojtek Figat
2021-12-27 16:00:26 +01:00
parent d61eb9c096
commit 7ef316f4f9
11 changed files with 131 additions and 55 deletions

View File

@@ -41,6 +41,7 @@ public class freetype : DepsModule
case TargetPlatform.PS5:
case TargetPlatform.Android:
case TargetPlatform.Switch:
case TargetPlatform.Mac:
options.OutputFiles.Add(Path.Combine(depsRoot, "libfreetype.a"));
break;
default: throw new InvalidPlatformException(options.Platform.Target);

View File

@@ -71,6 +71,7 @@ public class mono : DepsModule
break;
}
case TargetPlatform.Linux:
case TargetPlatform.Mac:
options.PublicDefinitions.Add("USE_MONO_DYNAMIC_LIB");
options.DependencyFiles.Add(Path.Combine(depsRoot, "libmonosgen-2.0.so"));
options.Libraries.Add(Path.Combine(depsRoot, "libmonosgen-2.0.so"));

View File

@@ -41,6 +41,7 @@ public class ogg : DepsModule
case TargetPlatform.PS5:
case TargetPlatform.Android:
case TargetPlatform.Switch:
case TargetPlatform.Mac:
options.OutputFiles.Add(Path.Combine(depsRoot, "libogg.a"));
break;
default: throw new InvalidPlatformException(options.Platform.Target);

View File

@@ -41,6 +41,7 @@ public class vorbis : DepsModule
case TargetPlatform.Linux:
case TargetPlatform.Android:
case TargetPlatform.Switch:
case TargetPlatform.Mac:
options.OutputFiles.Add(Path.Combine(depsRoot, "libvorbis.a"));
options.OutputFiles.Add(Path.Combine(depsRoot, "libvorbisenc.a"));
options.OutputFiles.Add(Path.Combine(depsRoot, "libvorbisfile.a"));

View File

@@ -33,6 +33,7 @@ namespace Flax.Build
case TargetPlatform.PS5:
case TargetPlatform.Android:
case TargetPlatform.Switch:
case TargetPlatform.Mac:
options.OutputFiles.Add(Path.Combine(path, string.Format("lib{0}.a", name)));
break;
default: throw new InvalidPlatformException(options.Platform.Target);

View File

@@ -36,9 +36,9 @@ namespace Flax.Build
case PlatformID.WinCE: return TargetPlatform.Windows;
case PlatformID.Unix:
{
var p = new Process
Process p = new Process
{
StartInfo = new ProcessStartInfo
StartInfo =
{
UseShellExecute = false,
RedirectStandardOutput = true,

View File

@@ -161,7 +161,7 @@
<Compile Include="Projects\VisualStudio\VisualStudioProject.cs" />
<Compile Include="Projects\VisualStudio\VisualStudioProjectGenerator.cs" />
<Compile Include="Projects\VisualStudio\VisualStudioVersion.cs" />
<Compile Include="Projects\XCode.cs" />
<Compile Include="Projects\XCodeProjectGenerator.cs" />
<Compile Include="Utilities\StringWriterWithEncoding.cs" />
<Compile Include="Utilities\Tokenizer.cs" />
<Compile Include="Utilities\TwoWayEnumerator.cs" />

View File

@@ -37,7 +37,7 @@ namespace Flax.Build.Platforms
public LinuxPlatform()
{
// Try to use system compiler
if (Environment.OSVersion.Platform == PlatformID.Unix)
if (Platform.BuildTargetPlatform == TargetPlatform.Linux)
{
// Pick the newest compiler (overriden by specified in command line)
if (Which(Compiler) != null)
@@ -62,7 +62,7 @@ namespace Flax.Build.Platforms
Log.Verbose($"Using native Linux toolchain (compiler {Compiler})");
HasRequiredSDKsInstalled = true;
}
else
else if (Platform.BuildTargetPlatform != TargetPlatform.Mac)
{
// Check if Linux toolchain is installed
string toolchainName = "v13_clang-7.0.1-centos7";

View File

@@ -1,5 +1,8 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System;
using System.IO;
using System.Diagnostics;
using Flax.Build.Projects;
namespace Flax.Build.Platforms
@@ -48,7 +51,31 @@ namespace Flax.Build.Platforms
if (Platform.BuildTargetPlatform != TargetPlatform.Mac)
return;
throw new System.NotImplementedException("TODO: detect MacSDK installation");
try
{
// Check if XCode is installed
Process p = new Process
{
StartInfo =
{
FileName = "xcode-select",
Arguments = "--print-path",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
}
};
p.Start();
string xcodePath = p.StandardOutput.ReadToEnd().Trim();
if (string.IsNullOrEmpty(xcodePath) || !Directory.Exists(xcodePath))
throw new Exception(xcodePath);
Log.Verbose(string.Format("Found XCode at {0}", xcodePath));
HasRequiredSDKsInstalled = true;
}
catch
{
Log.Warning("Missing XCode. Cannot build for Mac platform.");
}
}
/// <inheritdoc />

View File

@@ -1,49 +0,0 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System;
namespace Flax.Build.Projects
{
/// <summary>
/// Project generator for XCode.
/// </summary>
public class XCodeProjectGenerator : ProjectGenerator
{
/// <summary>
/// Initializes a new instance of the <see cref="XCodeProjectGenerator"/> class.
/// </summary>
public XCodeProjectGenerator()
{
}
/// <inheritdoc />
public override string ProjectFileExtension => "xcodeproj";
/// <inheritdoc />
public override string SolutionFileExtension => string.Empty;
/// <inheritdoc />
public override TargetType? Type => null;
/// <inheritdoc />
public override Project CreateProject()
{
return new Project
{
Generator = this,
};
}
/// <inheritdoc />
public override void GenerateProject(Project project)
{
throw new NotImplementedException("TODO: XCode");
}
/// <inheritdoc />
public override void GenerateSolution(Solution solution)
{
throw new NotImplementedException("TODO: XCode");
}
}
}

View File

@@ -0,0 +1,93 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Flax.Build.Projects
{
/// <summary>
/// Project generator for XCode.
/// </summary>
public class XCodeProjectGenerator : ProjectGenerator
{
private Random _rand = new Random(1995);
private byte[] _randBytes = new byte[12];
/// <summary>
/// Initializes a new instance of the <see cref="XCodeProjectGenerator"/> class.
/// </summary>
public XCodeProjectGenerator()
{
}
/// <inheritdoc />
public override string ProjectFileExtension => "pbxproj";
/// <inheritdoc />
public override string SolutionFileExtension => "xcodeproj";
/// <inheritdoc />
public override TargetType? Type => null;
/// <inheritdoc />
public override Project CreateProject()
{
return new Project
{
Generator = this,
};
}
/// <inheritdoc />
public override void GenerateProject(Project project)
{
Console.WriteLine(project.Path);
var contents = new StringBuilder();
contents.AppendLine("// !$*UTF8*$!");
contents.AppendLine("{");
contents.AppendLine("\tarchiveVersion = 1;");
contents.AppendLine("\tclasses = {");
contents.AppendLine("\t};");
contents.AppendLine("\tobjectVersion = 46;");
contents.AppendLine("\tobjects = {");
contents.AppendLine("\t};");
contents.AppendLine("\trootObject = " + GetRandomGuid() + " /* Project object */;");
contents.AppendLine("}");
Utilities.WriteFileIfChanged(Path.Combine(project.Path), contents.ToString());
}
/// <inheritdoc />
public override void GenerateSolution(Solution solution)
{
Directory.CreateDirectory(solution.Path);
var contents = new StringBuilder();
contents.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
contents.AppendLine("<Workspace version=\"1.0\">");
foreach (var project in solution.Projects)
{
}
contents.AppendLine("</Workspace>");
Utilities.WriteFileIfChanged(Path.Combine(solution.Path, solution.Name + ".xcworkspace", "contents.xcworkspacedata"), contents.ToString());
}
private string GetRandomGuid()
{
_rand.NextBytes(_randBytes);
string result = string.Empty;
for (int i = 0; i < 12; i++)
{
result += _randBytes[i].ToString("X2");
}
return result;
}
}
}