diff --git a/Source/Engine/Serialization/Json.h b/Source/Engine/Serialization/Json.h index 1823935e5..692c42bc7 100644 --- a/Source/Engine/Serialization/Json.h +++ b/Source/Engine/Serialization/Json.h @@ -20,6 +20,7 @@ #define RAPIDJSON_NEW(x) New #define RAPIDJSON_DELETE(x) Delete(x) #define RAPIDJSON_NOMEMBERITERATORCLASS +#define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseTrailingCommasFlag //#define RAPIDJSON_MALLOC(size) ::malloc(size) //#define RAPIDJSON_REALLOC(ptr, new_size) ::realloc(ptr, new_size) //#define RAPIDJSON_FREE(ptr) ::free(ptr) diff --git a/Source/Tools/Flax.Build/CommandLine.cs b/Source/Tools/Flax.Build/CommandLine.cs index 226ba9913..bc54675f5 100644 --- a/Source/Tools/Flax.Build/CommandLine.cs +++ b/Source/Tools/Flax.Build/CommandLine.cs @@ -6,6 +6,8 @@ using System.ComponentModel; using System.IO; using System.Linq; using System.Reflection; +using System.Text.Json; +using System.Text.Json.Serialization; namespace Flax.Build { @@ -407,6 +409,15 @@ namespace Flax.Build Configure(GetMembers(obj), obj, configuration); } + internal static void ConfigureChild(Type type, Dictionary configuration, string name = null) + { + if (configuration.TryGetValue(name ?? type.Name, out var subConfig) && subConfig?.Length != 0) + { + var child = JsonSerializer.Deserialize>(subConfig.AsSpan(), ProjectInfo.JsonOptions); + Configure(type, child); + } + } + private static void Configure(Dictionary members, object instance, string commandLine) { if (commandLine == null) diff --git a/Source/Tools/Flax.Build/Configuration.cs b/Source/Tools/Flax.Build/Configuration.cs index 9f2796767..8a662df10 100644 --- a/Source/Tools/Flax.Build/Configuration.cs +++ b/Source/Tools/Flax.Build/Configuration.cs @@ -259,6 +259,42 @@ namespace Flax.Build } } + /// + /// Platform-specific configuration for Windows. + /// + public static partial class WindowsConfiguration + { + /// + /// [Windows] True if SDL support should be enabled. + /// + [CommandLine("useSdl", "1 to enable SDL support in build on Windows")] + public static bool UseSDL = false; + } + + /// + /// Platform-specific configuration for Linux. + /// + public static partial class LinuxConfiguration + { + /// + /// [Linux] True if SDL support should be enabled. + /// + [CommandLine("useSdl", "1 to enable SDL support in build on Linux")] + public static bool UseSDL = false; + } + + /// + /// Platform-specific configuration for Mac. + /// + public static partial class MacConfiguration + { + /// + /// [Mac] True if SDL support should be enabled. + /// + [CommandLine("useSdl", "1 to enable SDL support in build on Mac")] + public static bool UseSDL = false; + } + /// /// The engine configuration options. /// @@ -317,9 +353,11 @@ namespace Flax.Build switch (options.Platform.Target) { case TargetPlatform.Windows: - case TargetPlatform.Linux: + return UseSDL && WindowsConfiguration.UseSDL; case TargetPlatform.Mac: - return UseSDL; + return UseSDL && MacConfiguration.UseSDL; + case TargetPlatform.Linux: + return UseSDL && LinuxConfiguration.UseSDL; case TargetPlatform.Web: return true; default: return false; diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/Assimp.cs b/Source/Tools/Flax.Build/Deps/Dependencies/Assimp.cs index 629a69070..9efcd84de 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/Assimp.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/Assimp.cs @@ -153,9 +153,9 @@ namespace Flax.Deps.Dependencies { var envVars = new Dictionary { - { "CC", "clang-" + Configuration.LinuxClangMinVer }, - { "CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer }, - { "CXX", "clang-" + Configuration.LinuxClangMinVer }, + { "CC", "clang-" + LinuxConfiguration.ClangMinVer }, + { "CC_FOR_BUILD", "clang-" + LinuxConfiguration.ClangMinVer }, + { "CXX", "clang-" + LinuxConfiguration.ClangMinVer }, { "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel }, }; diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/NvCloth.cs b/Source/Tools/Flax.Build/Deps/Dependencies/NvCloth.cs index 2458eceec..a622db17d 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/NvCloth.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/NvCloth.cs @@ -148,13 +148,13 @@ namespace Flax.Deps.Dependencies cmakeArgs += " -DTARGET_BUILD_PLATFORM=linux -DNVCLOTH_CXX_FLAGS=\"-Wno-error=poison-system-directories -Wno-error=missing-include-dirs\""; cmakeName = "linux"; binariesPrefix = "lib"; - envVars.Add("CC", "clang-" + Configuration.LinuxClangMinVer); - envVars.Add("CXX", "clang++-" + Configuration.LinuxClangMinVer); + envVars.Add("CC", "clang-" + LinuxConfiguration.ClangMinVer); + envVars.Add("CXX", "clang++-" + LinuxConfiguration.ClangMinVer); break; case TargetPlatform.Web: cmakeArgs += " -DTARGET_BUILD_PLATFORM=web"; cmakeArgs += $" -DCMAKE_TOOLCHAIN_FILE=\"{EmscriptenSdk.Instance.CMakeToolchainPath}\""; - if (Configuration.WebThreads) + if (WebConfiguration.Threads) cmakeArgs += " -DNVCLOTH_CXX_FLAGS=\"-pthread\""; cmakeName = "web"; binariesPrefix = "lib"; diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs b/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs index 37e446ce1..6477cf712 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/OpenAL.cs @@ -160,9 +160,9 @@ namespace Flax.Deps.Dependencies }; var envVars = new Dictionary { - { "CC", "clang-" + Configuration.LinuxClangMinVer }, - { "CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer }, - { "CXX", "clang++-" + Configuration.LinuxClangMinVer }, + { "CC", "clang-" + LinuxConfiguration.ClangMinVer }, + { "CC_FOR_BUILD", "clang-" + LinuxConfiguration.ClangMinVer }, + { "CXX", "clang++-" + LinuxConfiguration.ClangMinVer }, { "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel }, }; var config = $"-DALSOFT_REQUIRE_ALSA=ON " + diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/PhysX.cs b/Source/Tools/Flax.Build/Deps/Dependencies/PhysX.cs index a636c3647..50869df99 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/PhysX.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/PhysX.cs @@ -74,20 +74,20 @@ namespace Flax.Deps.Dependencies ConfigureCmakeSwitch(cmakeParams, "PHYSX_CXX_FLAGS", "\"-Wno-error=format -Wno-error=unused-but-set-variable -Wno-error=switch-default -Wno-error=invalid-offsetof -Wno-error=unsafe-buffer-usage -Wno-error=unsafe-buffer-usage-in-libc-call -Wno-error=missing-include-dirs\""); break; case TargetPlatform.Android: - ConfigureCmakeSwitch(cmakeParams, "CMAKE_INSTALL_PREFIX", $"install/android-{Configuration.AndroidPlatformApi}/PhysX"); - ConfigureCmakeSwitch(cmakeParams, "ANDROID_NATIVE_API_LEVEL", $"android-{Configuration.AndroidPlatformApi}"); + ConfigureCmakeSwitch(cmakeParams, "CMAKE_INSTALL_PREFIX", $"install/android-{AndroidConfiguration.PlatformApi}/PhysX"); + ConfigureCmakeSwitch(cmakeParams, "ANDROID_NATIVE_API_LEVEL", $"android-{AndroidConfiguration.PlatformApi}"); ConfigureCmakeSwitch(cmakeParams, "ANDROID_ABI", AndroidToolchain.GetAbiName(architecture)); break; case TargetPlatform.Mac: - ConfigureCmakeSwitch(cmakeParams, "CMAKE_OSX_DEPLOYMENT_TARGET", Configuration.MacOSXMinVer); + ConfigureCmakeSwitch(cmakeParams, "CMAKE_OSX_DEPLOYMENT_TARGET", MacConfiguration.MacOSXMinVer); ConfigureCmakeSwitch(cmakeParams, "PHYSX_CXX_FLAGS", "\"-Wno-error=format -Wno-error=unused-but-set-variable -Wno-error=switch-default -Wno-error=invalid-offsetof -Wno-error=unsafe-buffer-usage -Wno-error=unsafe-buffer-usage-in-libc-call -Wno-error=missing-include-dirs\""); break; case TargetPlatform.iOS: - ConfigureCmakeSwitch(cmakeParams, "CMAKE_OSX_DEPLOYMENT_TARGET", Configuration.iOSMinVer); - ConfigureCmakeSwitch(cmakeParams, "CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET", Configuration.iOSMinVer); + ConfigureCmakeSwitch(cmakeParams, "CMAKE_OSX_DEPLOYMENT_TARGET", iOSConfiguration.MinVer); + ConfigureCmakeSwitch(cmakeParams, "CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET", iOSConfiguration.MinVer); break; case TargetPlatform.Web: - ConfigureCmakeSwitch(cmakeParams, "PHYSX_CXX_FLAGS", Configuration.WebThreads ? "\"-pthread\"" : ""); + ConfigureCmakeSwitch(cmakeParams, "PHYSX_CXX_FLAGS", WebConfiguration.Threads ? "\"-pthread\"" : ""); break; } @@ -181,12 +181,12 @@ namespace Flax.Deps.Dependencies default: throw new InvalidArchitectureException(architecture); } binariesPrefix = "lib"; - envVars.Add("MACOSX_DEPLOYMENT_TARGET", Configuration.MacOSXMinVer); + envVars.Add("MACOSX_DEPLOYMENT_TARGET", MacConfiguration.MacOSXMinVer); break; case TargetPlatform.iOS: binariesSubDir = "ios.arm_64"; binariesPrefix = "lib"; - envVars.Add("IPHONEOS_DEPLOYMENT_TARGET", Configuration.iOSMinVer); + envVars.Add("IPHONEOS_DEPLOYMENT_TARGET", iOSConfiguration.MinVer); break; case TargetPlatform.Web: binariesSubDir = "web32"; @@ -211,9 +211,9 @@ namespace Flax.Deps.Dependencies break; } case TargetPlatform.Linux: - envVars.Add("CC", "clang-" + Configuration.LinuxClangMinVer); - envVars.Add("CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer); - envVars.Add("CXX", "clang++-" + Configuration.LinuxClangMinVer); + envVars.Add("CC", "clang-" + LinuxConfiguration.ClangMinVer); + envVars.Add("CC_FOR_BUILD", "clang-" + LinuxConfiguration.ClangMinVer); + envVars.Add("CXX", "clang++-" + LinuxConfiguration.ClangMinVer); break; case TargetPlatform.Mac: break; default: throw new InvalidPlatformException(BuildPlatform); diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/basis_universal.cs b/Source/Tools/Flax.Build/Deps/Dependencies/basis_universal.cs index b56cbb83d..4bb7635fe 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/basis_universal.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/basis_universal.cs @@ -123,7 +123,7 @@ namespace Flax.Deps.Dependencies foreach (var define in defines) cmakeArgs += $"-D{define.Key}={define.Value} "; } - if (platform == TargetPlatform.Web && Configuration.WebThreads) + if (platform == TargetPlatform.Web && WebConfiguration.Threads) cmakeArgs += "-pthread "; cmakeArgs += "\""; diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/curl.cs b/Source/Tools/Flax.Build/Deps/Dependencies/curl.cs index 2d25fed3d..0fa9ff839 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/curl.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/curl.cs @@ -134,8 +134,8 @@ namespace Flax.Deps.Dependencies }; var envVars = new Dictionary { - { "CC", "clang-" + Configuration.LinuxClangMinVer }, - { "CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer }, + { "CC", "clang-" + LinuxConfiguration.ClangMinVer }, + { "CC_FOR_BUILD", "clang-" + LinuxConfiguration.ClangMinVer }, { "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel }, }; var buildDir = Path.Combine(root, "build"); @@ -168,7 +168,7 @@ namespace Flax.Deps.Dependencies var archName = arch + "-apple-darwin19"; if (architecture == TargetArchitecture.ARM64) archName = "arm-apple-darwin19"; // for configure - var compilerFlags = string.Format("-mmacosx-version-min={0} -arch {1}", Configuration.MacOSXMinVer, arch); + var compilerFlags = string.Format("-mmacosx-version-min={0} -arch {1}", MacConfiguration.MacOSXMinVer, arch); var envVars = new Dictionary { { "CC", "clang" }, @@ -178,7 +178,7 @@ namespace Flax.Deps.Dependencies { "CPPFLAGS", compilerFlags }, { "ARCH", arch }, { "SDK", "macosx" }, - { "DEPLOYMENT_TARGET", Configuration.MacOSXMinVer }, + { "DEPLOYMENT_TARGET", MacConfiguration.MacOSXMinVer }, }; var buildDir = Path.Combine(root, "build"); SetupDirectory(buildDir, true); diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/freetype.cs b/Source/Tools/Flax.Build/Deps/Dependencies/freetype.cs index d43c73770..c59006673 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/freetype.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/freetype.cs @@ -81,8 +81,8 @@ namespace Flax.Deps.Dependencies { var envVars = new Dictionary { - { "CC", "clang-" + Configuration.LinuxClangMinVer }, - { "CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer }, + { "CC", "clang-" + LinuxConfiguration.ClangMinVer }, + { "CC_FOR_BUILD", "clang-" + LinuxConfiguration.ClangMinVer }, { "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel }, }; diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/mono.cs b/Source/Tools/Flax.Build/Deps/Dependencies/mono.cs index a90d1c2a0..edcc39671 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/mono.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/mono.cs @@ -591,8 +591,8 @@ namespace Flax.Deps.Dependencies { var envVars = new Dictionary { - { "CC", "clang-" + Configuration.LinuxClangMinVer }, - { "CXX", "clang++-" + Configuration.LinuxClangMinVer } + { "CC", "clang-" + LinuxConfiguration.ClangMinVer }, + { "CXX", "clang++-" + LinuxConfiguration.ClangMinVer } }; var monoOptions = new[] { @@ -662,7 +662,7 @@ namespace Flax.Deps.Dependencies { var sdk = AndroidSdk.Instance.RootPath; var ndk = AndroidNdk.Instance.RootPath; - var apiLevel = Configuration.AndroidPlatformApi.ToString(); + var apiLevel = AndroidConfiguration.PlatformApi.ToString(); var archName = UnixToolchain.GetToolchainName(platform, TargetArchitecture.ARM64); var toolchainRoot = Path.Combine(ndk, "toolchains", "llvm", "prebuilt", AndroidSdk.GetHostName()); var ndkBin = Path.Combine(toolchainRoot, "bin"); @@ -779,7 +779,7 @@ namespace Flax.Deps.Dependencies } case TargetPlatform.Mac: { - var compilerFlags = string.Format("-mmacosx-version-min={0}", Configuration.MacOSXMinVer); + var compilerFlags = string.Format("-mmacosx-version-min={0}", MacConfiguration.MacOSXMinVer); var envVars = new Dictionary { { "CFLAGS", compilerFlags }, diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/msdfgen.cs b/Source/Tools/Flax.Build/Deps/Dependencies/msdfgen.cs index 89ef9eb4b..670554004 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/msdfgen.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/msdfgen.cs @@ -136,9 +136,9 @@ namespace Flax.Deps.Dependencies libName = "msdfgen-core.lib"; break; case TargetPlatform.Linux: - envVars["CC"] = "clang-" + Configuration.LinuxClangMinVer; - envVars["CC_FOR_BUILD"] = "clang-" + Configuration.LinuxClangMinVer; - envVars["CXX"] = "clang++-" + Configuration.LinuxClangMinVer; + envVars["CC"] = "clang-" + LinuxConfiguration.ClangMinVer; + envVars["CC_FOR_BUILD"] = "clang-" + LinuxConfiguration.ClangMinVer; + envVars["CXX"] = "clang++-" + LinuxConfiguration.ClangMinVer; cmakeArgs += " -DCMAKE_POSITION_INDEPENDENT_CODE=ON"; break; } diff --git a/Source/Tools/Flax.Build/Deps/Dependencies/vorbis.cs b/Source/Tools/Flax.Build/Deps/Dependencies/vorbis.cs index 15ca415da..33ef9b159 100644 --- a/Source/Tools/Flax.Build/Deps/Dependencies/vorbis.cs +++ b/Source/Tools/Flax.Build/Deps/Dependencies/vorbis.cs @@ -250,9 +250,9 @@ namespace Flax.Deps.Dependencies vorbisConfig += " -DCMAKE_POSITION_INDEPENDENT_CODE=ON"; envVars = new Dictionary { - { "CC", "clang-" + Configuration.LinuxClangMinVer }, - { "CC_FOR_BUILD", "clang-" + Configuration.LinuxClangMinVer }, - { "CXX", "clang++-" + Configuration.LinuxClangMinVer }, + { "CC", "clang-" + LinuxConfiguration.ClangMinVer }, + { "CC_FOR_BUILD", "clang-" + LinuxConfiguration.ClangMinVer }, + { "CXX", "clang++-" + LinuxConfiguration.ClangMinVer }, { "CMAKE_BUILD_PARALLEL_LEVEL", CmakeBuildParallel }, }; ext = ".a"; diff --git a/Source/Tools/Flax.Build/Deps/Dependency.cs b/Source/Tools/Flax.Build/Deps/Dependency.cs index de78ff7ce..6362b939b 100644 --- a/Source/Tools/Flax.Build/Deps/Dependency.cs +++ b/Source/Tools/Flax.Build/Deps/Dependency.cs @@ -547,19 +547,19 @@ namespace Flax.Deps var ndk = AndroidNdk.Instance.RootPath; var abi = AndroidToolchain.GetAbiName(architecture); var hostName = AndroidSdk.GetHostName(); - cmdLine = string.Format("-DCMAKE_TOOLCHAIN_FILE=\"{0}/build/cmake/android.toolchain.cmake\" -DANDROID_NDK=\"{0}\" -DANDROID_STL=c++_shared -DANDROID_ABI={1} -DANDROID_PLATFORM=android-{2} -G \"MinGW Makefiles\" -DCMAKE_MAKE_PROGRAM=\"{0}/prebuilt/{3}/bin/make.exe\"", ndk, abi, Configuration.AndroidPlatformApi, hostName); + cmdLine = string.Format("-DCMAKE_TOOLCHAIN_FILE=\"{0}/build/cmake/android.toolchain.cmake\" -DANDROID_NDK=\"{0}\" -DANDROID_STL=c++_shared -DANDROID_ABI={1} -DANDROID_PLATFORM=android-{2} -G \"MinGW Makefiles\" -DCMAKE_MAKE_PROGRAM=\"{0}/prebuilt/{3}/bin/make.exe\"", ndk, abi, AndroidConfiguration.PlatformApi, hostName); break; } case TargetPlatform.Mac: { var arch = GetAppleArchName(architecture); - cmdLine = string.Format("CMakeLists.txt -DCMAKE_OSX_DEPLOYMENT_TARGET=\"{0}\" -DCMAKE_OSX_ARCHITECTURES={1}", Configuration.MacOSXMinVer, arch); + cmdLine = string.Format("CMakeLists.txt -DCMAKE_OSX_DEPLOYMENT_TARGET=\"{0}\" -DCMAKE_OSX_ARCHITECTURES={1}", MacConfiguration.MacOSXMinVer, arch); break; } case TargetPlatform.iOS: { var arch = GetAppleArchName(architecture); - cmdLine = string.Format("CMakeLists.txt -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=\"{0}\" -DCMAKE_OSX_ARCHITECTURES={1}", Configuration.iOSMinVer, arch); + cmdLine = string.Format("CMakeLists.txt -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_DEPLOYMENT_TARGET=\"{0}\" -DCMAKE_OSX_ARCHITECTURES={1}", iOSConfiguration.MinVer, arch); break; } case TargetPlatform.Web: diff --git a/Source/Tools/Flax.Build/Platforms/Android/AndroidToolchain.cs b/Source/Tools/Flax.Build/Platforms/Android/AndroidToolchain.cs index d88cdbd51..ab332fdb1 100644 --- a/Source/Tools/Flax.Build/Platforms/Android/AndroidToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Android/AndroidToolchain.cs @@ -8,13 +8,13 @@ using Flax.Build.NativeCpp; namespace Flax.Build { - partial class Configuration + partial class AndroidConfiguration { /// /// Specifies the Android API level to use (eg. 24). /// - [CommandLine("androidPlatformApi", "", "Specifies the Android API level to use (eg. 24).")] - public static int AndroidPlatformApi = 24; + [CommandLine("platformApi", "", "Specifies the Android API level to use (eg. 24).")] + public static int PlatformApi = 24; } } @@ -66,7 +66,7 @@ namespace Flax.Build.Platforms base.SetupEnvironment(options); options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_ANDROID"); - options.CompileEnv.PreprocessorDefinitions.Add(string.Format("__ANDROID_API__={0}", Configuration.AndroidPlatformApi)); + options.CompileEnv.PreprocessorDefinitions.Add(string.Format("__ANDROID_API__={0}", AndroidConfiguration.PlatformApi)); options.LinkEnv.InputLibraries.Add("c"); options.LinkEnv.InputLibraries.Add("z"); @@ -108,7 +108,7 @@ namespace Flax.Build.Platforms { case TargetArchitecture.x86: args.Add("-march=atom"); - if (Configuration.AndroidPlatformApi < 24) + if (AndroidConfiguration.PlatformApi < 24) args.Add("-mstackrealign"); break; case TargetArchitecture.x64: @@ -167,7 +167,7 @@ namespace Flax.Build.Platforms var toolchain = ToolsetRoot.Replace('\\', '/'); args.Add(string.Format("--sysroot=\"{0}/sysroot\"", toolchain)); args.Add(string.Format("--gcc-toolchain=\"{0}\"", toolchain)); - args.Add("--target=" + target + Configuration.AndroidPlatformApi); + args.Add("--target=" + target + AndroidConfiguration.PlatformApi); } /// diff --git a/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs b/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs index 65283e894..a53cfcfc7 100644 --- a/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs @@ -8,13 +8,13 @@ using System.IO; namespace Flax.Build { - partial class Configuration + partial class LinuxConfiguration { /// /// Specifies the minimum Clang compiler version to use on Linux (eg. 10). /// - [CommandLine("linuxClangMinVer", "", "Specifies the minimum Clang compiler version to use on Linux (eg. 10).")] - public static string LinuxClangMinVer = "14"; + [CommandLine("clangMinVer", "", "Specifies the minimum Clang compiler version to use on Linux (eg. 10).")] + public static string ClangMinVer = "14"; } } @@ -36,7 +36,7 @@ namespace Flax.Build.Platforms : base(platform, architecture, platform.ToolchainRoot, platform.Compiler) { // Check version - if (Utilities.ParseVersion(Configuration.LinuxClangMinVer, out var minClangVer) && ClangVersion < minClangVer) + if (Utilities.ParseVersion(LinuxConfiguration.ClangMinVer, out var minClangVer) && ClangVersion < minClangVer) Log.Error($"Old Clang version {ClangVersion}. Minimum supported is {minClangVer}."); // Setup system paths diff --git a/Source/Tools/Flax.Build/Platforms/Mac/MacToolchain.cs b/Source/Tools/Flax.Build/Platforms/Mac/MacToolchain.cs index 25c540d2d..891c9e38e 100644 --- a/Source/Tools/Flax.Build/Platforms/Mac/MacToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Mac/MacToolchain.cs @@ -5,7 +5,7 @@ using Flax.Build.NativeCpp; namespace Flax.Build { - partial class Configuration + partial class MacConfiguration { /// /// Specifies the minimum Mac OSX version to use (eg. 10.14). @@ -69,7 +69,7 @@ namespace Flax.Build.Platforms { base.AddArgsCommon(options, args); - args.Add("-mmacosx-version-min=" + Configuration.MacOSXMinVer); + args.Add("-mmacosx-version-min=" + MacConfiguration.MacOSXMinVer); } } } diff --git a/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs b/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs index 2c0929c72..0008988cc 100644 --- a/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs @@ -244,14 +244,14 @@ namespace Flax.Build.Platforms case TargetPlatform.Mac: switch (architecture) { - case TargetArchitecture.x64: return "x86_64-apple-macos" + Configuration.MacOSXMinVer; - case TargetArchitecture.ARM64: return "aarch64-apple-macos" + Configuration.MacOSXMinVer; + case TargetArchitecture.x64: return "x86_64-apple-macos" + MacConfiguration.MacOSXMinVer; + case TargetArchitecture.ARM64: return "aarch64-apple-macos" + MacConfiguration.MacOSXMinVer; default: throw new InvalidArchitectureException(architecture); } case TargetPlatform.iOS: switch (architecture) { - case TargetArchitecture.ARM64: return "aarch64-apple-ios" + Configuration.iOSMinVer; + case TargetArchitecture.ARM64: return "aarch64-apple-ios" + iOSConfiguration.MinVer; default: throw new InvalidArchitectureException(architecture); } default: throw new InvalidPlatformException(platform); diff --git a/Source/Tools/Flax.Build/Platforms/Web/WebToolchain.cs b/Source/Tools/Flax.Build/Platforms/Web/WebToolchain.cs index ee086c2b9..a465ccac0 100644 --- a/Source/Tools/Flax.Build/Platforms/Web/WebToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Web/WebToolchain.cs @@ -9,19 +9,19 @@ using Flax.Build.NativeCpp; namespace Flax.Build { - partial class Configuration + partial class WebConfiguration { /// /// Specifies the initial memory size (in MB) to use by Web app. /// - [CommandLine("webInitialMemory", "", "Specifies the initial memory size (in MB) to use by Web app.")] - public static int WebInitialMemory = 32; + [CommandLine("initialMemory", "", "Specifies the initial memory size (in MB) to use by Web app.")] + public static int InitialMemory = 32; /// /// Enables pthreads support for multithreading using SharedArrayBuffer in browsers. Changing it requires rebuilding deps for Web. /// - [CommandLine("webThreads", "0/1", "Enables pthreads support for multithreading using SharedArrayBuffer in browsers. Changing it requires rebuilding deps for Web.")] - public static bool WebThreads = false; + [CommandLine("threads", "0/1", "Enables pthreads support for multithreading using SharedArrayBuffer in browsers. Changing it requires rebuilding deps for Web.")] + public static bool Threads = false; } } @@ -105,7 +105,7 @@ namespace Flax.Build.Platforms options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_WEB"); options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_UNIX"); options.CompileEnv.PreprocessorDefinitions.Add("__EMSCRIPTEN__"); - if (Configuration.WebThreads) + if (WebConfiguration.Threads) options.CompileEnv.PreprocessorDefinitions.Add("__EMSCRIPTEN_PTHREADS__"); options.CompileEnv.EnableExceptions = WithExceptions(options); options.CompileEnv.CpuArchitecture = CpuArchitecture.SSE4_2; @@ -183,7 +183,7 @@ namespace Flax.Build.Platforms if (sanitizers == Sanitizer.None && options.Configuration != TargetConfiguration.Release) args.Add("-fsanitize=null -fsanitize-minimal-runtime"); // Minimal Runtime - if (Configuration.WebThreads) + if (WebConfiguration.Threads) args.Add("-pthread"); } @@ -308,7 +308,7 @@ namespace Flax.Build.Platforms args.Add("-sERROR_ON_UNDEFINED_SYMBOLS=0"); // Setup memory - var initialMemory = Configuration.WebInitialMemory; + var initialMemory = WebConfiguration.InitialMemory; if (options.CompileEnv.Sanitizers.HasFlag(Sanitizer.Address)) initialMemory = Math.Max(initialMemory, 64); // Address Sanitizer needs more memory args.Add($"-sINITIAL_MEMORY={initialMemory}MB"); diff --git a/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchain.cs b/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchain.cs index 0c2d44c5d..da6c868f3 100644 --- a/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Windows/WindowsToolchain.cs @@ -8,19 +8,19 @@ using Flax.Build.NativeCpp; namespace Flax.Build { - partial class Configuration + partial class WindowsConfiguration { /// /// Specifies the minimum Windows version to use (eg. 10). /// - [CommandLine("winMinVer", "", "Specifies the minimum Windows version to use (eg. 10).")] - public static string WindowsMinVer = "10"; + [CommandLine("minVer", "", "Specifies the minimum Windows version to use (eg. 10).")] + public static string MinVer = "10"; /// /// Specifies the minimum CPU architecture type to support (on x86/x64). /// - [CommandLine("winCpuArch", "", "Specifies the minimum CPU architecture type to support (on x86/x64).")] - public static CpuArchitecture WindowsCpuArch = CpuArchitecture.SSE4_2; // 99.78% support on PC according to Steam Hardware & Software Survey: September 2025 (https://store.steampowered.com/hwsurvey/) + [CommandLine("cpuArch", "", "Specifies the minimum CPU architecture type to support (on x86/x64).")] + public static CpuArchitecture CpuArch = CpuArchitecture.SSE4_2; // 99.78% support on PC according to Steam Hardware & Software Survey: September 2025 (https://store.steampowered.com/hwsurvey/) } } @@ -44,7 +44,7 @@ namespace Flax.Build.Platforms : base(platform, architecture, WindowsPlatformToolset.Latest, WindowsPlatformSDK.Latest) { // Select minimum Windows version - if (!Utilities.ParseVersion(Configuration.WindowsMinVer, out _minVersion)) + if (!Utilities.ParseVersion(WindowsConfiguration.MinVer, out _minVersion)) _minVersion = new Version(7, 0); } @@ -76,7 +76,7 @@ namespace Flax.Build.Platforms options.LinkEnv.InputLibraries.Add("oleaut32.lib"); options.LinkEnv.InputLibraries.Add("delayimp.lib"); - options.CompileEnv.CpuArchitecture = Configuration.WindowsCpuArch; + options.CompileEnv.CpuArchitecture = WindowsConfiguration.CpuArch; if (options.Architecture == TargetArchitecture.x64) { diff --git a/Source/Tools/Flax.Build/Platforms/iOS/iOSToolchain.cs b/Source/Tools/Flax.Build/Platforms/iOS/iOSToolchain.cs index 44647a607..a54035a69 100644 --- a/Source/Tools/Flax.Build/Platforms/iOS/iOSToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/iOS/iOSToolchain.cs @@ -6,13 +6,13 @@ using Flax.Build.NativeCpp; namespace Flax.Build { - partial class Configuration + partial class iOSConfiguration { /// /// Specifies the minimum iOS version to use (eg. 14). /// - [CommandLine("iOSMinVer", "", "Specifies the minimum iOS version to use (eg. 14).")] - public static string iOSMinVer = "15"; + [CommandLine("MinVer", "", "Specifies the minimum iOS version to use (eg. 14).")] + public static string MinVer = "15"; } } @@ -60,7 +60,7 @@ namespace Flax.Build.Platforms { base.AddArgsCommon(options, args); - args.Add("-miphoneos-version-min=" + Configuration.iOSMinVer); + args.Add("-miphoneos-version-min=" + iOSConfiguration.MinVer); } public override bool CompileCSharp(ref CSharpOptions options) diff --git a/Source/Tools/Flax.Build/Program.cs b/Source/Tools/Flax.Build/Program.cs index 711ac5ccb..5387a3b38 100644 --- a/Source/Tools/Flax.Build/Program.cs +++ b/Source/Tools/Flax.Build/Program.cs @@ -85,6 +85,11 @@ namespace Flax.Build { CommandLine.Configure(typeof(EngineConfiguration), engineProject.Configuration); CommandLine.Configure(typeof(Configuration), engineProject.Configuration); + CommandLine.ConfigureChild(typeof(WindowsConfiguration), engineProject.Configuration, "Windows"); + CommandLine.ConfigureChild(typeof(LinuxConfiguration), engineProject.Configuration, "Linux"); + CommandLine.ConfigureChild(typeof(MacConfiguration), engineProject.Configuration, "Mac"); + CommandLine.ConfigureChild(typeof(iOSConfiguration), engineProject.Configuration, "iOS"); + CommandLine.ConfigureChild(typeof(WebConfiguration), engineProject.Configuration, "Web"); } CommandLine.Configure(typeof(EngineConfiguration)); } diff --git a/Source/Tools/Flax.Build/ProjectInfo.cs b/Source/Tools/Flax.Build/ProjectInfo.cs index 00bdbf938..37f01531a 100644 --- a/Source/Tools/Flax.Build/ProjectInfo.cs +++ b/Source/Tools/Flax.Build/ProjectInfo.cs @@ -113,6 +113,55 @@ namespace Flax.Build value = "true"; else if (reader.TokenType == JsonTokenType.False) value = "false"; + else if (reader.TokenType == JsonTokenType.StartObject) + { + value = "{"; + int depth = 1; + while (depth > 0 && reader.Read()) + { + switch (reader.TokenType) + { + case JsonTokenType.StartObject: + depth++; + value += "{"; + break; + case JsonTokenType.EndObject: + if (value.Last() == ',') + value = value.Substring(0, value.Length - 1); + value += "}"; + if (depth != 1) + value += ","; + depth--; + break; + case JsonTokenType.StartArray: + value += "["; + break; + case JsonTokenType.EndArray: + value += "],"; + break; + case JsonTokenType.PropertyName: + value += $"\"{reader.GetString()}\":"; + break; + case JsonTokenType.String: + value += $"\"{reader.GetString()}\","; + break; + case JsonTokenType.Number: + value += $"{reader.GetString()},"; + break; + case JsonTokenType.True: + value += "true,"; + break; + case JsonTokenType.False: + value += "false,"; + break; + case JsonTokenType.Null: + value += "null,"; + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + } else value = reader.GetString(); dictionary.Add(key, value); @@ -147,6 +196,19 @@ namespace Flax.Build private static List _projectsCache; private string _versionControlCommit, _versionControlBranch; + internal static JsonSerializerOptions JsonOptions = new JsonSerializerOptions + { + Converters = + { + new FlaxVersionConverter(), + new ConfigurationDictionaryConverter(), + }, + IncludeFields = true, + AllowTrailingCommas = true, + ReadCommentHandling = JsonCommentHandling.Skip, + TypeInfoResolver = ProjectInfoSourceGenerationContext.Default, + }; + /// /// The project reference. /// @@ -230,7 +292,6 @@ namespace Flax.Build /// /// The custom build configuration entries loaded from project file. /// - [System.Text.Json.Serialization.JsonConverter(typeof(ConfigurationDictionaryConverter))] public Dictionary Configuration; /// @@ -264,7 +325,6 @@ namespace Flax.Build /// public string VersionControlInfo { - get { if (_versionControlCommit == null) @@ -356,7 +416,7 @@ namespace Flax.Build /// public void Save() { - var contents = JsonSerializer.Serialize(this, new JsonSerializerOptions() { Converters = { new FlaxVersionConverter() }, TypeInfoResolver = ProjectInfoSourceGenerationContext.Default }); + var contents = JsonSerializer.Serialize(this, JsonOptions); File.WriteAllText(ProjectPath, contents); } @@ -382,8 +442,7 @@ namespace Flax.Build // Load Log.Verbose("Loading project file from \"" + path + "\"..."); var contents = File.ReadAllText(path); - var project = JsonSerializer.Deserialize(contents.AsSpan(), - new JsonSerializerOptions() { Converters = { new FlaxVersionConverter() }, IncludeFields = true, TypeInfoResolver = ProjectInfoSourceGenerationContext.Default }); + var project = JsonSerializer.Deserialize(contents.AsSpan(), JsonOptions); project.ProjectPath = path; project.ProjectFolderPath = Path.GetDirectoryName(path); diff --git a/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProjectGenerator.cs b/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProjectGenerator.cs index be9f1235f..86ab6256f 100644 --- a/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProjectGenerator.cs +++ b/Source/Tools/Flax.Build/Projects/VisualStudio/VisualStudioProjectGenerator.cs @@ -49,7 +49,7 @@ namespace Flax.Build.Projects.VisualStudio vcProjectFileContent.AppendLine(string.Format(" {0}", ProjectGuid.ToString("B").ToUpperInvariant())); vcProjectFileContent.AppendLine(string.Format(" {0}", BaseName)); vcProjectFileContent.AppendLine(string.Format(" {0}", projectFileToolVersion)); - vcProjectFileContent.AppendLine(string.Format(" {0}", Configuration.AndroidPlatformApi)); + vcProjectFileContent.AppendLine(string.Format(" {0}", AndroidConfiguration.PlatformApi)); vcProjectFileContent.AppendLine(string.Format(" {0}", "arm64-v8a")); vcProjectFileContent.AppendLine(" Application"); vcProjectFileContent.AppendLine(" ");