// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using System.IO;
namespace Flax.Build.NativeCpp
{
///
/// The native C++ module build settings container.
///
public sealed class BuildOptions
{
///
/// The target that builds this module.
///
public Target Target;
///
/// The build platform.
///
public Platform Platform;
///
/// The build platform toolchain.
///
public Toolchain Toolchain;
///
/// The build architecture.
///
public TargetArchitecture Architecture;
///
/// The build configuration.
///
public TargetConfiguration Configuration;
///
/// The module compilation environment.
///
public CompileEnvironment CompileEnv;
///
/// The module linking environment.
///
public LinkEnvironment LinkEnv;
///
/// The source file directories. By default it contains the directory that contains this module file.
///
public List SourcePaths = new List();
///
/// The source files to include in module build.
///
public List SourceFiles = new List();
///
/// The collection of the modules that are required by this module (for linking). Inherited by the modules that include it.
///
public List PublicDependencies = new List();
///
/// The collection of the modules that are required by this module (for linking).
///
public List PrivateDependencies = new List();
///
/// The collection of defines with preprocessing symbol for a source files of this module. Inherited by the modules that include it.
///
public readonly HashSet PublicDefinitions = new HashSet();
///
/// The collection of defines with preprocessing symbol for a source files of this module.
///
public readonly HashSet PrivateDefinitions = new HashSet();
///
/// The collection of additional include paths for a source files of this module. Inherited by the modules that include it.
///
public readonly HashSet PublicIncludePaths = new HashSet();
///
/// The collection of additional include paths for a source files of this module.
///
public readonly HashSet PrivateIncludePaths = new HashSet();
///
/// The dependency files to include with output (additional debug files, dynamic libraries, etc.).
///
public HashSet DependencyFiles = new HashSet();
///
/// The optional dependency files to include with output (additional debug files, dynamic libraries, etc.). Missing files won't fail the build.
///
public HashSet OptionalDependencyFiles = new HashSet();
///
/// The list of libraries to link (typically external and third-party plugins).
///
public HashSet Libraries = new HashSet();
///
/// The list of libraries to link for delay-load (typically external and third-party plugins).
///
public HashSet DelayLoadLibraries = new HashSet();
///
/// The build output files (binaries, object files and static or dynamic libraries).
///
public List OutputFiles = new List();
///
/// The intermediate build artifacts folder directory.
///
public string IntermediateFolder;
///
/// The output build artifacts folder directory.
///
public string OutputFolder;
///
/// The build commands working folder directory.
///
public string WorkingDirectory;
///
/// The hot reload postfix added to the output binaries.
///
public string HotReloadPostfix;
///
/// The full path to the dependencies folder for the current build platform, configuration, and architecture.
///
public string DepsFolder => Path.Combine(Globals.EngineRoot, "Source", "Platforms", Platform.Target.ToString(), "Binaries", "ThirdParty", Architecture.ToString());
///
/// The scripting API building options.
///
public struct ScriptingAPIOptions
{
///
/// The preprocessor defines.
///
public HashSet Defines;
///
/// The system libraries references.
///
public HashSet SystemReferences;
///
/// The .Net libraries references (dll or exe files paths).
///
public HashSet FileReferences;
///
/// True if ignore compilation warnings due to missing code documentation comments.
///
public bool IgnoreMissingDocumentationWarnings;
///
/// Adds the other options into this.
///
/// The other.
public void Add(ScriptingAPIOptions other)
{
Defines.AddRange(other.Defines);
SystemReferences.AddRange(other.SystemReferences);
FileReferences.AddRange(other.FileReferences);
IgnoreMissingDocumentationWarnings |= other.IgnoreMissingDocumentationWarnings;
}
}
///
/// The scripting API building options.
///
public ScriptingAPIOptions ScriptingAPI = new ScriptingAPIOptions
{
Defines = new HashSet(),
SystemReferences = new HashSet
{
"System",
"System.Xml",
"System.Core",
},
FileReferences = new HashSet(),
};
///
/// Merges the files from input source paths into source files and clears the source paths list.
///
internal void MergeSourcePathsIntoSourceFiles()
{
if (SourcePaths.Count == 0)
return;
using (new ProfileEventScope("MergeSourcePathsIntoSourceFiles"))
{
for (var i = 0; i < SourcePaths.Count; i++)
{
var path = SourcePaths[i];
if (!Directory.Exists(path))
continue;
var files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
var count = SourceFiles.Count;
if (SourceFiles.Count == 0)
{
SourceFiles.AddRange(files);
}
else
{
for (int j = 0; j < files.Length; j++)
{
bool unique = true;
for (int k = 0; k < count; k++)
{
if (SourceFiles[k] == files[j])
{
unique = false;
break;
}
}
if (unique)
SourceFiles.Add(files[j]);
}
}
}
SourcePaths.Clear();
}
}
}
}