Support compiling third party library C files as C code
This commit is contained in:
@@ -127,7 +127,7 @@ namespace Flax.Build.Bindings
|
||||
var headerFiles = new List<string>(moduleOptions.SourceFiles.Count / 2);
|
||||
for (int i = 0; i < moduleOptions.SourceFiles.Count; i++)
|
||||
{
|
||||
if (moduleOptions.SourceFiles[i].EndsWith(".h", StringComparison.OrdinalIgnoreCase))
|
||||
if (moduleOptions.SourceFiles[i].EndsWith(".h", StringComparison.OrdinalIgnoreCase) || moduleOptions.SourceFiles[i].EndsWith(".hpp", StringComparison.OrdinalIgnoreCase))
|
||||
headerFiles.Add(moduleOptions.SourceFiles[i]);
|
||||
}
|
||||
if (headerFiles.Count == 0)
|
||||
|
||||
@@ -482,7 +482,7 @@ namespace Flax.Build
|
||||
var cppFiles = new List<string>(moduleOptions.SourceFiles.Count / 2);
|
||||
for (int i = 0; i < moduleOptions.SourceFiles.Count; i++)
|
||||
{
|
||||
if (moduleOptions.SourceFiles[i].EndsWith(".cpp", StringComparison.OrdinalIgnoreCase))
|
||||
if (moduleOptions.SourceFiles[i].EndsWith(".cpp", StringComparison.OrdinalIgnoreCase) || moduleOptions.SourceFiles[i].EndsWith(".c", StringComparison.OrdinalIgnoreCase))
|
||||
cppFiles.Add(moduleOptions.SourceFiles[i]);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Flax.Deps.Dependencies
|
||||
foreach (var protocolPath in protocolFiles)
|
||||
{
|
||||
var headerFile = Path.ChangeExtension(Path.GetFileName(protocolPath), "h");
|
||||
var glueFile = Path.ChangeExtension(Path.GetFileName(protocolPath), "cpp");
|
||||
var glueFile = Path.ChangeExtension(Path.GetFileName(protocolPath), "c");
|
||||
Utilities.Run("wayland-scanner", $"client-header {protocolPath} include/wayland/{headerFile}", null, dstPath, Utilities.RunOptions.DefaultTool);
|
||||
Utilities.Run("wayland-scanner", $"private-code {protocolPath} {glueFile}", null, dstPath, Utilities.RunOptions.DefaultTool);
|
||||
}
|
||||
|
||||
@@ -333,23 +333,6 @@ namespace Flax.Build.Platforms
|
||||
{
|
||||
commonArgs.Add("-c");
|
||||
commonArgs.Add("-pipe");
|
||||
commonArgs.Add("-x");
|
||||
commonArgs.Add("c++");
|
||||
|
||||
// C++ version
|
||||
switch (compileEnvironment.CppVersion)
|
||||
{
|
||||
case CppVersion.Cpp14:
|
||||
commonArgs.Add("-std=c++14");
|
||||
break;
|
||||
case CppVersion.Cpp17:
|
||||
case CppVersion.Latest:
|
||||
commonArgs.Add("-std=c++17");
|
||||
break;
|
||||
case CppVersion.Cpp20:
|
||||
commonArgs.Add("-std=c++20");
|
||||
break;
|
||||
}
|
||||
|
||||
commonArgs.Add("-Wdelete-non-virtual-dtor");
|
||||
commonArgs.Add("-fno-math-errno");
|
||||
@@ -407,7 +390,7 @@ namespace Flax.Build.Platforms
|
||||
commonArgs.Add(string.Format("-I\"{0}\"", includePath.Replace('\\', '/')));
|
||||
}
|
||||
|
||||
// Compile all C++ files
|
||||
// Compile all C/C++ files
|
||||
var args = new List<string>();
|
||||
foreach (var sourceFile in sourceFiles)
|
||||
{
|
||||
@@ -417,6 +400,30 @@ namespace Flax.Build.Platforms
|
||||
// Use shared arguments
|
||||
args.Clear();
|
||||
args.AddRange(commonArgs);
|
||||
|
||||
// Language for the file
|
||||
args.Add("-x");
|
||||
if (Path.GetExtension(sourceFile).Equals(".c", StringComparison.OrdinalIgnoreCase))
|
||||
args.Add("c");
|
||||
else
|
||||
{
|
||||
args.Add("c++");
|
||||
|
||||
// C++ version
|
||||
switch (compileEnvironment.CppVersion)
|
||||
{
|
||||
case CppVersion.Cpp14:
|
||||
args.Add("-std=c++14");
|
||||
break;
|
||||
case CppVersion.Cpp17:
|
||||
case CppVersion.Latest:
|
||||
args.Add("-std=c++17");
|
||||
break;
|
||||
case CppVersion.Cpp20:
|
||||
args.Add("-std=c++20");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Object File Name
|
||||
var objFile = Path.Combine(outputPath, sourceFilename + ".o");
|
||||
|
||||
@@ -241,11 +241,11 @@ namespace Flax.Build.Projects.VisualStudio
|
||||
foreach (var file in files)
|
||||
{
|
||||
string fileType;
|
||||
if (file.EndsWith(".h", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".inl", StringComparison.OrdinalIgnoreCase))
|
||||
if (file.EndsWith(".h", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".inl", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".hpp", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
fileType = "ClInclude";
|
||||
}
|
||||
else if (file.EndsWith(".cpp", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".cc", StringComparison.OrdinalIgnoreCase))
|
||||
else if (file.EndsWith(".cpp", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".cc", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".c", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
fileType = "ClCompile";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user