added argument for Visual Studio version specification

This commit is contained in:
Miha Markič 2017-01-25 17:22:54 +01:00
Родитель 93b9e2cb89
Коммит e12ece2684
4 изменённых файлов: 81 добавлений и 33 удалений

Просмотреть файл

@ -48,6 +48,7 @@ Generates target language bindings for interop with managed code.
-o, --out=VALUE output directory
-c, --compile compiles the generated output
--dll, --shared compiles as a shared library / DLL
--vs=VALUE Visual Studio version for compilation: 2012, 2013, 2015, Latest (defaults to Latest)
-v, --verbose generates diagnostic verbose output
-h, --help show this message and exit
```

Просмотреть файл

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CppSharp;
using CppSharp.Generators;
@ -11,6 +12,7 @@ namespace MonoEmbeddinator4000
static string Generator;
static string Platform;
static string OutputDir;
static string VsVersion;
static List<string> Assemblies;
static bool CompileCode;
static bool Verbose;
@ -21,6 +23,10 @@ namespace MonoEmbeddinator4000
{
var showHelp = args.Length == 0;
string vsVersions = string.Join(", ",
Enum.GetNames(typeof(VisualStudioVersion))
.Select(s => s.StartsWith("VS", StringComparison.InvariantCulture) ? s.Substring(2) : s)
);
var optionSet = new Mono.Options.OptionSet() {
{ "gen=", "target generator (C, C++, Obj-C)", v => Generator = v },
{ "p|platform=", "target platform (iOS, macOS, Android)", v => Platform = v },
@ -29,11 +35,13 @@ namespace MonoEmbeddinator4000
{ "d|debug", "enables debug mode for generated native and managed code", v => DebugMode = true },
{ "dll|shared", "compiles as a static library", v => Target = CompilationTarget.SharedLibrary },
{ "static", "compiles as a static library", v => Target = CompilationTarget.StaticLibrary },
{ "vs=", $"Visual Studio version for compilation: {vsVersions} (defaults to Latest)", v => VsVersion = v },
{ "v|verbose", "generates diagnostic verbose output", v => Verbose = true },
{ "h|help", "show this message and exit", v => showHelp = v != null },
};
Generator = "C";
VsVersion = "latest";
try
{
@ -64,45 +72,60 @@ namespace MonoEmbeddinator4000
static GeneratorKind ConvertToGeneratorKind(string gen)
{
switch(gen.ToLower())
switch (gen.ToLower())
{
case "c":
return GeneratorKind.C;
case "c++":
case "cpp":
return GeneratorKind.CPlusPlus;
case "objc":
case "obj-c":
case "objectivec":
case "objective-c":
return GeneratorKind.ObjectiveC;
case "java":
return GeneratorKind.Java;
case "c":
return GeneratorKind.C;
case "c++":
case "cpp":
return GeneratorKind.CPlusPlus;
case "objc":
case "obj-c":
case "objectivec":
case "objective-c":
return GeneratorKind.ObjectiveC;
case "java":
return GeneratorKind.Java;
}
throw new NotSupportedException("Unknown target generator: " + gen);
}
static TargetPlatform ConvertToTargetPlatform (string platform)
static VisualStudioVersion ConvertToVsVersion(string version)
{
switch (platform.ToLower ()) {
case "windows":
return TargetPlatform.Windows;
case "android":
return TargetPlatform.Android;
case "osx":
case "macosx":
case "macos":
return TargetPlatform.MacOS;
case "ios":
return TargetPlatform.iOS;
case "watchos":
return TargetPlatform.WatchOS;
case "tvos":
return TargetPlatform.TVOS;
if (string.Equals(version, "latest", StringComparison.InvariantCultureIgnoreCase))
{
return VisualStudioVersion.Latest;
}
VisualStudioVersion result;
if (Enum.TryParse("VS" + version, out result))
{
return result;
}
throw new NotSupportedException("Unknown Visual Studio version: " + version);
}
static TargetPlatform ConvertToTargetPlatform(string platform)
{
switch (platform.ToLower())
{
case "windows":
return TargetPlatform.Windows;
case "android":
return TargetPlatform.Android;
case "osx":
case "macosx":
case "macos":
return TargetPlatform.MacOS;
case "ios":
return TargetPlatform.iOS;
case "watchos":
return TargetPlatform.WatchOS;
case "tvos":
return TargetPlatform.TVOS;
}
throw new NotSupportedException ("Unknown target platform: " + platform);
throw new NotSupportedException("Unknown target platform: " + platform);
}
static void Main(string[] args)
@ -121,6 +144,9 @@ namespace MonoEmbeddinator4000
var targetPlatform = ConvertToTargetPlatform(Platform);
options.Platform = targetPlatform;
var vsVersion = ConvertToVsVersion(VsVersion);
options.VsVersion = vsVersion;
var currentDir = Directory.GetCurrentDirectory();
options.Project.AssemblyDirs.Add(currentDir);
@ -135,4 +161,4 @@ namespace MonoEmbeddinator4000
driver.Run();
}
}
}
}

Просмотреть файл

@ -398,7 +398,21 @@ namespace MonoEmbeddinator4000
if (vsSdks.Count == 0)
throw new Exception("Visual Studio SDK was not found on your system.");
var vsSdk = vsSdks.LastOrDefault();
ToolchainVersion vsSdk;
if (Options.VsVersion == VisualStudioVersion.Latest)
{
vsSdk = vsSdks.LastOrDefault();
}
else
{
var exactVersion = vsSdks.Where(vs => vs.Version == (float)Options.VsVersion).Cast<ToolchainVersion?>().SingleOrDefault();
if (!exactVersion.HasValue)
{
throw new Exception($"Visual Studio SDK version {Options.VsVersion} was not found on your system.");
}
vsSdk = exactVersion.Value;
}
var clBin = Path.GetFullPath(
Path.Combine(vsSdk.Directory, "..", "..", "VC", "bin", "cl.exe"));

Просмотреть файл

@ -1,4 +1,5 @@
using CppSharp.Generators;
using CppSharp;
using CppSharp.Generators;
namespace MonoEmbeddinator4000
{
@ -25,6 +26,12 @@ namespace MonoEmbeddinator4000
public TargetPlatform Platform;
/// <summary>
/// Specifies the VS version.
/// </summary>
/// <remarks>When null, latest is used.</remarks>
public VisualStudioVersion VsVersion;
// If code compilation is enabled, then sets the compilation target.
public CompilationTarget Target;