Add C++ version and compiler path into VS Code project files

#3040
This commit is contained in:
Wojtek Figat
2024-12-06 13:13:25 +01:00
parent 2f239fe405
commit 31e870b086
4 changed files with 37 additions and 0 deletions

View File

@@ -73,6 +73,11 @@ namespace Flax.Build
/// </summary>
public abstract TargetCompiler Compiler { get; }
/// <summary>
/// Gets the main native files compiler path.
/// </summary>
public virtual string NativeCompilerPath { get; }
/// <summary>
/// Initializes a new instance of the <see cref="Toolchain"/> class.
/// </summary>

View File

@@ -267,6 +267,9 @@ namespace Flax.Build.Platforms
/// <inheritdoc />
public override TargetCompiler Compiler => TargetCompiler.Clang;
/// <inheritdoc />
public override string NativeCompilerPath => ClangPath;
/// <inheritdoc />
public override void LogInfo()
{

View File

@@ -358,6 +358,9 @@ namespace Flax.Build.Platforms
/// <inheritdoc />
public override TargetCompiler Compiler => TargetCompiler.MSVC;
/// <inheritdoc />
public override string NativeCompilerPath => _compilerPath;
/// <inheritdoc />
public override void LogInfo()
{

View File

@@ -542,6 +542,8 @@ namespace Flax.Build.Projects.VisualStudioCode
var configuration = TargetConfiguration.Development;
var architecture = TargetArchitecture.x64;
var compilerPath = string.Empty;
var cppVersion = NativeCpp.CppVersion.Cpp14;
var includePaths = new HashSet<string>();
var preprocessorDefinitions = new HashSet<string>();
foreach (var e in mainProject.Defines)
@@ -563,6 +565,8 @@ namespace Flax.Build.Projects.VisualStudioCode
module.Key.SetupEnvironment(targetBuildOptions);
}
cppVersion = targetBuildOptions.CompileEnv.CppVersion;
compilerPath = toolchain.NativeCompilerPath;
foreach (var e in targetBuildOptions.CompileEnv.PreprocessorDefinitions)
preprocessorDefinitions.Add(e);
foreach (var e in targetBuildOptions.CompileEnv.IncludePaths)
@@ -570,6 +574,28 @@ namespace Flax.Build.Projects.VisualStudioCode
}
}
if (compilerPath.Length != 0)
json.AddField("compilerPath", compilerPath);
switch (cppVersion)
{
case NativeCpp.CppVersion.Cpp14:
json.AddField("cStandard", "c11");
json.AddField("cppStandard", "c++14");
break;
case NativeCpp.CppVersion.Cpp17:
case NativeCpp.CppVersion.Latest:
json.AddField("cStandard", "c17");
json.AddField("cppStandard", "c++17");
break;
case NativeCpp.CppVersion.Cpp20:
json.AddField("cStandard", "c17");
json.AddField("cppStandard", "c++20");
break;
default:
throw new Exception($"Visual Code project generator does not support C++ standard {cppVersion}.");
}
json.BeginArray("includePath");
{
foreach (var path in includePaths)