From 6849d31c00313c585c8156e50fcccf4c62fa80fe Mon Sep 17 00:00:00 2001 From: SmelJey Date: Mon, 26 Jul 2021 19:42:40 +1000 Subject: [PATCH 01/37] Add rider project model generator --- Sharpmake.Generators/Generic/R4UE.Template.cs | 27 + Sharpmake.Generators/Generic/R4UE.Util.cs | 33 ++ Sharpmake.Generators/Generic/R4UE.cs | 506 ++++++++++++++++++ 3 files changed, 566 insertions(+) create mode 100644 Sharpmake.Generators/Generic/R4UE.Template.cs create mode 100644 Sharpmake.Generators/Generic/R4UE.Util.cs create mode 100644 Sharpmake.Generators/Generic/R4UE.cs diff --git a/Sharpmake.Generators/Generic/R4UE.Template.cs b/Sharpmake.Generators/Generic/R4UE.Template.cs new file mode 100644 index 000000000..a92b9e8ad --- /dev/null +++ b/Sharpmake.Generators/Generic/R4UE.Template.cs @@ -0,0 +1,27 @@ +namespace Sharpmake.Generators.Generic +{ + public partial class R4UE + { + public static class Template + { + public static string FastBuildBuildCommand = @"cd $(SolutionDir) +[BeforeBuildCommand] +[BuildCommand]"; + + public static string FastBuildReBuildCommand = @"cd $(SolutionDir) +[BeforeBuildCommand] +[RebuildCommand]"; + + public static string FastBuildCleanCommand = @"del ""[IntermediateDirectory]\*unity*.cpp"" >NUL 2>NUL +del ""[IntermediateDirectory]\*.obj"" >NUL 2>NUL +del ""[IntermediateDirectory]\*.a"" >NUL 2>NUL +del ""[IntermediateDirectory]\*.lib"" >NUL 2>NUL +del ""[OutputDirectory]\[TargetFileFullName].exe"" >NUL 2>NUL +del ""[OutputDirectory]\[TargetFileFullName].elf"" >NUL 2>NUL +del ""[OutputDirectory]\[TargetFileFullName].exp"" >NUL 2>NUL +del ""[OutputDirectory]\[TargetFileFullName].ilk"" >NUL 2>NUL +del ""[OutputDirectory]\[TargetFileFullName].lib"" >NUL 2>NUL +del ""[OutputDirectory]\[TargetFileFullName].pdb"" >NUL 2>NUL"; + } + } +} diff --git a/Sharpmake.Generators/Generic/R4UE.Util.cs b/Sharpmake.Generators/Generic/R4UE.Util.cs new file mode 100644 index 000000000..270763bf2 --- /dev/null +++ b/Sharpmake.Generators/Generic/R4UE.Util.cs @@ -0,0 +1,33 @@ +using System; +using System.Linq; + +namespace Sharpmake.Generators.Generic +{ + public static class R4UeUtil + { + public static bool CheckOptions(this Project.Configuration config, params object[] options) + { + var optionsType = typeof(Options); + var getObjectArgsTypes = new Type[] { typeof(Project.Configuration) }; + var configArg = new object[] { config }; + + var getObjectMethod = optionsType.GetMethod("GetObject", getObjectArgsTypes); + var hasObjectMethod = optionsType.GetMethod("HasOption"); + + foreach (var option in options) + { + var genericHasOption = hasObjectMethod.MakeGenericMethod(option.GetType()); + if (!(bool)genericHasOption.Invoke(null, configArg)) + { + continue; + } + + var genericGetObj = getObjectMethod.MakeGenericMethod(option.GetType()); + return genericGetObj.Invoke(null, configArg).Equals(option); + } + + var genericGetFirstObj = getObjectMethod.MakeGenericMethod(options.First().GetType()); + return genericGetFirstObj.Invoke(null, configArg).Equals(options.First()); + } + } +} diff --git a/Sharpmake.Generators/Generic/R4UE.cs b/Sharpmake.Generators/Generic/R4UE.cs new file mode 100644 index 000000000..835df270c --- /dev/null +++ b/Sharpmake.Generators/Generic/R4UE.cs @@ -0,0 +1,506 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.IO; +using System.Linq; +using System.Text; +using Sharpmake.Generators.FastBuild; +using Sharpmake.Generators.VisualStudio; + +namespace Sharpmake.Generators.Generic +{ + /// + /// Generator for Rider project model json files. + /// + public partial class R4UE : IProjectGenerator + { + /// + /// Callback which should be added to in order to generate Rider project model. + /// + public static void PostGenerationCallback(List projects, List solutions) + { + var builder = Builder.Instance; + var riderFolder = Path.Combine(solutions.First().SharpmakeCsPath, ".Rider"); + var generator = new R4UE(); + var configs = solutions.First().Configurations.ToList(); + + // Do not move. Acquires all the information about projects for later usage in "Modules" sections. + generator.Generate(builder, projects, configs, Path.Combine(riderFolder, "root.json"), new List(), + new List()); + + foreach (var project in projects) + { + generator.Generate(builder, project, project.Configurations.ToList(), Path.Combine(riderFolder, project.Name), + new List(), new List()); + } + + } + + /// + /// Helper class to keep all the project information for "Modules" section of json file. + /// + private class RiderProjectInfo + { + public string Name { get; } + public Strings PublicDependencyModules { get; } + public Strings PublicIncludePaths { get; } + public Strings PrivateIncludePaths { get; } + public Strings PublicDefinitions { get; } + public Strings PrivateDefinitions { get; } + + public RiderProjectInfo(string projectName) + { + Name = projectName; + PublicDependencyModules = new Strings(); + PublicIncludePaths = new Strings(); + PrivateIncludePaths = new Strings(); + PublicDefinitions = new Strings(); + PrivateDefinitions = new Strings(); + } + + /// + /// Gathers all the needed information from . + /// + public void ReadConfiguration(Project.Configuration config) + { + PublicDependencyModules.AddRange(config.ResolvedPublicDependencies.Select(it => it.Project.Name)); + PublicIncludePaths.AddRange(config.IncludePaths); + PrivateIncludePaths.AddRange(config.IncludePrivatePaths); + PublicDefinitions.AddRange(config.ExportDefines); + PrivateDefinitions.AddRange(config.Defines); + } + + /// + /// Returns OrderedDictionary for json serialization + /// + /// + public OrderedDictionary ToDictionary() + { + var resDict = new OrderedDictionary(); + resDict.Add("PublicDependencyModules", PublicDependencyModules); + resDict.Add("PublicIncludePaths", PublicIncludePaths); + resDict.Add("PrivateIncludePaths", PrivateIncludePaths); + resDict.Add("PublicDefinitions", PublicDefinitions); + resDict.Add("PrivateDefinitions", PrivateDefinitions); + return resDict; + } + } + + /// + /// Maps projects information for later usage in "Modules" section. + /// + private Dictionary _projectsInfo = new Dictionary(); + + /// + /// Helper class for storing all the project-related information. + /// + private class RiderGenerationContext : IGenerationContext + { + public Builder Builder { get; } + public Project Project { get; } + public Project.Configuration Configuration { get; } + public string ProjectDirectory { get; } + public string ProjectFileName { get; } + public string ProjectPath { get; } + + public Resolver Resolver { get; } + + public DevEnv DevelopmentEnvironment { get; } + public Options.ExplicitOptions Options { get; } + public IDictionary CommandLineOptions { get; } + public string ProjectDirectoryCapitalized { get; } + public string ProjectSourceCapitalized { get; } + public bool PlainOutput => true; + + public FastBuildMakeCommandGenerator FastBuildMakeCommandGenerator { get; } + public string FastBuildArguments { get; } + + public RiderGenerationContext(Builder builder, Project project, Project.Configuration configuration, + string projectPath) + { + Builder = builder; + Resolver = new Resolver(); + + FileInfo fileInfo = new FileInfo(projectPath); + ProjectPath = fileInfo.FullName; + ProjectDirectory = Path.GetDirectoryName(ProjectPath); + ProjectFileName = Path.GetFileName(ProjectPath); + + ProjectDirectory = Path.GetDirectoryName(fileInfo.FullName); + ProjectFileName = fileInfo.Name; + Project = project; + + Configuration = configuration; + ProjectDirectoryCapitalized = Util.GetCapitalizedPath(ProjectDirectory); + ProjectSourceCapitalized = Util.GetCapitalizedPath(Project.SourceRootPath); + DevelopmentEnvironment = configuration.Target.GetFragment(); + + Options = new Options.ExplicitOptions(); + CommandLineOptions = new ProjectOptionsGenerator.VcxprojCmdLineOptions(); + + if (configuration.IsFastBuild) + { + FastBuildMakeCommandGenerator = new Bff.FastBuildDefaultNMakeCommandGenerator(); + FastBuildArguments = string.Join(" ", GetFastBuildOptions()); + } + } + + public void SelectOption(params Options.OptionAction[] options) + { + Sharpmake.Options.SelectOption(Configuration, options); + } + + public void SelectOptionWithFallback(Action fallbackAction, params Options.OptionAction[] options) + { + Sharpmake.Options.SelectOptionWithFallback(Configuration, fallbackAction, options); + } + + private List GetFastBuildOptions() + { + var fastBuildCommandLineOptions = new List(); + + if (FastBuildSettings.FastBuildUseIDE) + fastBuildCommandLineOptions.Add("-ide"); + + if (FastBuildSettings.FastBuildReport) + fastBuildCommandLineOptions.Add("-report"); + + if (FastBuildSettings.FastBuildNoSummaryOnError) + fastBuildCommandLineOptions.Add("-nosummaryonerror"); + + if (FastBuildSettings.FastBuildSummary) + fastBuildCommandLineOptions.Add("-summary"); + + if (FastBuildSettings.FastBuildVerbose) + fastBuildCommandLineOptions.Add("-verbose"); + + if (FastBuildSettings.FastBuildMonitor) + fastBuildCommandLineOptions.Add("-monitor"); + + // Configuring cache mode if that configuration is allowed to use caching + if (Configuration.FastBuildCacheAllowed) + { + // Setting the appropriate cache type commandline for that target. + switch (FastBuildSettings.CacheType) + { + case FastBuildSettings.CacheTypes.CacheRead: + fastBuildCommandLineOptions.Add("-cacheread"); + break; + case FastBuildSettings.CacheTypes.CacheWrite: + fastBuildCommandLineOptions.Add("-cachewrite"); + break; + case FastBuildSettings.CacheTypes.CacheReadWrite: + fastBuildCommandLineOptions.Add("-cache"); + break; + default: + break; + } + } + + if (FastBuildSettings.FastBuildDistribution && Configuration.FastBuildDistribution) + fastBuildCommandLineOptions.Add("-dist"); + + if (FastBuildSettings.FastBuildWait) + fastBuildCommandLineOptions.Add("-wait"); + + if (FastBuildSettings.FastBuildNoStopOnError) + fastBuildCommandLineOptions.Add("-nostoponerror"); + + if (FastBuildSettings.FastBuildFastCancel) + fastBuildCommandLineOptions.Add("-fastcancel"); + + if (FastBuildSettings.FastBuildNoUnity) + fastBuildCommandLineOptions.Add("-nounity"); + + if (!string.IsNullOrEmpty(Configuration.FastBuildCustomArgs)) + fastBuildCommandLineOptions.Add(Configuration.FastBuildCustomArgs); + + return fastBuildCommandLineOptions; + } + } + + private void GenerateConfOptions(RiderGenerationContext context) + { + var projectOptionsGen = new ProjectOptionsGenerator(); + projectOptionsGen.GenerateOptions(context); + } + + /// + /// Generates "root.json" file, gathers information about projects for later usage in "Modules" section. + /// + public void Generate(Builder builder, List projects, List configurations, string rootFile, List generatedFiles, + List skipFiles) + { + var info = new OrderedDictionary(); + foreach (var project in projects) + { + var riderProjInfo = new RiderProjectInfo(project.Name); + var projInfo = new Dictionary>(); + + foreach (var config in project.Configurations) + { + riderProjInfo.ReadConfiguration(config); + if (!projInfo.ContainsKey(config.Platform.ToString())) + { + + projInfo.Add(config.Platform.ToString(), new List()); + } + + projInfo[config.Platform.ToString()].Add(config.Name); + } + + _projectsInfo.Add(riderProjInfo.Name, riderProjInfo); + info.Add(project.Name, projInfo); + } + + var file = new FileInfo(rootFile); + + using (var stream = new MemoryStream()) + using (var writer = new StreamWriter(stream, new UTF8Encoding(false))) + using (var serializer = new Util.JsonSerializer(writer) { IsOutputFormatted = true }) + { + serializer.Serialize(info); + serializer.Flush(); + + if (builder.Context.WriteGeneratedFile(null, file, stream)) + { + generatedFiles.Add(Path.Combine(file.DirectoryName, file.Name)); + } + else + { + skipFiles.Add(Path.Combine(file.DirectoryName, file.Name)); + } + } + } + + /// + /// Generates all -related configuration files. + /// + public void Generate(Builder builder, Project project, List configurations, string projectFile, List generatedFiles, + List skipFiles) + { + foreach (var config in configurations) + { + var context = new RiderGenerationContext(builder, project, config, projectFile); + GenerateConfOptions(context); + GenerateConfiguration(context, generatedFiles, skipFiles); + } + } + + private void GenerateConfiguration(RiderGenerationContext context, List generatedFiles, List skipFiles) + { + var info = new OrderedDictionary(); + var includePaths = new Strings(); + var modules = new OrderedDictionary(); + var toolchain = new OrderedDictionary(); + + toolchain.Add("CppStandard", GetCppStandart(context.Configuration)); + toolchain.Add("bUseRTTI", IsRTTIEnabled(context.Configuration)); + toolchain.Add("bUseExceptions", IsExceptionEnabled(context.Configuration)); + toolchain.Add("bIsBuildingLibrary", context.Configuration.Output == Project.Configuration.OutputType.Dll + || context.Configuration.Output == Project.Configuration.OutputType.Lib); + toolchain.Add("bIsBuildingDll", context.Configuration.Output == Project.Configuration.OutputType.Dll); + toolchain.Add("Configuration", context.Configuration.Name); + toolchain.Add("bOptimizeCode", IsOptimizationEnabled(context.Configuration)); + toolchain.Add("bUseInlining", IsInliningEnabled(context.Configuration)); + toolchain.Add("bUseUnity", IsBlob(context.Configuration)); + toolchain.Add("bCreateDebugInfo", IsDebugInfo(context.Configuration)); + toolchain.Add("bUseAVX", IsAvx(context.Configuration)); + toolchain.Add("Compiler", context.Configuration.Compiler.ToString()); + toolchain.Add("bStrictConformanceMode", IsConformanceMode(context.Configuration)); + toolchain.Add("PrecompiledHeaderAction", GetPchAction(context)); + + if (context.Configuration.IsFastBuild) + { + var beforeBuildCommand = context.Configuration.FastBuildCustomActionsBeforeBuildCommand; + if (beforeBuildCommand == FileGeneratorUtilities.RemoveLineTag) + { + beforeBuildCommand = ""; + } + + using (context.Resolver.NewScopedParameter("BeforeBuildCommand", beforeBuildCommand)) + { + toolchain.Add("BuildCmd", GetBuildCommand(context)); + toolchain.Add("ReBuildCmd", GetReBuildCommand(context)); + toolchain.Add("CleanCmd", GetCleanCommand(context)); + } + } + + var platformVcxproj = PlatformRegistry.Query(context.Configuration.Platform); + includePaths.AddRange(platformVcxproj.GetPlatformIncludePaths(context)); + + var curProjectInfo = _projectsInfo[context.Project.Name]; + modules.Add(curProjectInfo.Name, curProjectInfo.ToDictionary()); + + foreach (var dependency in context.Configuration.ResolvedDependencies.Select(it => it.ProjectName)) + { + var dependencyInfo = _projectsInfo[dependency]; + modules.Add(dependencyInfo.Name, dependencyInfo.ToDictionary()); + } + + info.Add("Name", context.Configuration.ProjectName); + info.Add("Configuration", context.Configuration.Name); + info.Add("Platform", context.Configuration.Platform.ToString()); + info.Add("ToolchainInfo", toolchain); + info.Add("EnvironmentIncludePaths", includePaths); + info.Add("EnvironmentDefinitions", context.Configuration.Defines); + info.Add("Modules", modules); + + var file = new FileInfo($"{context.ProjectPath}_{context.Configuration.Platform}_{context.Configuration.Name}.json"); + + using (var stream = new MemoryStream()) + using (var writer = new StreamWriter(stream, new UTF8Encoding(false))) + using (var serializer = new Util.JsonSerializer(writer) { IsOutputFormatted = true }) + { + serializer.Serialize(info); + serializer.Flush(); + + if (context.Builder.Context.WriteGeneratedFile(null, file, stream)) + { + generatedFiles.Add(Path.Combine(file.DirectoryName, file.Name)); + } + else + { + skipFiles.Add(Path.Combine(file.DirectoryName, file.Name)); + } + } + } + + private string GetCppStandart(Project.Configuration config) + { + string res = "Default"; + + var stdOptions = new List(); + stdOptions.AddRange(Options.GetObjects(config).Select(it => it as object)); + stdOptions.AddRange(Options.GetObjects(config).Select(it => it as object)); + stdOptions.AddRange(Options.GetObjects(config).Select(it => it as object)); + stdOptions.AddRange(Options.GetObjects(config).Select(it => it as object)); + stdOptions.AddRange(Options.GetObjects(config).Select(it => it as object)); + + if (stdOptions.Count > 0) + { + res = stdOptions.First().ToString(); + } + + return res; + } + + private bool IsRTTIEnabled(Project.Configuration config) + { + return !config.CheckOptions(Options.Vc.Compiler.RTTI.Disable, + Options.Makefile.Compiler.Rtti.Disable, + Options.XCode.Compiler.RTTI.Disable, + Options.Clang.Compiler.Rtti.Disable); + } + + private bool IsExceptionEnabled(Project.Configuration config) + { + return !config.CheckOptions(Options.Vc.Compiler.Exceptions.Disable, + Options.Makefile.Compiler.Exceptions.Disable, + Options.XCode.Compiler.Exceptions.Disable, + Options.Clang.Compiler.Exceptions.Disable, + Options.Android.Compiler.Exceptions.Disable); + } + + private bool IsOptimizationEnabled(Project.Configuration config) + { + return !config.CheckOptions(Options.Vc.Compiler.Optimization.Disable, + Options.Makefile.Compiler.OptimizationLevel.Disable, + Options.XCode.Compiler.OptimizationLevel.Disable, + Options.Clang.Compiler.OptimizationLevel.Disable); + } + + private bool IsInliningEnabled(Project.Configuration config) + { + return !config.CheckOptions(Options.Vc.Compiler.Inline.Disable); + } + + private bool IsBlob(Project.Configuration config) + { + return config.IsBlobbed || config.FastBuildBlobbed; + } + + private bool IsDebugInfo(Project.Configuration config) + { + return !config.CheckOptions(Options.Vc.General.DebugInformation.Disable, + Options.Makefile.Compiler.GenerateDebugInformation.Disable, + Options.XCode.Compiler.GenerateDebuggingSymbols.Disable, + Options.Clang.Compiler.GenerateDebugInformation.Disable, + Options.Android.Compiler.DebugInformationFormat.None); + } + + private bool IsAvx(Project.Configuration config) + { + return config.CheckOptions(Options.Vc.Compiler.EnhancedInstructionSet.AdvancedVectorExtensions, + Options.Vc.Compiler.EnhancedInstructionSet.AdvancedVectorExtensions2, + Options.Vc.Compiler.EnhancedInstructionSet.AdvancedVectorExtensions512); + } + + private bool IsConformanceMode(Project.Configuration config) + { + return config.CheckOptions(Options.Vc.Compiler.ConformanceMode.Enable); + } + + private string GetPchAction(RiderGenerationContext context) + { + var platformVcxproj = PlatformRegistry.Query(context.Configuration.Platform); + + if (!Options.HasOption(context.Configuration)) + { + if (platformVcxproj.HasPrecomp(context)) + { + return "Include"; + } + + return "None"; + } + + var pchOption = Options.GetObject(context.Configuration); + switch (pchOption) + { + case Options.Vc.SourceFile.PrecompiledHeader.UsePrecompiledHeader: + return "Include"; + case Options.Vc.SourceFile.PrecompiledHeader.CreatePrecompiledHeader: + return "Create"; + default: + return "None"; + } + } + + private string GetBuildCommand(RiderGenerationContext context) + { + var unresolvedCommand = Template.FastBuildBuildCommand; + using (context.Resolver.NewScopedParameter("BuildCommand", + context.FastBuildMakeCommandGenerator.GetCommand( + FastBuildMakeCommandGenerator.BuildType.Build, + context.Configuration, context.FastBuildArguments))) + { + return context.Resolver.Resolve(unresolvedCommand); + } + } + + private string GetReBuildCommand(RiderGenerationContext context) + { + var unresolvedCommand = Template.FastBuildReBuildCommand; + using (context.Resolver.NewScopedParameter("RebuildCommand", + context.FastBuildMakeCommandGenerator.GetCommand( + FastBuildMakeCommandGenerator.BuildType.Rebuild, + context.Configuration, context.FastBuildArguments))) + { + return context.Resolver.Resolve(unresolvedCommand); + } + } + + private string GetCleanCommand(RiderGenerationContext context) + { + var unresolvedOutput = Template.FastBuildCleanCommand; + + using (context.Resolver.NewScopedParameter("IntermediateDirectory", context.Options["IntermediateDirectory"])) + using (context.Resolver.NewScopedParameter("OutputDirectory", context.Options["OutputDirectory"])) + using (context.Resolver.NewScopedParameter("TargetFileFullName", context.Configuration.TargetFileFullName)) + { + return context.Resolver.Resolve(unresolvedOutput); + } + } + } +} From 3a4f3b437cbea7eac24254a3e4b17400ce892dae Mon Sep 17 00:00:00 2001 From: SmelJey Date: Tue, 27 Jul 2021 18:27:33 +1000 Subject: [PATCH 02/37] Add Rider Json documentation --- Sharpmake.Generators/Generic/R4UE.md | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Sharpmake.Generators/Generic/R4UE.md diff --git a/Sharpmake.Generators/Generic/R4UE.md b/Sharpmake.Generators/Generic/R4UE.md new file mode 100644 index 000000000..2db6700fa --- /dev/null +++ b/Sharpmake.Generators/Generic/R4UE.md @@ -0,0 +1,47 @@ +## Introduction + +Rider Json has project files of 2 levels: ++ ```root.json``` - "solution"-wide file which contains information about all projects +and their configurations; ++ ```__.json``` - contains information about single configuration of the project. + +The following is the mapping of Sharpmake properties to Rider Json. + +## Relations between Sharpmake and Rider Json properties +### General +| Sharpmake | Rider Json | +| --------- | ---------- | +| ``Project.Configuration.ProjectName`` | ``Name`` | +| ``Project.Configuration.Name`` | ``Configuration`` | +| ``Configuration.Platform`` | ``Platform`` | +| ``IPlatformVcxproj.GetPlatformIncludePaths()`` | ``EnvironmentIncludePaths`` | +| ``Project.Configuration.Defines`` | ``EnvironmentDefinitions`` | +| ``Project.Configuration.ResolvedDependencies`` | ``Modules`` | + +### Toolchain Info +| Sharpmake | Rider Json | +| --------- | ---------- | +| ``Options..Compiler.CppLanguageStandard``| ``ToolchainInfo.CppStandart`` | +| ``Options..Compiler.RTTI`` | ``ToolchainInfo.RTTI`` | +| ``Options..Compiler.Exceptions`` | ``ToolchainInfo.bUseExceptions`` | +| ``Project.Configuration.OutputType`` | ``ToolchainInfo.bIsBuildingLibrary``
``ToolchainInfo.bIsBuildingDll``| +| ``Options..Compiler.Optimization`` | ``ToolchainInfo.bOptimizeCode`` | +| ``Options.Vc.Compiler.Inline`` | ``ToolchainInfo.bUseInlining`` | +| ``Project.Configuration.IsBlobbed``
``Project.Configuration.FastBuildBlobbed`` | ``ToolchainInfo.bUseUnity`` | +| ``Options.Vc.General.DebugInformation``
``Options..Compiler.GenerateDebugInformation``
``Options.XCode.Compiler.GenerateDebuggingSymbols``
``Options.Android.Compiler.DebugInformationFormat`` | ``ToolchainInfo.bCreateDebugInfo`` | +| ``Options.Vc.Compiler.EnhancedInstructionSet`` | ``ToolchainInfo.bUseAVX`` | +| ``Configuration.Compiler`` | ``ToolchainInfo.Compiler`` | +| ``Options.Vc.Compiler.ConformanceMode`` | ``ToolchainInfo.bStrictConformanceMode`` | +| ``Options.Vc.SourceFile.PrecompiledHeader``
``IPlatformVcxproj.HasPrecomp()`` | ``ToolchainInfo.PrecompiledHeaderAction`` | +| ``FastBuildMakeCommandGenerator.GetCommand()`` | ``ToolchainInfo.BuildCmd``
``ToolchainInfo.ReBuildCmd``
``ToolchainInfo.CleanCmd`` | + +### Modules info +| Sharpmake | Rider Json | +| --------- | ---------- | +| ``Project.Configuration.ResolvedPublicDependencies`` | ``PublicDependencyModules`` | +| ``Project.Configuration.IncludePaths`` | ``PublicIncludePaths`` | +| ``Project.Configuration.IncludePrivatePaths`` | ``PrivateIncludePaths`` | +| ``Project.Configuration.ExportDefines`` | ``PublicDefinitions`` | +| ``Project.Configuration.Defines`` | ``PrivateDefinitions`` | + + From 05296e44978e4a875ad04b9549d22a7843270019 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Wed, 28 Jul 2021 19:05:52 +1000 Subject: [PATCH 03/37] Change Rider-related files naming --- .../Generic/{R4UE.Template.cs => RiderJson.Template.cs} | 2 +- .../Generic/{R4UE.Util.cs => RiderJson.Util.cs} | 2 +- Sharpmake.Generators/Generic/{R4UE.cs => RiderJson.cs} | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename Sharpmake.Generators/Generic/{R4UE.Template.cs => RiderJson.Template.cs} (96%) rename Sharpmake.Generators/Generic/{R4UE.Util.cs => RiderJson.Util.cs} (97%) rename Sharpmake.Generators/Generic/{R4UE.cs => RiderJson.cs} (99%) diff --git a/Sharpmake.Generators/Generic/R4UE.Template.cs b/Sharpmake.Generators/Generic/RiderJson.Template.cs similarity index 96% rename from Sharpmake.Generators/Generic/R4UE.Template.cs rename to Sharpmake.Generators/Generic/RiderJson.Template.cs index a92b9e8ad..c4a9bc2be 100644 --- a/Sharpmake.Generators/Generic/R4UE.Template.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Template.cs @@ -1,6 +1,6 @@ namespace Sharpmake.Generators.Generic { - public partial class R4UE + public partial class RiderJson { public static class Template { diff --git a/Sharpmake.Generators/Generic/R4UE.Util.cs b/Sharpmake.Generators/Generic/RiderJson.Util.cs similarity index 97% rename from Sharpmake.Generators/Generic/R4UE.Util.cs rename to Sharpmake.Generators/Generic/RiderJson.Util.cs index 270763bf2..c11981218 100644 --- a/Sharpmake.Generators/Generic/R4UE.Util.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Util.cs @@ -3,7 +3,7 @@ namespace Sharpmake.Generators.Generic { - public static class R4UeUtil + public static class RiderJsonUtil { public static bool CheckOptions(this Project.Configuration config, params object[] options) { diff --git a/Sharpmake.Generators/Generic/R4UE.cs b/Sharpmake.Generators/Generic/RiderJson.cs similarity index 99% rename from Sharpmake.Generators/Generic/R4UE.cs rename to Sharpmake.Generators/Generic/RiderJson.cs index 835df270c..5029743e2 100644 --- a/Sharpmake.Generators/Generic/R4UE.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -12,7 +12,7 @@ namespace Sharpmake.Generators.Generic /// /// Generator for Rider project model json files. /// - public partial class R4UE : IProjectGenerator + public partial class RiderJson : IProjectGenerator { /// /// Callback which should be added to in order to generate Rider project model. @@ -21,7 +21,7 @@ public static void PostGenerationCallback(List projects, List { var builder = Builder.Instance; var riderFolder = Path.Combine(solutions.First().SharpmakeCsPath, ".Rider"); - var generator = new R4UE(); + var generator = new RiderJson(); var configs = solutions.First().Configurations.ToList(); // Do not move. Acquires all the information about projects for later usage in "Modules" sections. From 6cd947618d07a7e1466f4eb9676e7c96a8ada784 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Thu, 29 Jul 2021 19:39:29 +1000 Subject: [PATCH 04/37] [RiderJson] Change root.json file format: add solution configuration mapping and DoBuild property --- Sharpmake.Generators/Generic/RiderJson.cs | 67 +++++++++++-------- .../Generic/{R4UE.md => RiderJson.md} | 9 ++- 2 files changed, 47 insertions(+), 29 deletions(-) rename Sharpmake.Generators/Generic/{R4UE.md => RiderJson.md} (90%) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 5029743e2..d160fcf44 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -218,48 +218,36 @@ private List GetFastBuildOptions() return fastBuildCommandLineOptions; } } - - private void GenerateConfOptions(RiderGenerationContext context) - { - var projectOptionsGen = new ProjectOptionsGenerator(); - projectOptionsGen.GenerateOptions(context); - } - + /// /// Generates "root.json" file, gathers information about projects for later usage in "Modules" section. /// public void Generate(Builder builder, List projects, List configurations, string rootFile, List generatedFiles, List skipFiles) { - var info = new OrderedDictionary(); - foreach (var project in projects) + var projectsInfo = ReadProjects(projects); + + foreach (var solutionConfig in configurations) { - var riderProjInfo = new RiderProjectInfo(project.Name); - var projInfo = new Dictionary>(); - - foreach (var config in project.Configurations) + foreach (var proj in solutionConfig.IncludedProjectInfos) { - riderProjInfo.ReadConfiguration(config); - if (!projInfo.ContainsKey(config.Platform.ToString())) - { - - projInfo.Add(config.Platform.ToString(), new List()); - } - - projInfo[config.Platform.ToString()].Add(config.Name); + var projInfo = projectsInfo[proj.Project.Name] as Dictionary>; + var projConfig = new Dictionary(); + projConfig.Add("ProjectConfig", proj.Configuration.Name); + projConfig.Add("SolutionConfig", solutionConfig.Name); + projConfig.Add("DoBuild", (proj.ToBuild != Solution.Configuration.IncludedProjectInfo.Build.No).ToString()); + + projInfo[proj.Configuration.Platform.ToString()].Add(projConfig); } - - _projectsInfo.Add(riderProjInfo.Name, riderProjInfo); - info.Add(project.Name, projInfo); } - + var file = new FileInfo(rootFile); using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream, new UTF8Encoding(false))) using (var serializer = new Util.JsonSerializer(writer) { IsOutputFormatted = true }) { - serializer.Serialize(info); + serializer.Serialize(projectsInfo); serializer.Flush(); if (builder.Context.WriteGeneratedFile(null, file, stream)) @@ -272,7 +260,29 @@ public void Generate(Builder builder, List projects, List projects) + { + var info = new OrderedDictionary(); + foreach (var project in projects) { + var riderProjInfo = new RiderProjectInfo(project.Name); + var initialProjectInfo = new Dictionary>(); + + foreach (var config in project.Configurations) { + riderProjInfo.ReadConfiguration(config); + if (!initialProjectInfo.ContainsKey(config.Platform.ToString())) { + initialProjectInfo.Add(config.Platform.ToString(), new List()); + } + } + + info.Add(project.Name, initialProjectInfo); + + _projectsInfo.Add(riderProjInfo.Name, riderProjInfo); + } + + return info; + } + /// /// Generates all -related configuration files. /// @@ -282,7 +292,8 @@ public void Generate(Builder builder, Project project, List Date: Thu, 29 Jul 2021 20:47:57 +1000 Subject: [PATCH 05/37] [RiderJson] Add solution name specifier for RiderJson generator --- Sharpmake.Generators/Generic/RiderJson.cs | 71 ++++++++++++----------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index d160fcf44..b8fc78ad4 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -14,18 +14,21 @@ namespace Sharpmake.Generators.Generic /// public partial class RiderJson : IProjectGenerator { + public static string SolutionName = null; + /// /// Callback which should be added to in order to generate Rider project model. /// public static void PostGenerationCallback(List projects, List solutions) { var builder = Builder.Instance; - var riderFolder = Path.Combine(solutions.First().SharpmakeCsPath, ".Rider"); + var solution = solutions.FirstOrDefault(it => it.Name == SolutionName) ?? solutions.First(); + var riderFolder = Path.Combine(solution.SharpmakeCsPath, ".Rider"); var generator = new RiderJson(); - var configs = solutions.First().Configurations.ToList(); + var configs = solution.Configurations.ToList(); // Do not move. Acquires all the information about projects for later usage in "Modules" sections. - generator.Generate(builder, projects, configs, Path.Combine(riderFolder, "root.json"), new List(), + generator.Generate(builder, configs, Path.Combine(riderFolder, "root.json"), new List(), new List()); foreach (var project in projects) @@ -47,6 +50,7 @@ private class RiderProjectInfo public Strings PrivateIncludePaths { get; } public Strings PublicDefinitions { get; } public Strings PrivateDefinitions { get; } + public Strings Configurations { get; } public RiderProjectInfo(string projectName) { @@ -56,6 +60,7 @@ public RiderProjectInfo(string projectName) PrivateIncludePaths = new Strings(); PublicDefinitions = new Strings(); PrivateDefinitions = new Strings(); + Configurations = new Strings(); } /// @@ -68,6 +73,7 @@ public void ReadConfiguration(Project.Configuration config) PrivateIncludePaths.AddRange(config.IncludePrivatePaths); PublicDefinitions.AddRange(config.ExportDefines); PrivateDefinitions.AddRange(config.Defines); + Configurations.Add(config.Name); } /// @@ -220,24 +226,40 @@ private List GetFastBuildOptions() } /// - /// Generates "root.json" file, gathers information about projects for later usage in "Modules" section. + /// Generates "root.json" file for solution. + /// Also gathers information about projects for later usage in "Modules" section. /// - public void Generate(Builder builder, List projects, List configurations, string rootFile, List generatedFiles, + public void Generate(Builder builder, List configurations, string rootFile, List generatedFiles, List skipFiles) { - var projectsInfo = ReadProjects(projects); - + var info = new OrderedDictionary(); + foreach (var solutionConfig in configurations) { foreach (var proj in solutionConfig.IncludedProjectInfos) { - var projInfo = projectsInfo[proj.Project.Name] as Dictionary>; + if (!info.Contains(proj.Project.Name)) + { + info.Add(proj.Project.Name, new Dictionary>()); + _projectsInfo.Add(proj.Project.Name, new RiderProjectInfo(proj.Project.Name)); + } + + var riderProjInfo = _projectsInfo[proj.Project.Name]; + riderProjInfo.ReadConfiguration(proj.Configuration); + + var projObject = info[riderProjInfo.Name] as Dictionary>; var projConfig = new Dictionary(); - projConfig.Add("ProjectConfig", proj.Configuration.Name); + + projConfig.Add("ProjectConfig", riderProjInfo.Name); projConfig.Add("SolutionConfig", solutionConfig.Name); projConfig.Add("DoBuild", (proj.ToBuild != Solution.Configuration.IncludedProjectInfo.Build.No).ToString()); - projInfo[proj.Configuration.Platform.ToString()].Add(projConfig); + if (!projObject.ContainsKey(proj.Configuration.Platform.ToString())) + { + projObject.Add(proj.Configuration.Platform.ToString(), new List()); + } + + projObject[proj.Configuration.Platform.ToString()].Add(projConfig); } } @@ -247,7 +269,7 @@ public void Generate(Builder builder, List projects, List projects, List projects) - { - var info = new OrderedDictionary(); - foreach (var project in projects) { - var riderProjInfo = new RiderProjectInfo(project.Name); - var initialProjectInfo = new Dictionary>(); - - foreach (var config in project.Configurations) { - riderProjInfo.ReadConfiguration(config); - if (!initialProjectInfo.ContainsKey(config.Platform.ToString())) { - initialProjectInfo.Add(config.Platform.ToString(), new List()); - } - } - - info.Add(project.Name, initialProjectInfo); - - _projectsInfo.Add(riderProjInfo.Name, riderProjInfo); - } - - return info; - } - /// /// Generates all -related configuration files. /// @@ -291,6 +291,11 @@ public void Generate(Builder builder, Project project, List Date: Fri, 30 Jul 2021 13:24:44 +1000 Subject: [PATCH 06/37] [RiderJson] Change EnvironmentDefinitions source to IPlatformVcxproj.GetImplicitlyDefinedSymbols(). --- Sharpmake.Generators/Generic/RiderJson.cs | 2 +- Sharpmake.Generators/Generic/RiderJson.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index b8fc78ad4..118e8bb54 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -359,7 +359,7 @@ private void GenerateConfiguration(RiderGenerationContext context, List info.Add("Platform", context.Configuration.Platform.ToString()); info.Add("ToolchainInfo", toolchain); info.Add("EnvironmentIncludePaths", includePaths); - info.Add("EnvironmentDefinitions", context.Configuration.Defines); + info.Add("EnvironmentDefinitions", platformVcxproj.GetImplicitlyDefinedSymbols(context)); info.Add("Modules", modules); var file = new FileInfo($"{context.ProjectPath}_{context.Configuration.Platform}_{context.Configuration.Name}.json"); diff --git a/Sharpmake.Generators/Generic/RiderJson.md b/Sharpmake.Generators/Generic/RiderJson.md index 9beec6619..e8d8ed90e 100644 --- a/Sharpmake.Generators/Generic/RiderJson.md +++ b/Sharpmake.Generators/Generic/RiderJson.md @@ -22,7 +22,7 @@ The following is the mapping of Sharpmake properties to Rider Json. | ``Project.Configuration.Name`` | ``Configuration`` | | ``Configuration.Platform`` | ``Platform`` | | ``IPlatformVcxproj.GetPlatformIncludePaths()`` | ``EnvironmentIncludePaths`` | -| ``Project.Configuration.Defines`` | ``EnvironmentDefinitions`` | +| ``IPlatformVcxproj.GetImplicitlyDefinedSymbols()`` | ``EnvironmentDefinitions`` | | ``Project.Configuration.ResolvedDependencies`` | ``Modules`` | ### Toolchain Info From 8f141dc913c7319c8b3634e9b0d2abf1f00a7e57 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Mon, 2 Aug 2021 17:32:32 +1000 Subject: [PATCH 07/37] [RiderJson] Add sample for RiderJson, add output directory specifier. --- Sharpmake.Generators/Generic/RiderJson.cs | 7 +- samples/RiderJson/RiderJson.sharpmake.cs | 188 ++++++++++++++++++ .../codebase/executable1/private/main.cpp | 8 + .../codebase/executable2/private/function.cpp | 11 + .../codebase/library1/private/function1.cpp | 7 + .../codebase/library1/public/apiexport.hpp | 23 +++ .../codebase/library1/public/function1.hpp | 8 + .../codebase/library1/public/precomp.cpp | 1 + .../codebase/library1/public/precomp.hpp | 6 + .../codebase/library2/private/function2.cpp | 8 + .../codebase/library2/public/apiexport.hpp | 23 +++ .../codebase/library2/public/function2.hpp | 8 + .../codebase/library2/public/precomp.cpp | 1 + .../codebase/library2/public/precomp.hpp | 6 + 14 files changed, 302 insertions(+), 3 deletions(-) create mode 100644 samples/RiderJson/RiderJson.sharpmake.cs create mode 100644 samples/RiderJson/codebase/executable1/private/main.cpp create mode 100644 samples/RiderJson/codebase/executable2/private/function.cpp create mode 100644 samples/RiderJson/codebase/library1/private/function1.cpp create mode 100644 samples/RiderJson/codebase/library1/public/apiexport.hpp create mode 100644 samples/RiderJson/codebase/library1/public/function1.hpp create mode 100644 samples/RiderJson/codebase/library1/public/precomp.cpp create mode 100644 samples/RiderJson/codebase/library1/public/precomp.hpp create mode 100644 samples/RiderJson/codebase/library2/private/function2.cpp create mode 100644 samples/RiderJson/codebase/library2/public/apiexport.hpp create mode 100644 samples/RiderJson/codebase/library2/public/function2.hpp create mode 100644 samples/RiderJson/codebase/library2/public/precomp.cpp create mode 100644 samples/RiderJson/codebase/library2/public/precomp.hpp diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 118e8bb54..62e38aac0 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -14,7 +14,8 @@ namespace Sharpmake.Generators.Generic /// public partial class RiderJson : IProjectGenerator { - public static string SolutionName = null; + public static string SolutionName = null; + public static string OutputPath = ""; /// /// Callback which should be added to in order to generate Rider project model. @@ -23,7 +24,7 @@ public static void PostGenerationCallback(List projects, List { var builder = Builder.Instance; var solution = solutions.FirstOrDefault(it => it.Name == SolutionName) ?? solutions.First(); - var riderFolder = Path.Combine(solution.SharpmakeCsPath, ".Rider"); + var riderFolder = Path.Combine(solution.SharpmakeCsPath, OutputPath, ".Rider"); var generator = new RiderJson(); var configs = solution.Configurations.ToList(); @@ -250,7 +251,7 @@ public void Generate(Builder builder, List configuration var projObject = info[riderProjInfo.Name] as Dictionary>; var projConfig = new Dictionary(); - projConfig.Add("ProjectConfig", riderProjInfo.Name); + projConfig.Add("ProjectConfig", proj.Configuration.Name); projConfig.Add("SolutionConfig", solutionConfig.Name); projConfig.Add("DoBuild", (proj.ToBuild != Solution.Configuration.IncludedProjectInfo.Build.No).ToString()); diff --git a/samples/RiderJson/RiderJson.sharpmake.cs b/samples/RiderJson/RiderJson.sharpmake.cs new file mode 100644 index 000000000..c00e4b804 --- /dev/null +++ b/samples/RiderJson/RiderJson.sharpmake.cs @@ -0,0 +1,188 @@ +using System.IO; +using Sharpmake; + +namespace RiderJson +{ + public class BaseProject : Project + { + public BaseProject() + { + AddTargets(new Target( + Platform.win64, + DevEnv.vs2019, + Optimization.Debug | Optimization.Release, + OutputType.Lib, + Blob.NoBlob, + BuildSystem.FastBuild | BuildSystem.MSBuild)); + } + + [Configure] + public virtual void ConfigureAll(Configuration conf, Target target) + { + conf.ProjectPath = @"[project.SharpmakeCsPath]\projects"; + conf.Name = "[target.Optimization] [target.BuildSystem]"; + conf.IntermediatePath = @"[conf.ProjectPath]\obj\[project.Name]\[target.Platform]_[target.Optimization]_[target.DevEnv]"; + conf.IsFastBuild = target.BuildSystem == BuildSystem.FastBuild; + conf.IsBlobbed = target.Blob != Blob.NoBlob; + conf.FastBuildBlobbed = conf.IsBlobbed; + conf.AdditionalCompilerOptions.Add("/FS"); + } + } + + public class LibraryBaseProject : BaseProject + { + public override void ConfigureAll(Configuration conf, Target target) + { + base.ConfigureAll(conf, target); + + conf.IncludePaths.Add(@"[project.SourceRootPath]\public"); + conf.IncludePrivatePaths.Add(@"[project.SourceRootPath]\private"); + conf.PrecompHeader = "precomp.hpp"; + conf.PrecompSource = "precomp.cpp"; + conf.Defines.Add("LIBRARY_COMPILE"); + + conf.Output = Configuration.OutputType.Lib; + } + } + + [Generate] + public class LibraryProject1 : LibraryBaseProject + { + public LibraryProject1() + { + Name = "Lib1_Proj"; + SourceRootPath = @"[project.SharpmakeCsPath]\codebase\library1"; + } + } + + [Generate] + public class LibraryProject2 : LibraryBaseProject + { + public LibraryProject2() + { + Name = "Lib2_Proj"; + SourceRootPath = @"[project.SharpmakeCsPath]\codebase\library2"; + } + + public override void ConfigureAll(Configuration conf, Target target) + { + base.ConfigureAll(conf, target); + conf.AddPublicDependency(target); + } + } + + [Generate] + public class ExecutableProject1 : BaseProject + { + public ExecutableProject1() + { + Name = "Exe1_Proj"; + SourceRootPath = @"[project.SharpmakeCsPath]\codebase\executable1"; + } + + public override void ConfigureAll(Configuration conf, Target target) + { + base.ConfigureAll(conf, target); + conf.AddPrivateDependency(target); + } + } + + [Generate] + public class ExecutableProject2 : BaseProject + { + public ExecutableProject2() + { + Name = "Exe2_Proj"; + SourceRootPath = @"[project.SharpmakeCsPath]\codebase\executable2"; + } + + public override void ConfigureAll(Configuration conf, Target target) + { + base.ConfigureAll(conf, target); + conf.AddPrivateDependency(target); + } + } + + public class BaseSolution : Solution + { + public BaseSolution() + { + AddTargets(new Target( + Platform.win64, + DevEnv.vs2019, + Optimization.Debug | Optimization.Release, + OutputType.Lib, + Blob.NoBlob, + BuildSystem.FastBuild | BuildSystem.MSBuild)); + } + + [Configure] + public virtual void ConfigureAll(Configuration conf, Target target) + { + conf.Name = @"[solution.Name] [target.Optimization] [target.BuildSystem]"; + conf.SolutionPath = @"[solution.SharpmakeCsPath]\projects"; + } + } + + [Generate] + public class FirstSolution : BaseSolution + { + public FirstSolution() + { + Name = "Sol1"; + } + + public override void ConfigureAll(Configuration conf, Target target) + { + base.ConfigureAll(conf, target); + + conf.AddProject(target); + conf.AddProject(target); + conf.AddProject(target); + } + } + + [Generate] + public class SecondSolution : BaseSolution + { + public SecondSolution() + { + Name = "Sol2"; + } + + public override void ConfigureAll(Configuration conf, Target target) + { + base.ConfigureAll(conf, target); + + conf.AddProject(target); + conf.AddProject(target); + conf.AddProject(target); + conf.AddProject(target); + } + } + + public static class Main + { + [Sharpmake.Main] + public static void SharpmakeMain(Sharpmake.Arguments args) + { + string relativeRootPath = @".\codebase"; + FileInfo fileInfo = Util.GetCurrentSharpmakeFileInfo(); + string rootDirectory = Path.Combine(fileInfo.DirectoryName, relativeRootPath); + var rootDir = Util.SimplifyPath(rootDirectory); + + FastBuildSettings.SetPathToResourceCompilerInEnvironment = true; + + KitsRootPaths.SetUseKitsRootForDevEnv(DevEnv.vs2019, KitsRootEnum.KitsRoot10, Options.Vc.General.WindowsTargetPlatformVersion.v10_0_19041_0); + string sharpmakeFastBuildDir = Util.PathGetAbsolute(rootDir, @"..\..\..\tools\FastBuild"); + FastBuildSettings.FastBuildMakeCommand = Path.Combine(sharpmakeFastBuildDir, "Windows-x64", "FBuild.exe"); + + args.Builder.EventPostGeneration += Sharpmake.Generators.Generic.RiderJson.PostGenerationCallback; + Sharpmake.Generators.Generic.RiderJson.SolutionName = "Sol1"; + Sharpmake.Generators.Generic.RiderJson.OutputPath = "projects"; + + args.Generate(); + args.Generate(); + } + } +} diff --git a/samples/RiderJson/codebase/executable1/private/main.cpp b/samples/RiderJson/codebase/executable1/private/main.cpp new file mode 100644 index 000000000..166a35641 --- /dev/null +++ b/samples/RiderJson/codebase/executable1/private/main.cpp @@ -0,0 +1,8 @@ +#include +#include + +int main() { + std::cout << Ack() << std::endl; + + return 0; +} diff --git a/samples/RiderJson/codebase/executable2/private/function.cpp b/samples/RiderJson/codebase/executable2/private/function.cpp new file mode 100644 index 000000000..f5c174f14 --- /dev/null +++ b/samples/RiderJson/codebase/executable2/private/function.cpp @@ -0,0 +1,11 @@ + +#include + +#include + +int main() { + + std::cout << Ack2() << std::endl; + + return 0; +} diff --git a/samples/RiderJson/codebase/library1/private/function1.cpp b/samples/RiderJson/codebase/library1/private/function1.cpp new file mode 100644 index 000000000..ad349e300 --- /dev/null +++ b/samples/RiderJson/codebase/library1/private/function1.cpp @@ -0,0 +1,7 @@ +#include "precomp.hpp" +#include "function1.hpp" + +long Ack() +{ + return 1; +} diff --git a/samples/RiderJson/codebase/library1/public/apiexport.hpp b/samples/RiderJson/codebase/library1/public/apiexport.hpp new file mode 100644 index 000000000..49d7c5a58 --- /dev/null +++ b/samples/RiderJson/codebase/library1/public/apiexport.hpp @@ -0,0 +1,23 @@ +#if !defined(_LIBRARY_APIEXPORT_HPP) +#define _LIBRARY_APIEXPORT_HPP + +// dllexport boilerplate +#if defined(LIBRARY_DLL) +# if defined(_MSC_VER) +# if defined(LIBRARY_COMPILE) +# define LIBRARY_API __declspec(dllexport) +# else +# define LIBRARY_API __declspec(dllimport) +# endif +# elif defined(__GNUC__) || defined(__clang__) +# if defined(LIBRARY_COMPILE) +# define LIBRARY_API __attribute__ ((visibility ("default"))) +# endif +# endif +#endif + +#if !defined(LIBRARY_API) +# define LIBRARY_API +#endif + +#endif // _LIBRARY_APIEXPORT_HPP diff --git a/samples/RiderJson/codebase/library1/public/function1.hpp b/samples/RiderJson/codebase/library1/public/function1.hpp new file mode 100644 index 000000000..7637736d1 --- /dev/null +++ b/samples/RiderJson/codebase/library1/public/function1.hpp @@ -0,0 +1,8 @@ +#if !defined(_LIBRARY_FUNCTION_HPP) +#define _LIBRARY_FUNCTION_HPP + +#include + +LIBRARY_API long Ack(); + +#endif // _LIBRARY_FUNCTION_HPP diff --git a/samples/RiderJson/codebase/library1/public/precomp.cpp b/samples/RiderJson/codebase/library1/public/precomp.cpp new file mode 100644 index 000000000..22b304542 --- /dev/null +++ b/samples/RiderJson/codebase/library1/public/precomp.cpp @@ -0,0 +1 @@ +#include "precomp.hpp" diff --git a/samples/RiderJson/codebase/library1/public/precomp.hpp b/samples/RiderJson/codebase/library1/public/precomp.hpp new file mode 100644 index 000000000..69dc56070 --- /dev/null +++ b/samples/RiderJson/codebase/library1/public/precomp.hpp @@ -0,0 +1,6 @@ +#if !defined(_FUNCTION_PRECOMP_HPP) +#define _FUNCTION_PRECOMP_HPP + +#include "apiexport.hpp" + +#endif // _FUNCTION_PRECOMP_HPP diff --git a/samples/RiderJson/codebase/library2/private/function2.cpp b/samples/RiderJson/codebase/library2/private/function2.cpp new file mode 100644 index 000000000..aab04ddc4 --- /dev/null +++ b/samples/RiderJson/codebase/library2/private/function2.cpp @@ -0,0 +1,8 @@ +#include "precomp.hpp" +#include +#include "function2.hpp" + +long Ack2() +{ + return Ack() * 2; +} diff --git a/samples/RiderJson/codebase/library2/public/apiexport.hpp b/samples/RiderJson/codebase/library2/public/apiexport.hpp new file mode 100644 index 000000000..49d7c5a58 --- /dev/null +++ b/samples/RiderJson/codebase/library2/public/apiexport.hpp @@ -0,0 +1,23 @@ +#if !defined(_LIBRARY_APIEXPORT_HPP) +#define _LIBRARY_APIEXPORT_HPP + +// dllexport boilerplate +#if defined(LIBRARY_DLL) +# if defined(_MSC_VER) +# if defined(LIBRARY_COMPILE) +# define LIBRARY_API __declspec(dllexport) +# else +# define LIBRARY_API __declspec(dllimport) +# endif +# elif defined(__GNUC__) || defined(__clang__) +# if defined(LIBRARY_COMPILE) +# define LIBRARY_API __attribute__ ((visibility ("default"))) +# endif +# endif +#endif + +#if !defined(LIBRARY_API) +# define LIBRARY_API +#endif + +#endif // _LIBRARY_APIEXPORT_HPP diff --git a/samples/RiderJson/codebase/library2/public/function2.hpp b/samples/RiderJson/codebase/library2/public/function2.hpp new file mode 100644 index 000000000..db57ffc1a --- /dev/null +++ b/samples/RiderJson/codebase/library2/public/function2.hpp @@ -0,0 +1,8 @@ +#if !defined(_LIBRARY_FUNCTION_HPP) +#define _LIBRARY_FUNCTION_HPP + +#include + +LIBRARY_API long Ack2(); + +#endif // _LIBRARY_FUNCTION_HPP diff --git a/samples/RiderJson/codebase/library2/public/precomp.cpp b/samples/RiderJson/codebase/library2/public/precomp.cpp new file mode 100644 index 000000000..22b304542 --- /dev/null +++ b/samples/RiderJson/codebase/library2/public/precomp.cpp @@ -0,0 +1 @@ +#include "precomp.hpp" diff --git a/samples/RiderJson/codebase/library2/public/precomp.hpp b/samples/RiderJson/codebase/library2/public/precomp.hpp new file mode 100644 index 000000000..69dc56070 --- /dev/null +++ b/samples/RiderJson/codebase/library2/public/precomp.hpp @@ -0,0 +1,6 @@ +#if !defined(_FUNCTION_PRECOMP_HPP) +#define _FUNCTION_PRECOMP_HPP + +#include "apiexport.hpp" + +#endif // _FUNCTION_PRECOMP_HPP From da41113ef37bd8ec89b562384fd1bf04ed22ba8d Mon Sep 17 00:00:00 2001 From: SmelJey Date: Mon, 9 Aug 2021 19:59:35 +1000 Subject: [PATCH 08/37] [RiderJson] Extract build commands from toolchain to separate object. Add "Minimize" and "IgnoreDefaults" parameters. --- Sharpmake.Generators/Generic/RiderJson.cs | 84 ++++++++++++++++++----- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 62e38aac0..18f1ef3c4 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -16,6 +16,8 @@ public partial class RiderJson : IProjectGenerator { public static string SolutionName = null; public static string OutputPath = ""; + public static bool Minimize = false; + public static bool IgnoreDefaults = false; /// /// Callback which should be added to in order to generate Rider project model. @@ -84,11 +86,31 @@ public void ReadConfiguration(Project.Configuration config) public OrderedDictionary ToDictionary() { var resDict = new OrderedDictionary(); - resDict.Add("PublicDependencyModules", PublicDependencyModules); - resDict.Add("PublicIncludePaths", PublicIncludePaths); - resDict.Add("PrivateIncludePaths", PrivateIncludePaths); - resDict.Add("PublicDefinitions", PublicDefinitions); - resDict.Add("PrivateDefinitions", PrivateDefinitions); + if (!IgnoreDefaults || PublicDependencyModules.Count != 0) + { + resDict.Add("PublicDependencyModules", PublicDependencyModules); + } + + if (!IgnoreDefaults || PublicIncludePaths.Count != 0) + { + resDict.Add("PublicIncludePaths", PublicIncludePaths); + } + + if (!IgnoreDefaults || PrivateIncludePaths.Count != 0) + { + resDict.Add("PrivateIncludePaths", PrivateIncludePaths); + } + + if (!IgnoreDefaults || PublicDefinitions.Count != 0) + { + resDict.Add("PublicDefinitions", PublicDefinitions); + } + + if (!IgnoreDefaults || PrivateDefinitions.Count != 0) + { + resDict.Add("PrivateDefinitions", PrivateDefinitions); + } + return resDict; } } @@ -253,7 +275,10 @@ public void Generate(Builder builder, List configuration projConfig.Add("ProjectConfig", proj.Configuration.Name); projConfig.Add("SolutionConfig", solutionConfig.Name); - projConfig.Add("DoBuild", (proj.ToBuild != Solution.Configuration.IncludedProjectInfo.Build.No).ToString()); + if (!IgnoreDefaults) + { + projConfig.Add("DoBuild", (proj.ToBuild != Solution.Configuration.IncludedProjectInfo.Build.No).ToString()); + } if (!projObject.ContainsKey(proj.Configuration.Platform.ToString())) { @@ -270,6 +295,7 @@ public void Generate(Builder builder, List configuration using (var writer = new StreamWriter(stream, new UTF8Encoding(false))) using (var serializer = new Util.JsonSerializer(writer) { IsOutputFormatted = true }) { + serializer.IsOutputFormatted = !Minimize; serializer.Serialize(info); serializer.Flush(); @@ -310,6 +336,7 @@ private void GenerateConfiguration(RiderGenerationContext context, List var includePaths = new Strings(); var modules = new OrderedDictionary(); var toolchain = new OrderedDictionary(); + var buildCommands = new OrderedDictionary(); toolchain.Add("CppStandard", GetCppStandart(context.Configuration)); toolchain.Add("bUseRTTI", IsRTTIEnabled(context.Configuration)); @@ -327,20 +354,17 @@ private void GenerateConfiguration(RiderGenerationContext context, List toolchain.Add("bStrictConformanceMode", IsConformanceMode(context.Configuration)); toolchain.Add("PrecompiledHeaderAction", GetPchAction(context)); - if (context.Configuration.IsFastBuild) + var beforeBuildCommand = context.Configuration.FastBuildCustomActionsBeforeBuildCommand; + if (beforeBuildCommand == FileGeneratorUtilities.RemoveLineTag) { - var beforeBuildCommand = context.Configuration.FastBuildCustomActionsBeforeBuildCommand; - if (beforeBuildCommand == FileGeneratorUtilities.RemoveLineTag) - { - beforeBuildCommand = ""; - } - - using (context.Resolver.NewScopedParameter("BeforeBuildCommand", beforeBuildCommand)) - { - toolchain.Add("BuildCmd", GetBuildCommand(context)); - toolchain.Add("ReBuildCmd", GetReBuildCommand(context)); - toolchain.Add("CleanCmd", GetCleanCommand(context)); - } + beforeBuildCommand = ""; + } + + using (context.Resolver.NewScopedParameter("BeforeBuildCommand", beforeBuildCommand)) + { + buildCommands.Add("BuildCmd", GetBuildCommand(context)); + buildCommands.Add("ReBuildCmd", GetReBuildCommand(context)); + buildCommands.Add("CleanCmd", GetCleanCommand(context)); } var platformVcxproj = PlatformRegistry.Query(context.Configuration.Platform); @@ -359,6 +383,12 @@ private void GenerateConfiguration(RiderGenerationContext context, List info.Add("Configuration", context.Configuration.Name); info.Add("Platform", context.Configuration.Platform.ToString()); info.Add("ToolchainInfo", toolchain); + + if (context.Configuration.IsFastBuild || !IgnoreDefaults) + { + info.Add("BuildCommands", buildCommands); + } + info.Add("EnvironmentIncludePaths", includePaths); info.Add("EnvironmentDefinitions", platformVcxproj.GetImplicitlyDefinedSymbols(context)); info.Add("Modules", modules); @@ -369,6 +399,7 @@ private void GenerateConfiguration(RiderGenerationContext context, List using (var writer = new StreamWriter(stream, new UTF8Encoding(false))) using (var serializer = new Util.JsonSerializer(writer) { IsOutputFormatted = true }) { + serializer.IsOutputFormatted = !Minimize; serializer.Serialize(info); serializer.Flush(); @@ -486,6 +517,11 @@ private string GetPchAction(RiderGenerationContext context) private string GetBuildCommand(RiderGenerationContext context) { + if (!context.Configuration.IsFastBuild) + { + return ""; + } + var unresolvedCommand = Template.FastBuildBuildCommand; using (context.Resolver.NewScopedParameter("BuildCommand", context.FastBuildMakeCommandGenerator.GetCommand( @@ -498,6 +534,11 @@ private string GetBuildCommand(RiderGenerationContext context) private string GetReBuildCommand(RiderGenerationContext context) { + if (!context.Configuration.IsFastBuild) + { + return ""; + } + var unresolvedCommand = Template.FastBuildReBuildCommand; using (context.Resolver.NewScopedParameter("RebuildCommand", context.FastBuildMakeCommandGenerator.GetCommand( @@ -510,6 +551,11 @@ private string GetReBuildCommand(RiderGenerationContext context) private string GetCleanCommand(RiderGenerationContext context) { + if (!context.Configuration.IsFastBuild) + { + return ""; + } + var unresolvedOutput = Template.FastBuildCleanCommand; using (context.Resolver.NewScopedParameter("IntermediateDirectory", context.Options["IntermediateDirectory"])) From 1bd69a5a6e95d10c8017121bea13b7256719cb9f Mon Sep 17 00:00:00 2001 From: SmelJey Date: Mon, 9 Aug 2021 20:01:08 +1000 Subject: [PATCH 09/37] [RiderJson] Add PrivateDependencyModules, SourceRoot and SourceExtensions properties to Module --- Sharpmake.Generators/Generic/RiderJson.cs | 27 ++++++++++++++++++++--- Sharpmake.Generators/Generic/RiderJson.md | 3 +++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 18f1ef3c4..386005644 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -48,17 +48,25 @@ public static void PostGenerationCallback(List projects, List private class RiderProjectInfo { public string Name { get; } + public string SourcePath { get; } + public Strings SourceExtensions { get; } + public Strings PublicDependencyModules { get; } + public Strings PrivateDependencyModules { get; } public Strings PublicIncludePaths { get; } public Strings PrivateIncludePaths { get; } public Strings PublicDefinitions { get; } public Strings PrivateDefinitions { get; } public Strings Configurations { get; } - public RiderProjectInfo(string projectName) + public RiderProjectInfo(Project project) { - Name = projectName; + Name = project.Name; + SourceExtensions = project.SourceFilesExtensions; + SourcePath = project.SourceRootPath; + PublicDependencyModules = new Strings(); + PrivateDependencyModules = new Strings(); PublicIncludePaths = new Strings(); PrivateIncludePaths = new Strings(); PublicDefinitions = new Strings(); @@ -72,6 +80,7 @@ public RiderProjectInfo(string projectName) public void ReadConfiguration(Project.Configuration config) { PublicDependencyModules.AddRange(config.ResolvedPublicDependencies.Select(it => it.Project.Name)); + PrivateDependencyModules.AddRange(config.ResolvedPrivateDependencies.Select(it => it.Project.Name)); PublicIncludePaths.AddRange(config.IncludePaths); PrivateIncludePaths.AddRange(config.IncludePrivatePaths); PublicDefinitions.AddRange(config.ExportDefines); @@ -86,10 +95,22 @@ public void ReadConfiguration(Project.Configuration config) public OrderedDictionary ToDictionary() { var resDict = new OrderedDictionary(); + resDict.Add("SourcePath", SourcePath); + + if (!IgnoreDefaults || !SourceExtensions.All(new Project().SourceFilesExtensions.Contains)) + { + resDict.Add("SourceExtensions", SourceExtensions); + } + if (!IgnoreDefaults || PublicDependencyModules.Count != 0) { resDict.Add("PublicDependencyModules", PublicDependencyModules); } + + if (!IgnoreDefaults || PrivateDependencyModules.Count != 0) + { + resDict.Add("PrivateDependencyModules", PrivateDependencyModules); + } if (!IgnoreDefaults || PublicIncludePaths.Count != 0) { @@ -264,7 +285,7 @@ public void Generate(Builder builder, List configuration if (!info.Contains(proj.Project.Name)) { info.Add(proj.Project.Name, new Dictionary>()); - _projectsInfo.Add(proj.Project.Name, new RiderProjectInfo(proj.Project.Name)); + _projectsInfo.Add(proj.Project.Name, new RiderProjectInfo(proj.Project)); } var riderProjInfo = _projectsInfo[proj.Project.Name]; diff --git a/Sharpmake.Generators/Generic/RiderJson.md b/Sharpmake.Generators/Generic/RiderJson.md index e8d8ed90e..4bee26161 100644 --- a/Sharpmake.Generators/Generic/RiderJson.md +++ b/Sharpmake.Generators/Generic/RiderJson.md @@ -45,7 +45,10 @@ The following is the mapping of Sharpmake properties to Rider Json. ### Modules info | Sharpmake | Rider Json | | --------- | ---------- | +| ``Project.SourceRootPath`` | ``SourcePath`` | +| ``Project.SourceFilesExtensions`` | ``SourceExtensions`` | | ``Project.Configuration.ResolvedPublicDependencies`` | ``PublicDependencyModules`` | +| ``Project.Configuration.ResolvedPrivateDependencies`` | ``PrivateDependencyModules`` | | ``Project.Configuration.IncludePaths`` | ``PublicIncludePaths`` | | ``Project.Configuration.IncludePrivatePaths`` | ``PrivateIncludePaths`` | | ``Project.Configuration.ExportDefines`` | ``PublicDefinitions`` | From da9213965833878436360080e42294e4e01dd2df Mon Sep 17 00:00:00 2001 From: SmelJey Date: Mon, 16 Aug 2021 12:54:26 +1000 Subject: [PATCH 10/37] [RiderJson] Change RiderJson solution file extension, extract solution file from .Rider folder --- Sharpmake.Generators/Generic/RiderJson.cs | 23 ++++++++++++++--------- samples/RiderJson/RiderJson.sharpmake.cs | 3 ++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 386005644..6da3930c2 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -12,10 +12,11 @@ namespace Sharpmake.Generators.Generic /// /// Generator for Rider project model json files. /// - public partial class RiderJson : IProjectGenerator + public partial class RiderJson : IProjectGenerator, ISolutionGenerator { public static string SolutionName = null; - public static string OutputPath = ""; + public static string RiderFolderPath = ""; + public static string SolutionFilePath = ""; public static bool Minimize = false; public static bool IgnoreDefaults = false; @@ -26,12 +27,12 @@ public static void PostGenerationCallback(List projects, List { var builder = Builder.Instance; var solution = solutions.FirstOrDefault(it => it.Name == SolutionName) ?? solutions.First(); - var riderFolder = Path.Combine(solution.SharpmakeCsPath, OutputPath, ".Rider"); + var riderFolder = Path.Combine(solution.SharpmakeCsPath, RiderFolderPath, ".Rider"); var generator = new RiderJson(); var configs = solution.Configurations.ToList(); // Do not move. Acquires all the information about projects for later usage in "Modules" sections. - generator.Generate(builder, configs, Path.Combine(riderFolder, "root.json"), new List(), + generator.Generate(builder, solution, configs, Path.Combine(solution.SharpmakeCsPath, SolutionFilePath, solution.Name + ".rdjson"), new List(), new List()); foreach (var project in projects) @@ -273,25 +274,27 @@ private List GetFastBuildOptions() /// Generates "root.json" file for solution. /// Also gathers information about projects for later usage in "Modules" section. /// - public void Generate(Builder builder, List configurations, string rootFile, List generatedFiles, + public void Generate(Builder builder, Solution solution, List configurations, string solutionFile, List generatedFiles, List skipFiles) { var info = new OrderedDictionary(); + info.Add("ProjectFolderPath", Path.Combine(solution.SharpmakeCsPath, RiderFolderPath, ".Rider")); + var projects = new OrderedDictionary(); foreach (var solutionConfig in configurations) { foreach (var proj in solutionConfig.IncludedProjectInfos) { - if (!info.Contains(proj.Project.Name)) + if (!projects.Contains(proj.Project.Name)) { - info.Add(proj.Project.Name, new Dictionary>()); + projects.Add(proj.Project.Name, new Dictionary>()); _projectsInfo.Add(proj.Project.Name, new RiderProjectInfo(proj.Project)); } var riderProjInfo = _projectsInfo[proj.Project.Name]; riderProjInfo.ReadConfiguration(proj.Configuration); - var projObject = info[riderProjInfo.Name] as Dictionary>; + var projObject = projects[riderProjInfo.Name] as Dictionary>; var projConfig = new Dictionary(); projConfig.Add("ProjectConfig", proj.Configuration.Name); @@ -309,8 +312,10 @@ public void Generate(Builder builder, List configuration projObject[proj.Configuration.Platform.ToString()].Add(projConfig); } } + + info.Add("Projects", projects); - var file = new FileInfo(rootFile); + var file = new FileInfo(solutionFile); using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream, new UTF8Encoding(false))) diff --git a/samples/RiderJson/RiderJson.sharpmake.cs b/samples/RiderJson/RiderJson.sharpmake.cs index c00e4b804..b454e85c6 100644 --- a/samples/RiderJson/RiderJson.sharpmake.cs +++ b/samples/RiderJson/RiderJson.sharpmake.cs @@ -179,7 +179,8 @@ public static void SharpmakeMain(Sharpmake.Arguments args) args.Builder.EventPostGeneration += Sharpmake.Generators.Generic.RiderJson.PostGenerationCallback; Sharpmake.Generators.Generic.RiderJson.SolutionName = "Sol1"; - Sharpmake.Generators.Generic.RiderJson.OutputPath = "projects"; + Sharpmake.Generators.Generic.RiderJson.RiderFolderPath = "projects"; + Sharpmake.Generators.Generic.RiderJson.SolutionFilePath = "projects"; args.Generate(); args.Generate(); From 34c474120b38a6d2e56ac74e81c89cc242ce82d5 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Tue, 17 Aug 2021 15:53:01 +1000 Subject: [PATCH 11/37] [RiderJson] Resolve $(ProjectDir) variable in build commands, add missing solution bff file. --- Sharpmake.Generators/Generic/RiderJson.Template.cs | 2 ++ Sharpmake.Generators/Generic/RiderJson.cs | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.Template.cs b/Sharpmake.Generators/Generic/RiderJson.Template.cs index c4a9bc2be..965c74dcb 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Template.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Template.cs @@ -2,6 +2,8 @@ { public partial class RiderJson { + + // See Sharpmake.BasePlatform.GenerateProjectConfigurationFastBuildMakeFile() public static class Template { public static string FastBuildBuildCommand = @"cd $(SolutionDir) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 6da3930c2..c2e883b7d 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -266,6 +266,8 @@ private List GetFastBuildOptions() if (!string.IsNullOrEmpty(Configuration.FastBuildCustomArgs)) fastBuildCommandLineOptions.Add(Configuration.FastBuildCustomArgs); + fastBuildCommandLineOptions.Add(" -config $(SolutionName)" + FastBuildSettings.FastBuildConfigFileExtension); + return fastBuildCommandLineOptions; } } @@ -290,7 +292,7 @@ public void Generate(Builder builder, Solution solution, List>()); _projectsInfo.Add(proj.Project.Name, new RiderProjectInfo(proj.Project)); } - + var riderProjInfo = _projectsInfo[proj.Project.Name]; riderProjInfo.ReadConfiguration(proj.Configuration); @@ -386,6 +388,7 @@ private void GenerateConfiguration(RiderGenerationContext context, List beforeBuildCommand = ""; } + using (context.Resolver.NewScopedParameter("ProjectDir", context.Configuration.ProjectPath)) using (context.Resolver.NewScopedParameter("BeforeBuildCommand", beforeBuildCommand)) { buildCommands.Add("BuildCmd", GetBuildCommand(context)); @@ -547,14 +550,14 @@ private string GetBuildCommand(RiderGenerationContext context) { return ""; } - + var unresolvedCommand = Template.FastBuildBuildCommand; using (context.Resolver.NewScopedParameter("BuildCommand", context.FastBuildMakeCommandGenerator.GetCommand( FastBuildMakeCommandGenerator.BuildType.Build, context.Configuration, context.FastBuildArguments))) { - return context.Resolver.Resolve(unresolvedCommand); + return context.Resolver.Resolve(unresolvedCommand).Replace("$(ProjectDir)", context.Configuration.ProjectPath + "\\"); } } @@ -571,7 +574,7 @@ private string GetReBuildCommand(RiderGenerationContext context) FastBuildMakeCommandGenerator.BuildType.Rebuild, context.Configuration, context.FastBuildArguments))) { - return context.Resolver.Resolve(unresolvedCommand); + return context.Resolver.Resolve(unresolvedCommand).Replace("$(ProjectDir)", context.Configuration.ProjectPath + "\\"); } } From 77fb6ddb10ec4d4841d1688fd8a0b4ab68cf7c27 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Thu, 19 Aug 2021 17:02:14 +1000 Subject: [PATCH 12/37] [RiderJson] Add "TargetPath" to configuration json for fastbuild, rename "BuildCommands" to "BuildInfo" --- Sharpmake.Generators/Generic/RiderJson.cs | 12 +++++++----- samples/RiderJson/RiderJson.sharpmake.cs | 8 ++++---- .../executable2/private/{function.cpp => main.cpp} | 0 3 files changed, 11 insertions(+), 9 deletions(-) rename samples/RiderJson/codebase/executable2/private/{function.cpp => main.cpp} (100%) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index c2e883b7d..322cb8112 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -364,7 +364,7 @@ private void GenerateConfiguration(RiderGenerationContext context, List var includePaths = new Strings(); var modules = new OrderedDictionary(); var toolchain = new OrderedDictionary(); - var buildCommands = new OrderedDictionary(); + var buildInfo = new OrderedDictionary(); toolchain.Add("CppStandard", GetCppStandart(context.Configuration)); toolchain.Add("bUseRTTI", IsRTTIEnabled(context.Configuration)); @@ -391,9 +391,11 @@ private void GenerateConfiguration(RiderGenerationContext context, List using (context.Resolver.NewScopedParameter("ProjectDir", context.Configuration.ProjectPath)) using (context.Resolver.NewScopedParameter("BeforeBuildCommand", beforeBuildCommand)) { - buildCommands.Add("BuildCmd", GetBuildCommand(context)); - buildCommands.Add("ReBuildCmd", GetReBuildCommand(context)); - buildCommands.Add("CleanCmd", GetCleanCommand(context)); + var targetPath = Path.Combine(context.Configuration.TargetPath, context.Configuration.TargetFileFullNameWithExtension); + buildInfo.Add("TargetPath", targetPath); + buildInfo.Add("BuildCmd", GetBuildCommand(context)); + buildInfo.Add("ReBuildCmd", GetReBuildCommand(context)); + buildInfo.Add("CleanCmd", GetCleanCommand(context)); } var platformVcxproj = PlatformRegistry.Query(context.Configuration.Platform); @@ -415,7 +417,7 @@ private void GenerateConfiguration(RiderGenerationContext context, List if (context.Configuration.IsFastBuild || !IgnoreDefaults) { - info.Add("BuildCommands", buildCommands); + info.Add("BuildInfo", buildInfo); } info.Add("EnvironmentIncludePaths", includePaths); diff --git a/samples/RiderJson/RiderJson.sharpmake.cs b/samples/RiderJson/RiderJson.sharpmake.cs index b454e85c6..93f056c88 100644 --- a/samples/RiderJson/RiderJson.sharpmake.cs +++ b/samples/RiderJson/RiderJson.sharpmake.cs @@ -12,7 +12,7 @@ public BaseProject() DevEnv.vs2019, Optimization.Debug | Optimization.Release, OutputType.Lib, - Blob.NoBlob, + Blob.FastBuildUnitys, BuildSystem.FastBuild | BuildSystem.MSBuild)); } @@ -23,8 +23,8 @@ public virtual void ConfigureAll(Configuration conf, Target target) conf.Name = "[target.Optimization] [target.BuildSystem]"; conf.IntermediatePath = @"[conf.ProjectPath]\obj\[project.Name]\[target.Platform]_[target.Optimization]_[target.DevEnv]"; conf.IsFastBuild = target.BuildSystem == BuildSystem.FastBuild; - conf.IsBlobbed = target.Blob != Blob.NoBlob; - conf.FastBuildBlobbed = conf.IsBlobbed; + conf.IsBlobbed = target.Blob == Blob.Blob; + conf.FastBuildBlobbed = target.Blob == Blob.FastBuildUnitys; conf.AdditionalCompilerOptions.Add("/FS"); } } @@ -112,7 +112,7 @@ public BaseSolution() DevEnv.vs2019, Optimization.Debug | Optimization.Release, OutputType.Lib, - Blob.NoBlob, + Blob.FastBuildUnitys, BuildSystem.FastBuild | BuildSystem.MSBuild)); } diff --git a/samples/RiderJson/codebase/executable2/private/function.cpp b/samples/RiderJson/codebase/executable2/private/main.cpp similarity index 100% rename from samples/RiderJson/codebase/executable2/private/function.cpp rename to samples/RiderJson/codebase/executable2/private/main.cpp From 3f994fc8e5afade631caf4af495db590eff2dc0a Mon Sep 17 00:00:00 2001 From: SmelJey Date: Fri, 20 Aug 2021 18:12:34 +1000 Subject: [PATCH 13/37] [RiderJson] Fix incorrect IntermediateDirectory and OutputDirectory options of RiderGenerationContext --- Sharpmake.Generators/Generic/RiderJson.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 322cb8112..624c7be0b 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -150,7 +150,7 @@ private class RiderGenerationContext : IGenerationContext public Builder Builder { get; } public Project Project { get; } public Project.Configuration Configuration { get; } - public string ProjectDirectory { get; } + public string ProjectDirectory { get; set; } public string ProjectFileName { get; } public string ProjectPath { get; } @@ -352,8 +352,13 @@ public void Generate(Builder builder, Project project, List Date: Fri, 20 Aug 2021 19:40:12 +1000 Subject: [PATCH 14/37] [RiderJson] Add $(ProjectDir) and $(SolutionName) resolving in fastbuild build commands, change Clean command to remove .pdb and .pch files --- Sharpmake.Generators/Generic/RiderJson.Template.cs | 6 ++++-- Sharpmake.Generators/Generic/RiderJson.cs | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.Template.cs b/Sharpmake.Generators/Generic/RiderJson.Template.cs index 965c74dcb..b40e3b7ce 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Template.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Template.cs @@ -6,11 +6,11 @@ public partial class RiderJson // See Sharpmake.BasePlatform.GenerateProjectConfigurationFastBuildMakeFile() public static class Template { - public static string FastBuildBuildCommand = @"cd $(SolutionDir) + public static string FastBuildBuildCommand = @"cd [SolutionDir] [BeforeBuildCommand] [BuildCommand]"; - public static string FastBuildReBuildCommand = @"cd $(SolutionDir) + public static string FastBuildReBuildCommand = @"cd [SolutionDir] [BeforeBuildCommand] [RebuildCommand]"; @@ -18,6 +18,8 @@ public static class Template del ""[IntermediateDirectory]\*.obj"" >NUL 2>NUL del ""[IntermediateDirectory]\*.a"" >NUL 2>NUL del ""[IntermediateDirectory]\*.lib"" >NUL 2>NUL +del ""[IntermediateDirectory]\*.pch"" >NUL 2>NUL +del ""[IntermediateDirectory]\*.pdb"" >NUL 2>NUL del ""[OutputDirectory]\[TargetFileFullName].exe"" >NUL 2>NUL del ""[OutputDirectory]\[TargetFileFullName].elf"" >NUL 2>NUL del ""[OutputDirectory]\[TargetFileFullName].exp"" >NUL 2>NUL diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 624c7be0b..018e32779 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -393,6 +393,7 @@ private void GenerateConfiguration(RiderGenerationContext context, List beforeBuildCommand = ""; } + using (context.Resolver.NewScopedParameter("SolutionDir", Path.Combine(context.Project.SharpmakeCsPath, SolutionFilePath))) using (context.Resolver.NewScopedParameter("ProjectDir", context.Configuration.ProjectPath)) using (context.Resolver.NewScopedParameter("BeforeBuildCommand", beforeBuildCommand)) { @@ -564,7 +565,9 @@ private string GetBuildCommand(RiderGenerationContext context) FastBuildMakeCommandGenerator.BuildType.Build, context.Configuration, context.FastBuildArguments))) { - return context.Resolver.Resolve(unresolvedCommand).Replace("$(ProjectDir)", context.Configuration.ProjectPath + "\\"); + return context.Resolver.Resolve(unresolvedCommand) + .Replace("$(ProjectDir)", context.Configuration.ProjectPath + "\\") + .Replace("$(SolutionName)", SolutionName); } } @@ -581,7 +584,9 @@ private string GetReBuildCommand(RiderGenerationContext context) FastBuildMakeCommandGenerator.BuildType.Rebuild, context.Configuration, context.FastBuildArguments))) { - return context.Resolver.Resolve(unresolvedCommand).Replace("$(ProjectDir)", context.Configuration.ProjectPath + "\\"); + return context.Resolver.Resolve(unresolvedCommand) + .Replace("$(ProjectDir)", context.Configuration.ProjectPath + "\\") + .Replace("$(SolutionName)", SolutionName); } } From f8d828fa0cbf73893e9576cb9f0215b2368fee83 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Mon, 23 Aug 2021 10:41:14 +1000 Subject: [PATCH 15/37] [RiderJson] Add Architecture field to ToolchainInfo. Map output CppLanguageStandard and PchAction to RiderJson values. --- .../Generic/RiderJson.Util.cs | 225 +++++++++++++++++- Sharpmake.Generators/Generic/RiderJson.cs | 150 ++---------- samples/RiderJson/RiderJson.sharpmake.cs | 1 + 3 files changed, 247 insertions(+), 129 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.Util.cs b/Sharpmake.Generators/Generic/RiderJson.Util.cs index c11981218..cff5d5fb6 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Util.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Util.cs @@ -1,16 +1,235 @@ using System; using System.Linq; +using Sharpmake.Generators.VisualStudio; namespace Sharpmake.Generators.Generic { public static class RiderJsonUtil { - public static bool CheckOptions(this Project.Configuration config, params object[] options) + private static class CppLanguageStandard + { + public const string Cpp14 = "Cpp14"; + public const string Cpp17 = "Cpp17"; + public const string Latest = "Latest"; + public const string Default = "Default"; + } + + private static class PchAction + { + public const string None = "None"; + public const string Include = "Include"; + public const string Create = "Create"; + } + + public static string GetCppStandard(this IGenerationContext context) + { + var res = CppLanguageStandard.Default; + if (Options.HasOption(context.Configuration)) + { + context.SelectOptionWithFallback + ( + () => res = CppLanguageStandard.Default, + Options.Option(Options.Vc.Compiler.CppLanguageStandard.CPP14, () => res = CppLanguageStandard.Cpp14), + Options.Option(Options.Vc.Compiler.CppLanguageStandard.GNU14, () => res = CppLanguageStandard.Cpp14), + Options.Option(Options.Vc.Compiler.CppLanguageStandard.CPP17, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.Vc.Compiler.CppLanguageStandard.GNU17, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.Vc.Compiler.CppLanguageStandard.Latest, () => res = CppLanguageStandard.Latest) + ); + return res; + } + if (Options.HasOption(context.Configuration)) + { + context.SelectOptionWithFallback + ( + () => res = CppLanguageStandard.Default, + Options.Option(Options.Clang.Compiler.CppLanguageStandard.Cpp14, () => res = CppLanguageStandard.Cpp14), + Options.Option(Options.Clang.Compiler.CppLanguageStandard.GnuCpp14, () => res = CppLanguageStandard.Cpp14), + Options.Option(Options.Clang.Compiler.CppLanguageStandard.Cpp17, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.Clang.Compiler.CppLanguageStandard.GnuCpp17, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.Clang.Compiler.CppLanguageStandard.Cpp2a, () => res = CppLanguageStandard.Latest), + Options.Option(Options.Clang.Compiler.CppLanguageStandard.GnuCpp2a, () => res = CppLanguageStandard.Latest) + ); + return res; + } + if (Options.HasOption(context.Configuration)) + { + context.SelectOptionWithFallback + ( + () => res = CppLanguageStandard.Default, + Options.Option(Options.Makefile.Compiler.CppLanguageStandard.Cpp14, () => res = CppLanguageStandard.Cpp14), + Options.Option(Options.Makefile.Compiler.CppLanguageStandard.GnuCpp14, () => res = CppLanguageStandard.Cpp14), + Options.Option(Options.Makefile.Compiler.CppLanguageStandard.Cpp17, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.Makefile.Compiler.CppLanguageStandard.GnuCpp17, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.Makefile.Compiler.CppLanguageStandard.Cpp2a, () => res = CppLanguageStandard.Latest), + Options.Option(Options.Makefile.Compiler.CppLanguageStandard.GnuCpp2a, () => res = CppLanguageStandard.Latest) + ); + return res; + } + if (Options.HasOption(context.Configuration)) + { + context.SelectOptionWithFallback + ( + () => res = CppLanguageStandard.Default, + Options.Option(Options.XCode.Compiler.CppLanguageStandard.CPP14, () => res = CppLanguageStandard.Cpp14), + Options.Option(Options.XCode.Compiler.CppLanguageStandard.GNU14, () => res = CppLanguageStandard.Cpp14), + Options.Option(Options.XCode.Compiler.CppLanguageStandard.CPP17, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.XCode.Compiler.CppLanguageStandard.GNU17, () => res = CppLanguageStandard.Cpp17) + ); + return res; + } + + context.SelectOptionWithFallback + ( + () => res = CppLanguageStandard.Default, + Options.Option(Options.Android.Compiler.CppLanguageStandard.Cpp14, () => res = CppLanguageStandard.Cpp14), + Options.Option(Options.Android.Compiler.CppLanguageStandard.Cpp1y, () => res = CppLanguageStandard.Cpp14), + Options.Option(Options.Android.Compiler.CppLanguageStandard.GNU_Cpp14, () => res = CppLanguageStandard.Cpp14), + Options.Option(Options.Android.Compiler.CppLanguageStandard.GNU_Cpp1y, () => res = CppLanguageStandard.Cpp14), + Options.Option(Options.Android.Compiler.CppLanguageStandard.Cpp17, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.Android.Compiler.CppLanguageStandard.Cpp1z, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.Android.Compiler.CppLanguageStandard.GNU_Cpp17, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.Android.Compiler.CppLanguageStandard.GNU_Cpp1z, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.Android.Compiler.CppLanguageStandard.Cpp2a, () => res = CppLanguageStandard.Latest), + Options.Option(Options.Android.Compiler.CppLanguageStandard.GNU_Cpp2a, () => res = CppLanguageStandard.Latest) + ); + + return res; + } + + public static string GetArchitecture(this IGenerationContext context) + { + var architecture = Util.GetPlatformString(context.Configuration.Platform, context.Project, context.Configuration.Target); + if (architecture == "Any CPU") + { + architecture = "x64"; + } + + return architecture.ToLower(); + } + + public static bool IsRttiEnabled(this IGenerationContext context) + { + if (!context.Configuration.CheckOptions(Options.Vc.Compiler.RTTI.Disable, + Options.Makefile.Compiler.Rtti.Disable, + Options.XCode.Compiler.RTTI.Disable, + Options.Clang.Compiler.Rtti.Disable)) + { + // Check default value + return Options.GetObject(context.Configuration) != + Options.Vc.Compiler.RTTI.Disable; + } + + return false; + } + + public static bool IsExceptionEnabled(this IGenerationContext context) + { + if (!context.Configuration.CheckOptions(Options.Vc.Compiler.Exceptions.Disable, + Options.Makefile.Compiler.Exceptions.Disable, + Options.XCode.Compiler.Exceptions.Disable, + Options.Clang.Compiler.Exceptions.Disable, + Options.Android.Compiler.Exceptions.Disable)) + { + // Check default value + return Options.GetObject(context.Configuration) != Options.Vc.Compiler.Exceptions.Disable; + } + + return false; + } + + public static bool IsOptimizationEnabled(this IGenerationContext context) + { + if (!context.Configuration.CheckOptions( + Options.Vc.Compiler.Optimization.Disable, + Options.Makefile.Compiler.OptimizationLevel.Disable, + Options.XCode.Compiler.OptimizationLevel.Disable, + Options.Clang.Compiler.OptimizationLevel.Disable)) + { + // Check default value + return Options.GetObject(context.Configuration) != Options.Vc.Compiler.Optimization.Disable; + } + + return false; + } + + public static bool IsInliningEnabled(this IGenerationContext context) + { + return Options.GetObject(context.Configuration) != + Options.Vc.Compiler.Inline.Disable; + } + + public static bool IsBlob(this IGenerationContext context) + { + return context.Configuration.IsBlobbed || context.Configuration.FastBuildBlobbed; + } + + public static bool IsDebugInfo(this IGenerationContext context) + { + if (!context.Configuration.CheckOptions( + Options.Vc.General.DebugInformation.Disable, + Options.Makefile.Compiler.GenerateDebugInformation.Disable, + Options.XCode.Compiler.GenerateDebuggingSymbols.Disable, + Options.Clang.Compiler.GenerateDebugInformation.Disable, + Options.Android.Compiler.DebugInformationFormat.None)) + { + // Check default option + return Options.GetObject(context.Configuration) != + Options.Vc.General.DebugInformation.Disable; + } + + return false; + } + + public static bool IsAvx(this IGenerationContext context) + { + bool res = false; + context.SelectOptionWithFallback( + () => res = false, + Options.Option(Options.Vc.Compiler.EnhancedInstructionSet.AdvancedVectorExtensions, () => res = true), + Options.Option(Options.Vc.Compiler.EnhancedInstructionSet.AdvancedVectorExtensions2, () => res = true), + Options.Option(Options.Vc.Compiler.EnhancedInstructionSet.AdvancedVectorExtensions512, () => res = true) + ); + + return res; + } + + public static bool IsConformanceMode(this IGenerationContext context) + { + return Options.GetObject(context.Configuration) == + Options.Vc.Compiler.ConformanceMode.Enable; + } + + public static string GetPchAction(this IGenerationContext context) + { + var platformVcxproj = PlatformRegistry.Query(context.Configuration.Platform); + + if (!Options.HasOption(context.Configuration)) + { + return platformVcxproj.HasPrecomp(context) ? PchAction.Include : PchAction.None; + } + + var pchOption = Options.GetObject(context.Configuration); + switch (pchOption) + { + case Options.Vc.SourceFile.PrecompiledHeader.UsePrecompiledHeader: + return PchAction.Include; + case Options.Vc.SourceFile.PrecompiledHeader.CreatePrecompiledHeader: + return PchAction.Create; + default: + return PchAction.None; + } + } + + /// + /// Checks if one of the presents in without trying to get default values. + /// Comparing to IGenerationContext.SelectOption(), can check options of different types. + /// + private static bool CheckOptions(this Project.Configuration config, params object[] options) { var optionsType = typeof(Options); var getObjectArgsTypes = new Type[] { typeof(Project.Configuration) }; var configArg = new object[] { config }; - + var getObjectMethod = optionsType.GetMethod("GetObject", getObjectArgsTypes); var hasObjectMethod = optionsType.GetMethod("HasOption"); @@ -25,7 +244,7 @@ public static bool CheckOptions(this Project.Configuration config, params object var genericGetObj = getObjectMethod.MakeGenericMethod(option.GetType()); return genericGetObj.Invoke(null, configArg).Equals(option); } - + var genericGetFirstObj = getObjectMethod.MakeGenericMethod(options.First().GetType()); return genericGetFirstObj.Invoke(null, configArg).Equals(options.First()); } diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 018e32779..449214026 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -92,11 +92,9 @@ public void ReadConfiguration(Project.Configuration config) /// /// Returns OrderedDictionary for json serialization /// - /// public OrderedDictionary ToDictionary() { - var resDict = new OrderedDictionary(); - resDict.Add("SourcePath", SourcePath); + var resDict = new OrderedDictionary { { "SourcePath", SourcePath } }; if (!IgnoreDefaults || !SourceExtensions.All(new Project().SourceFilesExtensions.Contains)) { @@ -140,7 +138,7 @@ public OrderedDictionary ToDictionary() /// /// Maps projects information for later usage in "Modules" section. /// - private Dictionary _projectsInfo = new Dictionary(); + private readonly Dictionary _projectsInfo = new Dictionary(); /// /// Helper class for storing all the project-related information. @@ -276,11 +274,10 @@ private List GetFastBuildOptions() /// Generates "root.json" file for solution. /// Also gathers information about projects for later usage in "Modules" section. /// - public void Generate(Builder builder, Solution solution, List configurations, string solutionFile, List generatedFiles, - List skipFiles) + public void Generate(Builder builder, Solution solution, List configurations, string solutionFile, + List generatedFiles, List skipFiles) { - var info = new OrderedDictionary(); - info.Add("ProjectFolderPath", Path.Combine(solution.SharpmakeCsPath, RiderFolderPath, ".Rider")); + var info = new OrderedDictionary { { "ProjectFolderPath", Path.Combine(solution.SharpmakeCsPath, RiderFolderPath, ".Rider") } }; var projects = new OrderedDictionary(); foreach (var solutionConfig in configurations) @@ -351,10 +348,12 @@ public void Generate(Builder builder, Project project, List var modules = new OrderedDictionary(); var toolchain = new OrderedDictionary(); var buildInfo = new OrderedDictionary(); - - toolchain.Add("CppStandard", GetCppStandart(context.Configuration)); - toolchain.Add("bUseRTTI", IsRTTIEnabled(context.Configuration)); - toolchain.Add("bUseExceptions", IsExceptionEnabled(context.Configuration)); - toolchain.Add("bIsBuildingLibrary", context.Configuration.Output == Project.Configuration.OutputType.Dll - || context.Configuration.Output == Project.Configuration.OutputType.Lib); + + toolchain.Add("CppStandard", context.GetCppStandard()); + toolchain.Add("Architecture", context.GetArchitecture()); + toolchain.Add("bUseRTTI", context.IsRttiEnabled()); + toolchain.Add("bUseExceptions", context.IsExceptionEnabled()); + toolchain.Add("bIsBuildingLibrary", context.Configuration.Output == Project.Configuration.OutputType.Lib); toolchain.Add("bIsBuildingDll", context.Configuration.Output == Project.Configuration.OutputType.Dll); toolchain.Add("Configuration", context.Configuration.Name); - toolchain.Add("bOptimizeCode", IsOptimizationEnabled(context.Configuration)); - toolchain.Add("bUseInlining", IsInliningEnabled(context.Configuration)); - toolchain.Add("bUseUnity", IsBlob(context.Configuration)); - toolchain.Add("bCreateDebugInfo", IsDebugInfo(context.Configuration)); - toolchain.Add("bUseAVX", IsAvx(context.Configuration)); + toolchain.Add("bOptimizeCode", context.IsOptimizationEnabled()); + toolchain.Add("bUseInlining", context.IsInliningEnabled()); + toolchain.Add("bUseUnity", context.IsBlob()); + toolchain.Add("bCreateDebugInfo", context.IsDebugInfo()); + toolchain.Add("bUseAVX", context.IsAvx()); toolchain.Add("Compiler", context.Configuration.Compiler.ToString()); - toolchain.Add("bStrictConformanceMode", IsConformanceMode(context.Configuration)); - toolchain.Add("PrecompiledHeaderAction", GetPchAction(context)); + toolchain.Add("bStrictConformanceMode", context.IsConformanceMode()); + toolchain.Add("PrecompiledHeaderAction", context.GetPchAction()); var beforeBuildCommand = context.Configuration.FastBuildCustomActionsBeforeBuildCommand; if (beforeBuildCommand == FileGeneratorUtilities.RemoveLineTag) @@ -451,107 +450,6 @@ private void GenerateConfiguration(RiderGenerationContext context, List } } - private string GetCppStandart(Project.Configuration config) - { - string res = "Default"; - - var stdOptions = new List(); - stdOptions.AddRange(Options.GetObjects(config).Select(it => it as object)); - stdOptions.AddRange(Options.GetObjects(config).Select(it => it as object)); - stdOptions.AddRange(Options.GetObjects(config).Select(it => it as object)); - stdOptions.AddRange(Options.GetObjects(config).Select(it => it as object)); - stdOptions.AddRange(Options.GetObjects(config).Select(it => it as object)); - - if (stdOptions.Count > 0) - { - res = stdOptions.First().ToString(); - } - - return res; - } - - private bool IsRTTIEnabled(Project.Configuration config) - { - return !config.CheckOptions(Options.Vc.Compiler.RTTI.Disable, - Options.Makefile.Compiler.Rtti.Disable, - Options.XCode.Compiler.RTTI.Disable, - Options.Clang.Compiler.Rtti.Disable); - } - - private bool IsExceptionEnabled(Project.Configuration config) - { - return !config.CheckOptions(Options.Vc.Compiler.Exceptions.Disable, - Options.Makefile.Compiler.Exceptions.Disable, - Options.XCode.Compiler.Exceptions.Disable, - Options.Clang.Compiler.Exceptions.Disable, - Options.Android.Compiler.Exceptions.Disable); - } - - private bool IsOptimizationEnabled(Project.Configuration config) - { - return !config.CheckOptions(Options.Vc.Compiler.Optimization.Disable, - Options.Makefile.Compiler.OptimizationLevel.Disable, - Options.XCode.Compiler.OptimizationLevel.Disable, - Options.Clang.Compiler.OptimizationLevel.Disable); - } - - private bool IsInliningEnabled(Project.Configuration config) - { - return !config.CheckOptions(Options.Vc.Compiler.Inline.Disable); - } - - private bool IsBlob(Project.Configuration config) - { - return config.IsBlobbed || config.FastBuildBlobbed; - } - - private bool IsDebugInfo(Project.Configuration config) - { - return !config.CheckOptions(Options.Vc.General.DebugInformation.Disable, - Options.Makefile.Compiler.GenerateDebugInformation.Disable, - Options.XCode.Compiler.GenerateDebuggingSymbols.Disable, - Options.Clang.Compiler.GenerateDebugInformation.Disable, - Options.Android.Compiler.DebugInformationFormat.None); - } - - private bool IsAvx(Project.Configuration config) - { - return config.CheckOptions(Options.Vc.Compiler.EnhancedInstructionSet.AdvancedVectorExtensions, - Options.Vc.Compiler.EnhancedInstructionSet.AdvancedVectorExtensions2, - Options.Vc.Compiler.EnhancedInstructionSet.AdvancedVectorExtensions512); - } - - private bool IsConformanceMode(Project.Configuration config) - { - return config.CheckOptions(Options.Vc.Compiler.ConformanceMode.Enable); - } - - private string GetPchAction(RiderGenerationContext context) - { - var platformVcxproj = PlatformRegistry.Query(context.Configuration.Platform); - - if (!Options.HasOption(context.Configuration)) - { - if (platformVcxproj.HasPrecomp(context)) - { - return "Include"; - } - - return "None"; - } - - var pchOption = Options.GetObject(context.Configuration); - switch (pchOption) - { - case Options.Vc.SourceFile.PrecompiledHeader.UsePrecompiledHeader: - return "Include"; - case Options.Vc.SourceFile.PrecompiledHeader.CreatePrecompiledHeader: - return "Create"; - default: - return "None"; - } - } - private string GetBuildCommand(RiderGenerationContext context) { if (!context.Configuration.IsFastBuild) diff --git a/samples/RiderJson/RiderJson.sharpmake.cs b/samples/RiderJson/RiderJson.sharpmake.cs index 93f056c88..5cd00bac3 100644 --- a/samples/RiderJson/RiderJson.sharpmake.cs +++ b/samples/RiderJson/RiderJson.sharpmake.cs @@ -26,6 +26,7 @@ public virtual void ConfigureAll(Configuration conf, Target target) conf.IsBlobbed = target.Blob == Blob.Blob; conf.FastBuildBlobbed = target.Blob == Blob.FastBuildUnitys; conf.AdditionalCompilerOptions.Add("/FS"); + conf.Options.Add(Options.Vc.Compiler.CppLanguageStandard.CPP17); } } From 8fb09f6075c988429426351055ad4d8810ada79c Mon Sep 17 00:00:00 2001 From: SmelJey Date: Wed, 13 Oct 2021 20:02:04 +1000 Subject: [PATCH 16/37] [RiderJson] Make RiderJson generation accessible via command line argument, fix generation on multiple DevEnvs --- Sharpmake.Application/CommandLineArguments.cs | 7 ++ Sharpmake.Application/Program.cs | 6 ++ Sharpmake.Generators/Generic/RiderJson.cs | 72 +++++++++++-------- samples/RiderJson/RiderJson.sharpmake.cs | 13 ++-- 4 files changed, 58 insertions(+), 40 deletions(-) diff --git a/Sharpmake.Application/CommandLineArguments.cs b/Sharpmake.Application/CommandLineArguments.cs index aea1edb44..b627a2b55 100644 --- a/Sharpmake.Application/CommandLineArguments.cs +++ b/Sharpmake.Application/CommandLineArguments.cs @@ -62,6 +62,7 @@ public enum InputType public string DebugSolutionStartArguments = string.Empty; public string DebugSolutionPath = string.Empty; public DevEnv DebugSolutionDevEnv = DebugProjectGenerator.DefaultDevEnv; + public bool GenerateRdJson = false; [CommandLine.Option("sources", @"sharpmake sources files: ex: /sources( ""project1.sharpmake"", ""..\..\project2.sharpmake"" )")] public void SetSources(params string[] files) @@ -361,6 +362,12 @@ public void CommandLineForceCleanup(string autocleanupDb) Exit = true; } + [CommandLine.Option("rdjson", @"Generate Rider project files")] + public void CommandLineGenerateRdJson() + { + GenerateRdJson = true; + } + public void Validate() { if (Assemblies.Length == 0 && Sources.Length == 0) diff --git a/Sharpmake.Application/Program.cs b/Sharpmake.Application/Program.cs index 5222bde81..2ee170fd8 100644 --- a/Sharpmake.Application/Program.cs +++ b/Sharpmake.Application/Program.cs @@ -12,6 +12,7 @@ using System.Threading; using System.Threading.Tasks; using Sharpmake.Generators; +using Sharpmake.Generators.Generic; using Sharpmake.Generators.VisualStudio; namespace Sharpmake.Application @@ -657,6 +658,11 @@ public static Builder CreateBuilder(BuildContext.BaseBuildContext context, Argum + $" Make sure to have a static entry point method flagged with [{typeof(Main).FullName}] attribute, and add 'arguments.Generate<[your_class]>();' in it."); builder.Context.ConfigureOrder = builder.Arguments.ConfigureOrder; + if (parameters.GenerateRdJson) + { + builder.EventPostGeneration += RiderJson.PostGenerationCallback; + } + // Call all configuration's methods and resolve project/solution member's values using (Builder.Instance.CreateProfilingScope("Build")) builder.BuildProjectAndSolution(); diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 449214026..7a7d469a1 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -14,9 +14,6 @@ namespace Sharpmake.Generators.Generic /// public partial class RiderJson : IProjectGenerator, ISolutionGenerator { - public static string SolutionName = null; - public static string RiderFolderPath = ""; - public static string SolutionFilePath = ""; public static bool Minimize = false; public static bool IgnoreDefaults = false; @@ -26,21 +23,31 @@ public partial class RiderJson : IProjectGenerator, ISolutionGenerator public static void PostGenerationCallback(List projects, List solutions) { var builder = Builder.Instance; - var solution = solutions.FirstOrDefault(it => it.Name == SolutionName) ?? solutions.First(); - var riderFolder = Path.Combine(solution.SharpmakeCsPath, RiderFolderPath, ".Rider"); var generator = new RiderJson(); - var configs = solution.Configurations.ToList(); - - // Do not move. Acquires all the information about projects for later usage in "Modules" sections. - generator.Generate(builder, solution, configs, Path.Combine(solution.SharpmakeCsPath, SolutionFilePath, solution.Name + ".rdjson"), new List(), - new List()); + + var generatedFiles = new List(); + var skipFiles = new List(); - foreach (var project in projects) + foreach (var solution in solutions) { - generator.Generate(builder, project, project.Configurations.ToList(), Path.Combine(riderFolder, project.Name), - new List(), new List()); - } + foreach (var solutionFileEntry in solution.SolutionFilesMapping) + { + generator._projectsInfo.Clear(); + var solutionFolder = Path.GetDirectoryName(solutionFileEntry.Key); + generator.Generate(builder, solution, solutionFileEntry.Value, + Path.Combine(solutionFileEntry.Key + ".rdjson"), generatedFiles, skipFiles); + var solutionFileName = Path.GetFileName(solutionFileEntry.Key); + + foreach (var projectInfo in solutionFileEntry.Value.SelectMany(solutionConfig => + solutionConfig.IncludedProjectInfos)) + { + generator.Generate(builder, projectInfo.Project, + new List {projectInfo.Configuration}, + Path.Combine(solutionFolder, $".{solutionFileName}"), generatedFiles, skipFiles); + } + } + } } /// @@ -152,6 +159,8 @@ private class RiderGenerationContext : IGenerationContext public string ProjectFileName { get; } public string ProjectPath { get; } + public string SolutionName { get; } + public Resolver Resolver { get; } public DevEnv DevelopmentEnvironment { get; } @@ -165,7 +174,7 @@ private class RiderGenerationContext : IGenerationContext public string FastBuildArguments { get; } public RiderGenerationContext(Builder builder, Project project, Project.Configuration configuration, - string projectPath) + string projectPath, string solutionName) { Builder = builder; Resolver = new Resolver(); @@ -184,6 +193,8 @@ public RiderGenerationContext(Builder builder, Project project, Project.Configur ProjectSourceCapitalized = Util.GetCapitalizedPath(Project.SourceRootPath); DevelopmentEnvironment = configuration.Target.GetFragment(); + SolutionName = solutionName; + Options = new Options.ExplicitOptions(); CommandLineOptions = new ProjectOptionsGenerator.VcxprojCmdLineOptions(); @@ -269,17 +280,16 @@ private List GetFastBuildOptions() return fastBuildCommandLineOptions; } } - + /// - /// Generates "root.json" file for solution. + /// Generates ".rdjson" file for . /// Also gathers information about projects for later usage in "Modules" section. /// public void Generate(Builder builder, Solution solution, List configurations, string solutionFile, List generatedFiles, List skipFiles) { - var info = new OrderedDictionary { { "ProjectFolderPath", Path.Combine(solution.SharpmakeCsPath, RiderFolderPath, ".Rider") } }; var projects = new OrderedDictionary(); - + foreach (var solutionConfig in configurations) { foreach (var proj in solutionConfig.IncludedProjectInfos) @@ -312,8 +322,6 @@ public void Generate(Builder builder, Solution solution, List beforeBuildCommand = ""; } - using (context.Resolver.NewScopedParameter("SolutionDir", Path.Combine(context.Project.SharpmakeCsPath, SolutionFilePath))) + using (context.Resolver.NewScopedParameter("SolutionDir", context.ProjectDirectory)) using (context.Resolver.NewScopedParameter("ProjectDir", context.Configuration.ProjectPath)) using (context.Resolver.NewScopedParameter("BeforeBuildCommand", beforeBuildCommand)) { @@ -429,7 +439,7 @@ private void GenerateConfiguration(RiderGenerationContext context, List info.Add("EnvironmentDefinitions", platformVcxproj.GetImplicitlyDefinedSymbols(context)); info.Add("Modules", modules); - var file = new FileInfo($"{context.ProjectPath}_{context.Configuration.Platform}_{context.Configuration.Name}.json"); + var file = new FileInfo(Path.Combine(context.ProjectPath, $"{context.Project.Name}_{context.Configuration.Platform}_{context.Configuration.Name}.json")); using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream, new UTF8Encoding(false))) @@ -456,7 +466,7 @@ private string GetBuildCommand(RiderGenerationContext context) { return ""; } - + var unresolvedCommand = Template.FastBuildBuildCommand; using (context.Resolver.NewScopedParameter("BuildCommand", context.FastBuildMakeCommandGenerator.GetCommand( @@ -465,7 +475,7 @@ private string GetBuildCommand(RiderGenerationContext context) { return context.Resolver.Resolve(unresolvedCommand) .Replace("$(ProjectDir)", context.Configuration.ProjectPath + "\\") - .Replace("$(SolutionName)", SolutionName); + .Replace("$(SolutionName)", context.SolutionName); } } @@ -484,7 +494,7 @@ private string GetReBuildCommand(RiderGenerationContext context) { return context.Resolver.Resolve(unresolvedCommand) .Replace("$(ProjectDir)", context.Configuration.ProjectPath + "\\") - .Replace("$(SolutionName)", SolutionName); + .Replace("$(SolutionName)", context.SolutionName); } } diff --git a/samples/RiderJson/RiderJson.sharpmake.cs b/samples/RiderJson/RiderJson.sharpmake.cs index 5cd00bac3..f1b11bdd3 100644 --- a/samples/RiderJson/RiderJson.sharpmake.cs +++ b/samples/RiderJson/RiderJson.sharpmake.cs @@ -9,7 +9,7 @@ public BaseProject() { AddTargets(new Target( Platform.win64, - DevEnv.vs2019, + DevEnv.vs2017 | DevEnv.vs2019, Optimization.Debug | Optimization.Release, OutputType.Lib, Blob.FastBuildUnitys, @@ -19,7 +19,7 @@ public BaseProject() [Configure] public virtual void ConfigureAll(Configuration conf, Target target) { - conf.ProjectPath = @"[project.SharpmakeCsPath]\projects"; + conf.ProjectPath = @"[project.SharpmakeCsPath]\projects\[target.DevEnv]"; conf.Name = "[target.Optimization] [target.BuildSystem]"; conf.IntermediatePath = @"[conf.ProjectPath]\obj\[project.Name]\[target.Platform]_[target.Optimization]_[target.DevEnv]"; conf.IsFastBuild = target.BuildSystem == BuildSystem.FastBuild; @@ -110,7 +110,7 @@ public BaseSolution() { AddTargets(new Target( Platform.win64, - DevEnv.vs2019, + DevEnv.vs2019 | DevEnv.vs2017, Optimization.Debug | Optimization.Release, OutputType.Lib, Blob.FastBuildUnitys, @@ -121,7 +121,7 @@ public BaseSolution() public virtual void ConfigureAll(Configuration conf, Target target) { conf.Name = @"[solution.Name] [target.Optimization] [target.BuildSystem]"; - conf.SolutionPath = @"[solution.SharpmakeCsPath]\projects"; + conf.SolutionPath = @"[solution.SharpmakeCsPath]\projects\[target.DevEnv]"; } } @@ -178,11 +178,6 @@ public static void SharpmakeMain(Sharpmake.Arguments args) string sharpmakeFastBuildDir = Util.PathGetAbsolute(rootDir, @"..\..\..\tools\FastBuild"); FastBuildSettings.FastBuildMakeCommand = Path.Combine(sharpmakeFastBuildDir, "Windows-x64", "FBuild.exe"); - args.Builder.EventPostGeneration += Sharpmake.Generators.Generic.RiderJson.PostGenerationCallback; - Sharpmake.Generators.Generic.RiderJson.SolutionName = "Sol1"; - Sharpmake.Generators.Generic.RiderJson.RiderFolderPath = "projects"; - Sharpmake.Generators.Generic.RiderJson.SolutionFilePath = "projects"; - args.Generate(); args.Generate(); } From 9207f6215fa27e6b1cf7ec44b1b2bc3c8fe6b308 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Tue, 19 Oct 2021 22:13:21 +1000 Subject: [PATCH 17/37] [RiderJson] Add rdjson files to output log --- Sharpmake.Application/Program.cs | 2 +- Sharpmake.Generators/Generic/RiderJson.cs | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Sharpmake.Application/Program.cs b/Sharpmake.Application/Program.cs index 2ee170fd8..84508c7fc 100644 --- a/Sharpmake.Application/Program.cs +++ b/Sharpmake.Application/Program.cs @@ -660,7 +660,7 @@ public static Builder CreateBuilder(BuildContext.BaseBuildContext context, Argum if (parameters.GenerateRdJson) { - builder.EventPostGeneration += RiderJson.PostGenerationCallback; + builder.EventPostGenerationReport += RiderJson.PostGenerationCallback; } // Call all configuration's methods and resolve project/solution member's values diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 7a7d469a1..eb1da0e5b 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.Specialized; using System.IO; @@ -20,13 +21,12 @@ public partial class RiderJson : IProjectGenerator, ISolutionGenerator /// /// Callback which should be added to in order to generate Rider project model. /// - public static void PostGenerationCallback(List projects, List solutions) + public static void PostGenerationCallback(List projects, List solutions, ConcurrentDictionary generationReport) { var builder = Builder.Instance; var generator = new RiderJson(); - - var generatedFiles = new List(); - var skipFiles = new List(); + + builder.LogWriteLine(" RdJson files generated:"); foreach (var solution in solutions) { @@ -34,17 +34,24 @@ public static void PostGenerationCallback(List projects, List { generator._projectsInfo.Clear(); var solutionFolder = Path.GetDirectoryName(solutionFileEntry.Key); + + var generationOutput = generationReport[solution.GetType()]; + var fileWithExtension = Path.Combine(solutionFileEntry.Key + ".rdjson"); + generator.Generate(builder, solution, solutionFileEntry.Value, - Path.Combine(solutionFileEntry.Key + ".rdjson"), generatedFiles, skipFiles); + fileWithExtension, generationOutput.Generated, generationOutput.Skipped); + + builder.LogWriteLine(" {0,5}", fileWithExtension); var solutionFileName = Path.GetFileName(solutionFileEntry.Key); foreach (var projectInfo in solutionFileEntry.Value.SelectMany(solutionConfig => solutionConfig.IncludedProjectInfos)) { + var projectOutput = generationReport[projectInfo.Project.GetType()]; generator.Generate(builder, projectInfo.Project, new List {projectInfo.Configuration}, - Path.Combine(solutionFolder, $".{solutionFileName}"), generatedFiles, skipFiles); + Path.Combine(solutionFolder, $".{solutionFileName}"), projectOutput.Generated, projectOutput.Skipped); } } } From fdc62451f235bbf092ae633c619c8e6ffab6b173 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Fri, 22 Oct 2021 20:34:54 +1000 Subject: [PATCH 18/37] [RiderJson] Fix projects dependencies calculating (at the same way as it's working for vcxproj) --- Sharpmake.Generators/Generic/RiderJson.cs | 53 +++++++++++++++-------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index eb1da0e5b..dd4d9a17a 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -27,12 +27,30 @@ public static void PostGenerationCallback(List projects, List var generator = new RiderJson(); builder.LogWriteLine(" RdJson files generated:"); + + foreach (var project in projects) + { + foreach (var config in project.Configurations) + { + if (!generator._projectsInfo.ContainsKey(config.Target)) + { + generator._projectsInfo.Add(config.Target, new Dictionary()); + } + + if (!generator._projectsInfo[config.Target].ContainsKey(project.Name)) + { + generator._projectsInfo[config.Target].Add(project.Name, new RiderProjectInfo(project)); + } + + var riderProjInfo = generator._projectsInfo[config.Target][project.Name]; + riderProjInfo.ReadConfiguration(config); + } + } foreach (var solution in solutions) { foreach (var solutionFileEntry in solution.SolutionFilesMapping) { - generator._projectsInfo.Clear(); var solutionFolder = Path.GetDirectoryName(solutionFileEntry.Key); var generationOutput = generationReport[solution.GetType()]; @@ -152,7 +170,8 @@ public OrderedDictionary ToDictionary() /// /// Maps projects information for later usage in "Modules" section. /// - private readonly Dictionary _projectsInfo = new Dictionary(); + private readonly Dictionary> _projectsInfo + = new Dictionary>(); /// /// Helper class for storing all the project-related information. @@ -304,13 +323,9 @@ public void Generate(Builder builder, Solution solution, List>()); - _projectsInfo.Add(proj.Project.Name, new RiderProjectInfo(proj.Project)); } - - var riderProjInfo = _projectsInfo[proj.Project.Name]; - riderProjInfo.ReadConfiguration(proj.Configuration); - var projObject = projects[riderProjInfo.Name] as Dictionary>; + var projObject = projects[proj.Project.Name] as Dictionary>; var projConfig = new Dictionary(); projConfig.Add("ProjectConfig", proj.Configuration.Name); @@ -353,22 +368,16 @@ public void Generate(Builder builder, Solution solution, List /// Generates all -related configuration files. /// - public void Generate(Builder builder, Project project, List configurations, string projectFile, List generatedFiles, - List skipFiles) + public void Generate(Builder builder, Project project, List configurations, string projectFile, + List generatedFiles, List skipFiles) { foreach (var config in configurations) { - if (!_projectsInfo.ContainsKey(project.Name) || !_projectsInfo[project.Name].Configurations.Contains(config.Name)) - { - continue; - } - var solutionDir = Path.GetDirectoryName(projectFile); var context = new RiderGenerationContext(builder, project, config, projectFile, Path.GetFileName(projectFile).Substring(1)) { // Hack to generate correct OutputDirectory options. ProjectDirectory = solutionDir, - }; var projectOptionsGen = new ProjectOptionsGenerator(); @@ -423,12 +432,18 @@ private void GenerateConfiguration(RiderGenerationContext context, List var platformVcxproj = PlatformRegistry.Query(context.Configuration.Platform); includePaths.AddRange(platformVcxproj.GetPlatformIncludePaths(context)); - var curProjectInfo = _projectsInfo[context.Project.Name]; + var curProjectInfo = _projectsInfo[context.Configuration.Target][context.Project.Name]; modules.Add(curProjectInfo.Name, curProjectInfo.ToDictionary()); - - foreach (var dependency in context.Configuration.ResolvedDependencies.Select(it => it.ProjectName)) + + foreach (var dependency in context.Configuration.ResolvedDependencies) { - var dependencyInfo = _projectsInfo[dependency]; + // Dependencies can contain projects with the same names. They will share same project info. + if (modules.Contains(dependency.Project.Name)) + { + continue; + } + + var dependencyInfo = _projectsInfo[dependency.Target][dependency.Project.Name]; modules.Add(dependencyInfo.Name, dependencyInfo.ToDictionary()); } From bbb91c8c81bc1d154e395a77aa6cdec61d4fad20 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Mon, 25 Oct 2021 19:40:18 +1000 Subject: [PATCH 19/37] [RiderJson] Add msbuild commands to output json --- .../Generic/RiderJson.Template.cs | 8 +- Sharpmake.Generators/Generic/RiderJson.cs | 123 +++++++++++------- 2 files changed, 79 insertions(+), 52 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.Template.cs b/Sharpmake.Generators/Generic/RiderJson.Template.cs index b40e3b7ce..278cc171f 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Template.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Template.cs @@ -9,11 +9,7 @@ public static class Template public static string FastBuildBuildCommand = @"cd [SolutionDir] [BeforeBuildCommand] [BuildCommand]"; - - public static string FastBuildReBuildCommand = @"cd [SolutionDir] -[BeforeBuildCommand] -[RebuildCommand]"; - + public static string FastBuildCleanCommand = @"del ""[IntermediateDirectory]\*unity*.cpp"" >NUL 2>NUL del ""[IntermediateDirectory]\*.obj"" >NUL 2>NUL del ""[IntermediateDirectory]\*.a"" >NUL 2>NUL @@ -26,6 +22,8 @@ public static class Template del ""[OutputDirectory]\[TargetFileFullName].ilk"" >NUL 2>NUL del ""[OutputDirectory]\[TargetFileFullName].lib"" >NUL 2>NUL del ""[OutputDirectory]\[TargetFileFullName].pdb"" >NUL 2>NUL"; + + public static string MsBuildBuildCommand = @"$(MsBuildPath) [ProjectFile] -t:[Command] -p:Configuration=[ConfigurationName] -p:Platform=[PlatformName]"; } } } diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index dd4d9a17a..5b0c26131 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -412,21 +412,20 @@ private void GenerateConfiguration(RiderGenerationContext context, List toolchain.Add("bStrictConformanceMode", context.IsConformanceMode()); toolchain.Add("PrecompiledHeaderAction", context.GetPchAction()); - var beforeBuildCommand = context.Configuration.FastBuildCustomActionsBeforeBuildCommand; - if (beforeBuildCommand == FileGeneratorUtilities.RemoveLineTag) - { - beforeBuildCommand = ""; - } - using (context.Resolver.NewScopedParameter("SolutionDir", context.ProjectDirectory)) using (context.Resolver.NewScopedParameter("ProjectDir", context.Configuration.ProjectPath)) - using (context.Resolver.NewScopedParameter("BeforeBuildCommand", beforeBuildCommand)) { var targetPath = Path.Combine(context.Configuration.TargetPath, context.Configuration.TargetFileFullNameWithExtension); buildInfo.Add("TargetPath", targetPath); - buildInfo.Add("BuildCmd", GetBuildCommand(context)); - buildInfo.Add("ReBuildCmd", GetReBuildCommand(context)); - buildInfo.Add("CleanCmd", GetCleanCommand(context)); + + var commands = GetBuildCommands(context); + + if (commands.Build != "" || !IgnoreDefaults) + buildInfo.Add("BuildCmd", commands.Build); + if (commands.Rebuild != "" || !IgnoreDefaults) + buildInfo.Add("ReBuildCmd", commands.Rebuild); + if (commands.Clean != "" || !IgnoreDefaults) + buildInfo.Add("CleanCmd", commands.Clean); } var platformVcxproj = PlatformRegistry.Query(context.Configuration.Platform); @@ -451,12 +450,8 @@ private void GenerateConfiguration(RiderGenerationContext context, List info.Add("Configuration", context.Configuration.Name); info.Add("Platform", context.Configuration.Platform.ToString()); info.Add("ToolchainInfo", toolchain); - - if (context.Configuration.IsFastBuild || !IgnoreDefaults) - { - info.Add("BuildInfo", buildInfo); - } - + info.Add("BuildInfo", buildInfo); + info.Add("EnvironmentIncludePaths", includePaths); info.Add("EnvironmentDefinitions", platformVcxproj.GetImplicitlyDefinedSymbols(context)); info.Add("Modules", modules); @@ -482,53 +477,77 @@ private void GenerateConfiguration(RiderGenerationContext context, List } } - private string GetBuildCommand(RiderGenerationContext context) + private struct BuildCommands + { + public string Build; + public string Rebuild; + public string Clean; + } + + private BuildCommands GetBuildCommands(RiderGenerationContext context) { - if (!context.Configuration.IsFastBuild) + if (context.Configuration.IsFastBuild) { - return ""; + var beforeBuildCommand = context.Configuration.FastBuildCustomActionsBeforeBuildCommand; + if (beforeBuildCommand == FileGeneratorUtilities.RemoveLineTag) + { + beforeBuildCommand = ""; + } + + using (context.Resolver.NewScopedParameter("BeforeBuildCommand", beforeBuildCommand)) + { + return new BuildCommands + { + Build = GetFastBuildCommand(context, FastBuildMakeCommandGenerator.BuildType.Build), + Rebuild = GetFastBuildCommand(context, FastBuildMakeCommandGenerator.BuildType.Rebuild), + Clean = GetFastBuildClean(context) + }; + } } - - var unresolvedCommand = Template.FastBuildBuildCommand; - using (context.Resolver.NewScopedParameter("BuildCommand", - context.FastBuildMakeCommandGenerator.GetCommand( - FastBuildMakeCommandGenerator.BuildType.Build, - context.Configuration, context.FastBuildArguments))) + + if (context.Configuration.CustomBuildSettings != null) { - return context.Resolver.Resolve(unresolvedCommand) - .Replace("$(ProjectDir)", context.Configuration.ProjectPath + "\\") - .Replace("$(SolutionName)", context.SolutionName); + var buildSettings = context.Configuration.CustomBuildSettings; + return new BuildCommands + { + Build = buildSettings.BuildCommand, + Rebuild = buildSettings.RebuildCommand, + Clean = buildSettings.CleanCommand + }; + } + + using (context.Resolver.NewScopedParameter("ProjectFile", context.Configuration.ProjectFullFileNameWithExtension.Replace(" ", "%20"))) + using (context.Resolver.NewScopedParameter("ConfigurationName", context.Configuration.Name.Replace(" ", "%20"))) + using (context.Resolver.NewScopedParameter("PlatformName", + Util.GetPlatformString(context.Configuration.Platform, context.Project, context.Configuration.Target).Replace(" ", "%20"))) + { + return new BuildCommands + { + Build = GetMsBuildCommand(context, "Build"), + Rebuild = GetMsBuildCommand(context, "Rebuild"), + Clean = GetMsBuildCommand(context, "Clean") + }; } } - private string GetReBuildCommand(RiderGenerationContext context) + private string GetFastBuildCommand(RiderGenerationContext context, FastBuildMakeCommandGenerator.BuildType commandType) { - if (!context.Configuration.IsFastBuild) - { - return ""; - } - - var unresolvedCommand = Template.FastBuildReBuildCommand; - using (context.Resolver.NewScopedParameter("RebuildCommand", - context.FastBuildMakeCommandGenerator.GetCommand( - FastBuildMakeCommandGenerator.BuildType.Rebuild, - context.Configuration, context.FastBuildArguments))) + var unresolvedCommand = Template.FastBuildBuildCommand; + using (context.Resolver.NewScopedParameter("BuildCommand", + context.FastBuildMakeCommandGenerator.GetCommand( + commandType, + context.Configuration, context.FastBuildArguments))) { return context.Resolver.Resolve(unresolvedCommand) .Replace("$(ProjectDir)", context.Configuration.ProjectPath + "\\") .Replace("$(SolutionName)", context.SolutionName); } } - - private string GetCleanCommand(RiderGenerationContext context) + + private string GetFastBuildClean(RiderGenerationContext context) { - if (!context.Configuration.IsFastBuild) - { - return ""; - } - var unresolvedOutput = Template.FastBuildCleanCommand; - + using (context.Resolver.NewScopedParameter("IntermediateDirectory", context.Options["IntermediateDirectory"])) using (context.Resolver.NewScopedParameter("OutputDirectory", context.Options["OutputDirectory"])) using (context.Resolver.NewScopedParameter("TargetFileFullName", context.Configuration.TargetFileFullName)) @@ -536,5 +555,15 @@ private string GetCleanCommand(RiderGenerationContext context) return context.Resolver.Resolve(unresolvedOutput); } } + + private string GetMsBuildCommand(RiderGenerationContext context, string buildCommand) + { + var unresolvedCommand = Template.MsBuildBuildCommand; + + using (context.Resolver.NewScopedParameter("Command", buildCommand)) + { + return context.Resolver.Resolve(unresolvedCommand); + } + } } } From 26154442126179cfb32ea27ee22a6b4030938481 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Tue, 26 Oct 2021 19:44:41 +1000 Subject: [PATCH 20/37] [RiderJson] Fix invalid ProjectDirectory in RiderGenerationContext --- Sharpmake.Generators/Generic/RiderJson.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 5b0c26131..05f6c346b 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -207,9 +207,6 @@ public RiderGenerationContext(Builder builder, Project project, Project.Configur FileInfo fileInfo = new FileInfo(projectPath); ProjectPath = fileInfo.FullName; - ProjectDirectory = Path.GetDirectoryName(ProjectPath); - ProjectFileName = Path.GetFileName(ProjectPath); - ProjectDirectory = Path.GetDirectoryName(fileInfo.FullName); ProjectFileName = fileInfo.Name; Project = project; @@ -373,17 +370,11 @@ public void Generate(Builder builder, Project project, List Date: Tue, 26 Oct 2021 23:16:01 +1000 Subject: [PATCH 21/37] [RiderJson] Fix clean command for FastBuild --- Sharpmake.Generators/Generic/RiderJson.Template.cs | 2 +- Sharpmake.Generators/Generic/RiderJson.cs | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.Template.cs b/Sharpmake.Generators/Generic/RiderJson.Template.cs index 278cc171f..393e585e5 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Template.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Template.cs @@ -23,7 +23,7 @@ public static class Template del ""[OutputDirectory]\[TargetFileFullName].lib"" >NUL 2>NUL del ""[OutputDirectory]\[TargetFileFullName].pdb"" >NUL 2>NUL"; - public static string MsBuildBuildCommand = @"$(MsBuildPath) [ProjectFile] -t:[Command] -p:Configuration=[ConfigurationName] -p:Platform=[PlatformName]"; + public static string MsBuildBuildCommand = @"$(MsBuildPath) ""[ProjectFile]"" -t:[Command] -p:Configuration=""[ConfigurationName]"" -p:Platform=""[PlatformName]"""; } } } diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 05f6c346b..d951c6340 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -507,10 +507,10 @@ private BuildCommands GetBuildCommands(RiderGenerationContext context) }; } - using (context.Resolver.NewScopedParameter("ProjectFile", context.Configuration.ProjectFullFileNameWithExtension.Replace(" ", "%20"))) - using (context.Resolver.NewScopedParameter("ConfigurationName", context.Configuration.Name.Replace(" ", "%20"))) + using (context.Resolver.NewScopedParameter("ProjectFile", context.Configuration.ProjectFullFileNameWithExtension)) + using (context.Resolver.NewScopedParameter("ConfigurationName", context.Configuration.Name)) using (context.Resolver.NewScopedParameter("PlatformName", - Util.GetPlatformString(context.Configuration.Platform, context.Project, context.Configuration.Target).Replace(" ", "%20"))) + Util.GetPlatformString(context.Configuration.Platform, context.Project, context.Configuration.Target))) { return new BuildCommands { @@ -538,6 +538,11 @@ private string GetFastBuildCommand(RiderGenerationContext context, FastBuildMake private string GetFastBuildClean(RiderGenerationContext context) { var unresolvedOutput = Template.FastBuildCleanCommand; + if (context.Options["IntermediateDirectory"] == FileGeneratorUtilities.RemoveLineTag + || context.Options["OutputDirectory"] == FileGeneratorUtilities.RemoveLineTag) + { + return ""; + } using (context.Resolver.NewScopedParameter("IntermediateDirectory", context.Options["IntermediateDirectory"])) using (context.Resolver.NewScopedParameter("OutputDirectory", context.Options["OutputDirectory"])) From 6d26fb42ad6a96b0fcbe367c34ee874bc1993c3b Mon Sep 17 00:00:00 2001 From: SmelJey Date: Wed, 27 Oct 2021 11:33:32 +1000 Subject: [PATCH 22/37] [RiderJson] Add SolutionFolder to RdJson output --- Sharpmake.Generators/Generic/RiderJson.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index d951c6340..205feb802 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -317,12 +317,16 @@ public void Generate(Builder builder, Solution solution, List>()); + projects.Add(projectEntry, new Dictionary>()); } - var projObject = projects[proj.Project.Name] as Dictionary>; + var projObject = projects[projectEntry] as Dictionary>; var projConfig = new Dictionary(); projConfig.Add("ProjectConfig", proj.Configuration.Name); From 188eda47f6123a5c083d43356fb8cd78b7e07812 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Wed, 3 Nov 2021 23:38:57 +1000 Subject: [PATCH 23/37] [RiderJson] Fix rdjson generation for non-generate projects --- Sharpmake.Generators/Generic/RiderJson.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 205feb802..2273047ab 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -66,6 +66,11 @@ public static void PostGenerationCallback(List projects, List foreach (var projectInfo in solutionFileEntry.Value.SelectMany(solutionConfig => solutionConfig.IncludedProjectInfos)) { + if (projectInfo.Project.SharpmakeProjectType != Project.ProjectTypeAttribute.Generate) + { + continue; + } + var projectOutput = generationReport[projectInfo.Project.GetType()]; generator.Generate(builder, projectInfo.Project, new List {projectInfo.Configuration}, From 3d6cff3bd76659824e18f89ce98df5834a3c2417 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Wed, 10 Nov 2021 17:30:17 +1000 Subject: [PATCH 24/37] [RiderJson] Fix defines, change Compiler option --- .../Generic/RiderJson.Util.cs | 32 +++++++++++++++++++ Sharpmake.Generators/Generic/RiderJson.cs | 8 +++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.Util.cs b/Sharpmake.Generators/Generic/RiderJson.Util.cs index cff5d5fb6..f76a3fc09 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Util.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Util.cs @@ -21,6 +21,38 @@ private static class PchAction public const string Create = "Create"; } + private static class Compiler + { + public const string Unknown = "Unknown"; + public const string Clang = "Clang"; + public const string Vs15 = "VisualStudio2015"; + public const string Vs17 = "VisualStudio2017"; + public const string Vs19 = "VisualStudio2019"; + public const string Vs22 = "VisualStudio2022"; + } + + public static string GetCompiler(this IGenerationContext context) + { + if (context.Configuration.Platform.IsUsingClang()) + { + return Compiler.Clang; + } + + switch (context.Configuration.Compiler) + { + case DevEnv.vs2015: + return Compiler.Vs15; + case DevEnv.vs2017: + return Compiler.Vs17; + case DevEnv.vs2019: + return Compiler.Vs19; + case DevEnv.vs2022: + return Compiler.Vs22; + default: + return Compiler.Unknown; + } + } + public static string GetCppStandard(this IGenerationContext context) { var res = CppLanguageStandard.Default; diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 2273047ab..4ca0fc133 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -392,10 +392,12 @@ private void GenerateConfiguration(RiderGenerationContext context, List { var info = new OrderedDictionary(); var includePaths = new Strings(); + var defines = new Strings(); var modules = new OrderedDictionary(); var toolchain = new OrderedDictionary(); var buildInfo = new OrderedDictionary(); + toolchain.Add("Compiler", context.GetCompiler()); toolchain.Add("CppStandard", context.GetCppStandard()); toolchain.Add("Architecture", context.GetArchitecture()); toolchain.Add("bUseRTTI", context.IsRttiEnabled()); @@ -408,7 +410,6 @@ private void GenerateConfiguration(RiderGenerationContext context, List toolchain.Add("bUseUnity", context.IsBlob()); toolchain.Add("bCreateDebugInfo", context.IsDebugInfo()); toolchain.Add("bUseAVX", context.IsAvx()); - toolchain.Add("Compiler", context.Configuration.Compiler.ToString()); toolchain.Add("bStrictConformanceMode", context.IsConformanceMode()); toolchain.Add("PrecompiledHeaderAction", context.GetPchAction()); @@ -431,6 +432,9 @@ private void GenerateConfiguration(RiderGenerationContext context, List var platformVcxproj = PlatformRegistry.Query(context.Configuration.Platform); includePaths.AddRange(platformVcxproj.GetPlatformIncludePaths(context)); + defines.AddRange(platformVcxproj.GetImplicitlyDefinedSymbols(context)); + defines.AddRange(context.Options.ExplicitDefines); + var curProjectInfo = _projectsInfo[context.Configuration.Target][context.Project.Name]; modules.Add(curProjectInfo.Name, curProjectInfo.ToDictionary()); @@ -453,7 +457,7 @@ private void GenerateConfiguration(RiderGenerationContext context, List info.Add("BuildInfo", buildInfo); info.Add("EnvironmentIncludePaths", includePaths); - info.Add("EnvironmentDefinitions", platformVcxproj.GetImplicitlyDefinedSymbols(context)); + info.Add("EnvironmentDefinitions", defines); info.Add("Modules", modules); var file = new FileInfo(Path.Combine(context.ProjectPath, $"{context.Project.Name}_{context.Configuration.Platform}_{context.Configuration.Name}.json")); From e7d4954551da7b5d4002d8dea7d0a02f07f2f99c Mon Sep 17 00:00:00 2001 From: SmelJey Date: Wed, 10 Nov 2021 19:40:14 +1000 Subject: [PATCH 25/37] [RiderJson] Make distinguishable [Generate] and other projects. --- Sharpmake.Generators/Generic/RiderJson.Util.cs | 10 ++++++++++ Sharpmake.Generators/Generic/RiderJson.cs | 17 +++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.Util.cs b/Sharpmake.Generators/Generic/RiderJson.Util.cs index f76a3fc09..187f33160 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Util.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Util.cs @@ -31,6 +31,16 @@ private static class Compiler public const string Vs22 = "VisualStudio2022"; } + public static string GetQualifiedName(this Project project) + { + if (project.SharpmakeProjectType == Project.ProjectTypeAttribute.Generate) + { + return project.Name; + } + + return $"{project.FullClassName}@{project.Name}"; + } + public static string GetCompiler(this IGenerationContext context) { if (context.Configuration.Platform.IsUsingClang()) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 4ca0fc133..a1fd98c92 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -95,7 +95,7 @@ private class RiderProjectInfo public Strings PrivateIncludePaths { get; } public Strings PublicDefinitions { get; } public Strings PrivateDefinitions { get; } - public Strings Configurations { get; } + public RiderProjectInfo(Project project) { @@ -109,7 +109,6 @@ public RiderProjectInfo(Project project) PrivateIncludePaths = new Strings(); PublicDefinitions = new Strings(); PrivateDefinitions = new Strings(); - Configurations = new Strings(); } /// @@ -117,13 +116,12 @@ public RiderProjectInfo(Project project) /// public void ReadConfiguration(Project.Configuration config) { - PublicDependencyModules.AddRange(config.ResolvedPublicDependencies.Select(it => it.Project.Name)); - PrivateDependencyModules.AddRange(config.ResolvedPrivateDependencies.Select(it => it.Project.Name)); + PublicDependencyModules.AddRange(config.ResolvedPublicDependencies.Select(it => it.Project.GetQualifiedName())); + PrivateDependencyModules.AddRange(config.ResolvedPrivateDependencies.Select(it => it.Project.GetQualifiedName())); PublicIncludePaths.AddRange(config.IncludePaths); PrivateIncludePaths.AddRange(config.IncludePrivatePaths); PublicDefinitions.AddRange(config.ExportDefines); PrivateDefinitions.AddRange(config.Defines); - Configurations.Add(config.Name); } /// @@ -440,14 +438,9 @@ private void GenerateConfiguration(RiderGenerationContext context, List foreach (var dependency in context.Configuration.ResolvedDependencies) { - // Dependencies can contain projects with the same names. They will share same project info. - if (modules.Contains(dependency.Project.Name)) - { - continue; - } - + var projectName = dependency.Project.GetQualifiedName(); var dependencyInfo = _projectsInfo[dependency.Target][dependency.Project.Name]; - modules.Add(dependencyInfo.Name, dependencyInfo.ToDictionary()); + modules.Add(projectName, dependencyInfo.ToDictionary()); } info.Add("Name", context.Configuration.ProjectName); From 20d92c386c747ba01ee3564823641ca58d1f220f Mon Sep 17 00:00:00 2001 From: SmelJey Date: Thu, 11 Nov 2021 01:21:37 +1000 Subject: [PATCH 26/37] [RiderJson] Update RdJson format (source files and output type) --- .../Generic/RiderJson.Util.cs | 22 +++++++++++++++++++ Sharpmake.Generators/Generic/RiderJson.cs | 18 +++++---------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.Util.cs b/Sharpmake.Generators/Generic/RiderJson.Util.cs index 187f33160..af0f101d6 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Util.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Util.cs @@ -31,6 +31,13 @@ private static class Compiler public const string Vs22 = "VisualStudio2022"; } + private static class OutputType + { + public const string Exe = "Exe"; + public const string Lib = "Lib"; + public const string Utility = "Utility"; + } + public static string GetQualifiedName(this Project project) { if (project.SharpmakeProjectType == Project.ProjectTypeAttribute.Generate) @@ -148,6 +155,21 @@ public static string GetArchitecture(this IGenerationContext context) return architecture.ToLower(); } + + public static string GetOutputType(this IGenerationContext context) + { + if (context.Project is FastBuildAllProject || context.Project.SharpmakeProjectType == Project.ProjectTypeAttribute.Export) + { + return OutputType.Utility; + } + + if (context.Configuration.Output == Project.Configuration.OutputType.Lib) + { + return OutputType.Lib; + } + + return OutputType.Exe; + } public static bool IsRttiEnabled(this IGenerationContext context) { diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index a1fd98c92..5b0f3ef63 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -86,8 +86,6 @@ public static void PostGenerationCallback(List projects, List private class RiderProjectInfo { public string Name { get; } - public string SourcePath { get; } - public Strings SourceExtensions { get; } public Strings PublicDependencyModules { get; } public Strings PrivateDependencyModules { get; } @@ -100,9 +98,7 @@ private class RiderProjectInfo public RiderProjectInfo(Project project) { Name = project.Name; - SourceExtensions = project.SourceFilesExtensions; - SourcePath = project.SourceRootPath; - + PublicDependencyModules = new Strings(); PrivateDependencyModules = new Strings(); PublicIncludePaths = new Strings(); @@ -129,12 +125,7 @@ public void ReadConfiguration(Project.Configuration config) /// public OrderedDictionary ToDictionary() { - var resDict = new OrderedDictionary { { "SourcePath", SourcePath } }; - - if (!IgnoreDefaults || !SourceExtensions.All(new Project().SourceFilesExtensions.Contains)) - { - resDict.Add("SourceExtensions", SourceExtensions); - } + var resDict = new OrderedDictionary(); if (!IgnoreDefaults || PublicDependencyModules.Count != 0) { @@ -398,9 +389,9 @@ private void GenerateConfiguration(RiderGenerationContext context, List toolchain.Add("Compiler", context.GetCompiler()); toolchain.Add("CppStandard", context.GetCppStandard()); toolchain.Add("Architecture", context.GetArchitecture()); + toolchain.Add("OutputType", context.GetOutputType()); toolchain.Add("bUseRTTI", context.IsRttiEnabled()); toolchain.Add("bUseExceptions", context.IsExceptionEnabled()); - toolchain.Add("bIsBuildingLibrary", context.Configuration.Output == Project.Configuration.OutputType.Lib); toolchain.Add("bIsBuildingDll", context.Configuration.Output == Project.Configuration.OutputType.Dll); toolchain.Add("Configuration", context.Configuration.Name); toolchain.Add("bOptimizeCode", context.IsOptimizationEnabled()); @@ -453,6 +444,9 @@ private void GenerateConfiguration(RiderGenerationContext context, List info.Add("EnvironmentDefinitions", defines); info.Add("Modules", modules); + info.Add("RootPath", context.Project.SourceRootPath); + info.Add("SourceFiles", context.Project.ResolvedSourceFiles); + var file = new FileInfo(Path.Combine(context.ProjectPath, $"{context.Project.Name}_{context.Configuration.Platform}_{context.Configuration.Name}.json")); using (var stream = new MemoryStream()) From 97f13c80e77b2cc9589035ce91c25611cf9b9359 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Thu, 11 Nov 2021 19:20:57 +1000 Subject: [PATCH 27/37] [RiderJson] Fix clang compiler detection --- Sharpmake.Generators/Generic/RiderJson.Util.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.Util.cs b/Sharpmake.Generators/Generic/RiderJson.Util.cs index af0f101d6..21ebadd40 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Util.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Util.cs @@ -50,7 +50,10 @@ public static string GetQualifiedName(this Project project) public static string GetCompiler(this IGenerationContext context) { - if (context.Configuration.Platform.IsUsingClang()) + var toolset = Options.GetObject(context.Configuration); + if (toolset == Options.Vc.General.PlatformToolset.ClangCL + || toolset == Options.Vc.General.PlatformToolset.LLVM + || context.Configuration.Platform.IsUsingClang()) { return Compiler.Clang; } From 570a552709f2370087a073f48267c3187928fe54 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Mon, 15 Nov 2021 19:35:12 +1000 Subject: [PATCH 28/37] [RiderJson] Add RiderJson generation params as command line args --- Sharpmake.Application/CommandLineArguments.cs | 5 +- .../Generic/RiderJson.Util.cs | 30 ++++++-- Sharpmake.Generators/Generic/RiderJson.cs | 77 ++++++------------- samples/RiderJson/RiderJson.sharpmake.cs | 3 +- .../codebase/executable2/private/main.cpp | 3 +- 5 files changed, 56 insertions(+), 62 deletions(-) diff --git a/Sharpmake.Application/CommandLineArguments.cs b/Sharpmake.Application/CommandLineArguments.cs index b627a2b55..1e3a1141b 100644 --- a/Sharpmake.Application/CommandLineArguments.cs +++ b/Sharpmake.Application/CommandLineArguments.cs @@ -6,6 +6,7 @@ using System.IO; using System.Runtime.Serialization; using System.Text.RegularExpressions; +using Sharpmake.Generators.Generic; namespace Sharpmake.Application { @@ -363,9 +364,11 @@ public void CommandLineForceCleanup(string autocleanupDb) } [CommandLine.Option("rdjson", @"Generate Rider project files")] - public void CommandLineGenerateRdJson() + public void CommandLineGenerateRdJson(bool minimize = false, bool ignoreDefaults = false) { GenerateRdJson = true; + RiderJson.Minimize = minimize; + RiderJson.IgnoreDefaults = ignoreDefaults; } public void Validate() diff --git a/Sharpmake.Generators/Generic/RiderJson.Util.cs b/Sharpmake.Generators/Generic/RiderJson.Util.cs index 21ebadd40..395784491 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Util.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Util.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Linq; using Sharpmake.Generators.VisualStudio; @@ -6,22 +7,25 @@ namespace Sharpmake.Generators.Generic { public static class RiderJsonUtil { - private static class CppLanguageStandard + public static class CppLanguageStandard { public const string Cpp14 = "Cpp14"; public const string Cpp17 = "Cpp17"; public const string Latest = "Latest"; - public const string Default = "Default"; + + public const string Default = Cpp14; } - private static class PchAction + public static class PchAction { public const string None = "None"; public const string Include = "Include"; public const string Create = "Create"; + + public const string Default = None; } - private static class Compiler + public static class Compiler { public const string Unknown = "Unknown"; public const string Clang = "Clang"; @@ -29,13 +33,17 @@ private static class Compiler public const string Vs17 = "VisualStudio2017"; public const string Vs19 = "VisualStudio2019"; public const string Vs22 = "VisualStudio2022"; + + public const string Default = Unknown; } - private static class OutputType + public static class OutputType { public const string Exe = "Exe"; public const string Lib = "Lib"; public const string Utility = "Utility"; + + public const string Default = Exe; } public static string GetQualifiedName(this Project project) @@ -47,6 +55,18 @@ public static string GetQualifiedName(this Project project) return $"{project.FullClassName}@{project.Name}"; } + + public static void AddIfCondition(this IDictionary dict, string key, object value, bool condition) + { + if (!RiderJson.IgnoreDefaults || condition) + { + dict.Add(key, value); + } + } + public static void AddIfNotDefault(this IDictionary dict, string key, object value, object defaultValue) + { + dict.AddIfCondition(key, value, !defaultValue.Equals(value)); + } public static string GetCompiler(this IGenerationContext context) { diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 5b0f3ef63..c73c94942 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -127,36 +127,13 @@ public OrderedDictionary ToDictionary() { var resDict = new OrderedDictionary(); - if (!IgnoreDefaults || PublicDependencyModules.Count != 0) - { - resDict.Add("PublicDependencyModules", PublicDependencyModules); - } - - if (!IgnoreDefaults || PrivateDependencyModules.Count != 0) - { - resDict.Add("PrivateDependencyModules", PrivateDependencyModules); - } + resDict.AddIfCondition("PublicDependencyModules", PublicDependencyModules, PublicDependencyModules.Count != 0); + resDict.AddIfCondition("PrivateDependencyModules", PrivateDependencyModules, PrivateDependencyModules.Count != 0); + resDict.AddIfCondition("PublicIncludePaths", PublicIncludePaths, PublicIncludePaths.Count != 0); + resDict.AddIfCondition("PrivateIncludePaths", PrivateIncludePaths, PrivateIncludePaths.Count != 0); + resDict.AddIfCondition("PublicDefinitions", PublicDefinitions, PublicDefinitions.Count != 0); + resDict.AddIfCondition("PrivateDefinitions", PrivateDefinitions, PrivateDefinitions.Count != 0); - if (!IgnoreDefaults || PublicIncludePaths.Count != 0) - { - resDict.Add("PublicIncludePaths", PublicIncludePaths); - } - - if (!IgnoreDefaults || PrivateIncludePaths.Count != 0) - { - resDict.Add("PrivateIncludePaths", PrivateIncludePaths); - } - - if (!IgnoreDefaults || PublicDefinitions.Count != 0) - { - resDict.Add("PublicDefinitions", PublicDefinitions); - } - - if (!IgnoreDefaults || PrivateDefinitions.Count != 0) - { - resDict.Add("PrivateDefinitions", PrivateDefinitions); - } - return resDict; } } @@ -325,10 +302,7 @@ public void Generate(Builder builder, Solution solution, List var toolchain = new OrderedDictionary(); var buildInfo = new OrderedDictionary(); - toolchain.Add("Compiler", context.GetCompiler()); - toolchain.Add("CppStandard", context.GetCppStandard()); - toolchain.Add("Architecture", context.GetArchitecture()); - toolchain.Add("OutputType", context.GetOutputType()); - toolchain.Add("bUseRTTI", context.IsRttiEnabled()); - toolchain.Add("bUseExceptions", context.IsExceptionEnabled()); - toolchain.Add("bIsBuildingDll", context.Configuration.Output == Project.Configuration.OutputType.Dll); + toolchain.AddIfNotDefault("Compiler", context.GetCompiler(), RiderJsonUtil.Compiler.Default); + toolchain.AddIfNotDefault("CppStandard", context.GetCppStandard(), RiderJsonUtil.CppLanguageStandard.Default); + toolchain.AddIfNotDefault("Architecture", context.GetArchitecture(), "x64"); + toolchain.AddIfNotDefault("OutputType", context.GetOutputType(), RiderJsonUtil.OutputType.Default); + toolchain.AddIfNotDefault("bUseRTTI", context.IsRttiEnabled(), false); + toolchain.AddIfNotDefault("bUseExceptions", context.IsExceptionEnabled(), true); + toolchain.AddIfNotDefault("bIsBuildingDll", context.Configuration.Output == Project.Configuration.OutputType.Dll, false); toolchain.Add("Configuration", context.Configuration.Name); - toolchain.Add("bOptimizeCode", context.IsOptimizationEnabled()); - toolchain.Add("bUseInlining", context.IsInliningEnabled()); - toolchain.Add("bUseUnity", context.IsBlob()); - toolchain.Add("bCreateDebugInfo", context.IsDebugInfo()); - toolchain.Add("bUseAVX", context.IsAvx()); - toolchain.Add("bStrictConformanceMode", context.IsConformanceMode()); - toolchain.Add("PrecompiledHeaderAction", context.GetPchAction()); + toolchain.AddIfNotDefault("bOptimizeCode", context.IsOptimizationEnabled(), false); + toolchain.AddIfNotDefault("bUseInlining", context.IsInliningEnabled(), false); + toolchain.AddIfNotDefault("bUseUnity", context.IsBlob(), false); + toolchain.AddIfNotDefault("bCreateDebugInfo", context.IsDebugInfo(), false); + toolchain.AddIfNotDefault("bUseAVX", context.IsAvx(), false); + toolchain.AddIfNotDefault("bStrictConformanceMode", context.IsConformanceMode(), false); + toolchain.AddIfNotDefault("PrecompiledHeaderAction", context.GetPchAction(), RiderJsonUtil.PchAction.Default); using (context.Resolver.NewScopedParameter("SolutionDir", context.ProjectDirectory)) using (context.Resolver.NewScopedParameter("ProjectDir", context.Configuration.ProjectPath)) @@ -410,12 +384,9 @@ private void GenerateConfiguration(RiderGenerationContext context, List var commands = GetBuildCommands(context); - if (commands.Build != "" || !IgnoreDefaults) - buildInfo.Add("BuildCmd", commands.Build); - if (commands.Rebuild != "" || !IgnoreDefaults) - buildInfo.Add("ReBuildCmd", commands.Rebuild); - if (commands.Clean != "" || !IgnoreDefaults) - buildInfo.Add("CleanCmd", commands.Clean); + buildInfo.AddIfNotDefault("BuildCmd", commands.Build, ""); + buildInfo.AddIfNotDefault("ReBuildCmd", commands.Rebuild, ""); + buildInfo.AddIfNotDefault("CleanCmd", commands.Clean, ""); } var platformVcxproj = PlatformRegistry.Query(context.Configuration.Platform); diff --git a/samples/RiderJson/RiderJson.sharpmake.cs b/samples/RiderJson/RiderJson.sharpmake.cs index f1b11bdd3..d24dafc25 100644 --- a/samples/RiderJson/RiderJson.sharpmake.cs +++ b/samples/RiderJson/RiderJson.sharpmake.cs @@ -41,6 +41,7 @@ public override void ConfigureAll(Configuration conf, Target target) conf.PrecompHeader = "precomp.hpp"; conf.PrecompSource = "precomp.cpp"; conf.Defines.Add("LIBRARY_COMPILE"); + conf.SolutionFolder = "Libs/"; conf.Output = Configuration.OutputType.Lib; } @@ -120,7 +121,7 @@ public BaseSolution() [Configure] public virtual void ConfigureAll(Configuration conf, Target target) { - conf.Name = @"[solution.Name] [target.Optimization] [target.BuildSystem]"; + conf.Name = @"[target.Optimization] [target.BuildSystem]"; conf.SolutionPath = @"[solution.SharpmakeCsPath]\projects\[target.DevEnv]"; } } diff --git a/samples/RiderJson/codebase/executable2/private/main.cpp b/samples/RiderJson/codebase/executable2/private/main.cpp index f5c174f14..0d977f29d 100644 --- a/samples/RiderJson/codebase/executable2/private/main.cpp +++ b/samples/RiderJson/codebase/executable2/private/main.cpp @@ -1,5 +1,4 @@ - -#include +#include #include From 5f0afbe294c190e4b100f4e3963cde1f35653180 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Mon, 29 Nov 2021 17:18:55 +1000 Subject: [PATCH 29/37] [RiderJson] Add source regexes and filters info to the output --- .../Generic/RiderJson.Util.cs | 1 + Sharpmake.Generators/Generic/RiderJson.cs | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.Util.cs b/Sharpmake.Generators/Generic/RiderJson.Util.cs index 395784491..2efe3f782 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Util.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Util.cs @@ -63,6 +63,7 @@ public static void AddIfCondition(this IDictionary dict, string key, object valu dict.Add(key, value); } } + public static void AddIfNotDefault(this IDictionary dict, string key, object value, object defaultValue) { dict.AddIfCondition(key, value, !defaultValue.Equals(value)); diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index c73c94942..d09578b3a 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -359,6 +359,7 @@ private void GenerateConfiguration(RiderGenerationContext context, List var modules = new OrderedDictionary(); var toolchain = new OrderedDictionary(); var buildInfo = new OrderedDictionary(); + var sourceFilesInfo = new OrderedDictionary(); toolchain.AddIfNotDefault("Compiler", context.GetCompiler(), RiderJsonUtil.Compiler.Default); toolchain.AddIfNotDefault("CppStandard", context.GetCppStandard(), RiderJsonUtil.CppLanguageStandard.Default); @@ -405,6 +406,20 @@ private void GenerateConfiguration(RiderGenerationContext context, List modules.Add(projectName, dependencyInfo.ToDictionary()); } + var sourceRoots = new Strings {context.Project.SourceRootPath}; + sourceRoots.AddRange(context.Project.AdditionalSourceRootPaths); + sourceFilesInfo.Add("SourceRoots", sourceRoots); + sourceFilesInfo.AddIfCondition("SourceFilesFilters", context.Project.SourceFilesFilters ?? new Strings(), + context.Project.SourceFilesFilters != null); + sourceFilesInfo.AddIfCondition("SourceFiltersRegex", + context.Project.SourceFilesIncludeRegex.Concat(context.Project.SourceFilesFiltersRegex), + context.Project.SourceFilesIncludeRegex.Count > 0 || context.Project.SourceFilesFiltersRegex.Count > 0); + sourceFilesInfo.AddIfCondition("ExcludeRegex", context.Project.SourceFilesExcludeRegex, + context.Project.SourceFilesExclude.Count > 0); + sourceFilesInfo.Add("SourceExtensions", context.Project.SourceFilesExtensions); + sourceFilesInfo.Add("SourceFiles", context.Project.ResolvedSourceFiles); + sourceFilesInfo.Add("ExcludedFiles", context.Project.SourceFilesExclude); + info.Add("Name", context.Configuration.ProjectName); info.Add("Configuration", context.Configuration.Name); info.Add("Platform", context.Configuration.Platform.ToString()); @@ -414,9 +429,7 @@ private void GenerateConfiguration(RiderGenerationContext context, List info.Add("EnvironmentIncludePaths", includePaths); info.Add("EnvironmentDefinitions", defines); info.Add("Modules", modules); - - info.Add("RootPath", context.Project.SourceRootPath); - info.Add("SourceFiles", context.Project.ResolvedSourceFiles); + info.Add("SourceInfo", sourceFilesInfo); var file = new FileInfo(Path.Combine(context.ProjectPath, $"{context.Project.Name}_{context.Configuration.Platform}_{context.Configuration.Name}.json")); From 4828c38f641e2d24a64ce51ae50157be8d62da16 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Sun, 17 Apr 2022 10:22:18 +1000 Subject: [PATCH 30/37] [RiderJson] Rename OutputType --- Sharpmake.Generators/Generic/RiderJson.Util.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.Util.cs b/Sharpmake.Generators/Generic/RiderJson.Util.cs index 2efe3f782..3887a38b8 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Util.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Util.cs @@ -39,11 +39,12 @@ public static class Compiler public static class OutputType { - public const string Exe = "Exe"; - public const string Lib = "Lib"; + public const string Executable = "Executable"; + public const string DynamicLibrary = "DynamicLinkLibrary"; + public const string StaticLibrary = "Lib"; public const string Utility = "Utility"; - public const string Default = Exe; + public const string Default = Executable; } public static string GetQualifiedName(this Project project) @@ -187,12 +188,15 @@ public static string GetOutputType(this IGenerationContext context) return OutputType.Utility; } - if (context.Configuration.Output == Project.Configuration.OutputType.Lib) + switch (context.Configuration.Output) { - return OutputType.Lib; + case Project.Configuration.OutputType.Lib: + return OutputType.StaticLibrary; + case Project.Configuration.OutputType.Dll: + return OutputType.DynamicLibrary; + default: + return OutputType.Executable; } - - return OutputType.Exe; } public static bool IsRttiEnabled(this IGenerationContext context) From dae577228f40970861a672db2653c8529423772a Mon Sep 17 00:00:00 2001 From: SmelJey Date: Sun, 17 Apr 2022 10:56:00 +1000 Subject: [PATCH 31/37] [RiderJson] Fix start arguments in RiderJsonProject --- Sharpmake.Generators/Generic/RiderJson.Util.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.Util.cs b/Sharpmake.Generators/Generic/RiderJson.Util.cs index 3887a38b8..a162713f2 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Util.cs +++ b/Sharpmake.Generators/Generic/RiderJson.Util.cs @@ -41,7 +41,7 @@ public static class OutputType { public const string Executable = "Executable"; public const string DynamicLibrary = "DynamicLinkLibrary"; - public const string StaticLibrary = "Lib"; + public const string StaticLibrary = "StaticLibrary"; public const string Utility = "Utility"; public const string Default = Executable; From d9154adeef09fb8bafa040bdcf6ab852d6481bec Mon Sep 17 00:00:00 2001 From: SmelJey Date: Mon, 27 Jun 2022 19:04:00 +1000 Subject: [PATCH 32/37] [RiderJson] Fix RiderJson generation when there are non-cpp projects --- Sharpmake.Generators/Generic/RiderJson.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index d09578b3a..084b37d2c 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -55,16 +55,18 @@ public static void PostGenerationCallback(List projects, List var generationOutput = generationReport[solution.GetType()]; var fileWithExtension = Path.Combine(solutionFileEntry.Key + ".rdjson"); + + var configurations = solutionFileEntry.Value + .Where(it => PlatformRegistry.Has(it.Platform)).ToList(); - generator.Generate(builder, solution, solutionFileEntry.Value, - fileWithExtension, generationOutput.Generated, generationOutput.Skipped); + generator.Generate(builder, solution, configurations, fileWithExtension, generationOutput.Generated, + generationOutput.Skipped); builder.LogWriteLine(" {0,5}", fileWithExtension); var solutionFileName = Path.GetFileName(solutionFileEntry.Key); - foreach (var projectInfo in solutionFileEntry.Value.SelectMany(solutionConfig => - solutionConfig.IncludedProjectInfos)) + foreach (var projectInfo in configurations.SelectMany(solutionConfig => solutionConfig.IncludedProjectInfos)) { if (projectInfo.Project.SharpmakeProjectType != Project.ProjectTypeAttribute.Generate) { From 1e19ea1f3fb281b9062a53754b8e1791c4bd786c Mon Sep 17 00:00:00 2001 From: SmelJey Date: Wed, 29 Jun 2022 21:47:27 +1000 Subject: [PATCH 33/37] Extract FastBuild build arguments to FastBuildMakeCommandGenerator --- Sharpmake.Generators/Generic/RiderJson.cs | 71 ++------------------ Sharpmake.Generators/VisualStudio/Vcxproj.cs | 58 +--------------- Sharpmake/FastBuildSettings.cs | 61 +++++++++++++++++ 3 files changed, 67 insertions(+), 123 deletions(-) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 084b37d2c..445a9b014 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -197,7 +197,11 @@ public RiderGenerationContext(Builder builder, Project project, Project.Configur if (configuration.IsFastBuild) { FastBuildMakeCommandGenerator = new Bff.FastBuildDefaultNMakeCommandGenerator(); - FastBuildArguments = string.Join(" ", GetFastBuildOptions()); + + var fastBuildCommandLineOptions = FastBuildMakeCommandGenerator.GetArguments(Configuration); + fastBuildCommandLineOptions.Add(" -config $(SolutionName)" + FastBuildSettings.FastBuildConfigFileExtension); + + FastBuildArguments = string.Join(" ", fastBuildCommandLineOptions); } } @@ -210,71 +214,6 @@ public void SelectOptionWithFallback(Action fallbackAction, params Options.Optio { Sharpmake.Options.SelectOptionWithFallback(Configuration, fallbackAction, options); } - - private List GetFastBuildOptions() - { - var fastBuildCommandLineOptions = new List(); - - if (FastBuildSettings.FastBuildUseIDE) - fastBuildCommandLineOptions.Add("-ide"); - - if (FastBuildSettings.FastBuildReport) - fastBuildCommandLineOptions.Add("-report"); - - if (FastBuildSettings.FastBuildNoSummaryOnError) - fastBuildCommandLineOptions.Add("-nosummaryonerror"); - - if (FastBuildSettings.FastBuildSummary) - fastBuildCommandLineOptions.Add("-summary"); - - if (FastBuildSettings.FastBuildVerbose) - fastBuildCommandLineOptions.Add("-verbose"); - - if (FastBuildSettings.FastBuildMonitor) - fastBuildCommandLineOptions.Add("-monitor"); - - // Configuring cache mode if that configuration is allowed to use caching - if (Configuration.FastBuildCacheAllowed) - { - // Setting the appropriate cache type commandline for that target. - switch (FastBuildSettings.CacheType) - { - case FastBuildSettings.CacheTypes.CacheRead: - fastBuildCommandLineOptions.Add("-cacheread"); - break; - case FastBuildSettings.CacheTypes.CacheWrite: - fastBuildCommandLineOptions.Add("-cachewrite"); - break; - case FastBuildSettings.CacheTypes.CacheReadWrite: - fastBuildCommandLineOptions.Add("-cache"); - break; - default: - break; - } - } - - if (FastBuildSettings.FastBuildDistribution && Configuration.FastBuildDistribution) - fastBuildCommandLineOptions.Add("-dist"); - - if (FastBuildSettings.FastBuildWait) - fastBuildCommandLineOptions.Add("-wait"); - - if (FastBuildSettings.FastBuildNoStopOnError) - fastBuildCommandLineOptions.Add("-nostoponerror"); - - if (FastBuildSettings.FastBuildFastCancel) - fastBuildCommandLineOptions.Add("-fastcancel"); - - if (FastBuildSettings.FastBuildNoUnity) - fastBuildCommandLineOptions.Add("-nounity"); - - if (!string.IsNullOrEmpty(Configuration.FastBuildCustomArgs)) - fastBuildCommandLineOptions.Add(Configuration.FastBuildCustomArgs); - - fastBuildCommandLineOptions.Add(" -config $(SolutionName)" + FastBuildSettings.FastBuildConfigFileExtension); - - return fastBuildCommandLineOptions; - } } /// diff --git a/Sharpmake.Generators/VisualStudio/Vcxproj.cs b/Sharpmake.Generators/VisualStudio/Vcxproj.cs index a839f9f47..b9525d296 100644 --- a/Sharpmake.Generators/VisualStudio/Vcxproj.cs +++ b/Sharpmake.Generators/VisualStudio/Vcxproj.cs @@ -500,63 +500,7 @@ private void GenerateImpl(GenerationContext context, IList generatedFile if (conf.IsFastBuild) { - var fastBuildCommandLineOptions = new List(); - - if (FastBuildSettings.FastBuildUseIDE) - fastBuildCommandLineOptions.Add("-ide"); - - if (FastBuildSettings.FastBuildReport) - fastBuildCommandLineOptions.Add("-report"); - - if (FastBuildSettings.FastBuildNoSummaryOnError) - fastBuildCommandLineOptions.Add("-nosummaryonerror"); - - if (FastBuildSettings.FastBuildSummary) - fastBuildCommandLineOptions.Add("-summary"); - - if (FastBuildSettings.FastBuildVerbose) - fastBuildCommandLineOptions.Add("-verbose"); - - if (FastBuildSettings.FastBuildMonitor) - fastBuildCommandLineOptions.Add("-monitor"); - - // Configuring cache mode if that configuration is allowed to use caching - if (conf.FastBuildCacheAllowed) - { - // Setting the appropriate cache type commandline for that target. - switch (FastBuildSettings.CacheType) - { - case FastBuildSettings.CacheTypes.CacheRead: - fastBuildCommandLineOptions.Add("-cacheread"); - break; - case FastBuildSettings.CacheTypes.CacheWrite: - fastBuildCommandLineOptions.Add("-cachewrite"); - break; - case FastBuildSettings.CacheTypes.CacheReadWrite: - fastBuildCommandLineOptions.Add("-cache"); - break; - default: - break; - } - } - - if (FastBuildSettings.FastBuildDistribution && conf.FastBuildDistribution) - fastBuildCommandLineOptions.Add("-dist"); - - if (FastBuildSettings.FastBuildWait) - fastBuildCommandLineOptions.Add("-wait"); - - if (FastBuildSettings.FastBuildNoStopOnError) - fastBuildCommandLineOptions.Add("-nostoponerror"); - - if (FastBuildSettings.FastBuildFastCancel) - fastBuildCommandLineOptions.Add("-fastcancel"); - - if (FastBuildSettings.FastBuildNoUnity) - fastBuildCommandLineOptions.Add("-nounity"); - - if (!string.IsNullOrEmpty(conf.FastBuildCustomArgs)) - fastBuildCommandLineOptions.Add(conf.FastBuildCustomArgs); + var fastBuildCommandLineOptions = FastBuildMakeCommandGenerator.GetArguments(conf); if (!string.IsNullOrEmpty(FastBuildCustomArguments)) fastBuildCommandLineOptions.Add(FastBuildCustomArguments); diff --git a/Sharpmake/FastBuildSettings.cs b/Sharpmake/FastBuildSettings.cs index 06c98238e..2d909cdab 100644 --- a/Sharpmake/FastBuildSettings.cs +++ b/Sharpmake/FastBuildSettings.cs @@ -15,6 +15,67 @@ public enum BuildType }; public abstract string GetCommand(BuildType buildType, Sharpmake.Project.Configuration conf, string fastbuildArguments); + + public static List GetArguments(Sharpmake.Project.Configuration conf) + { + var arguments = new List(); + if (FastBuildSettings.FastBuildUseIDE) + arguments.Add("-ide"); + + if (FastBuildSettings.FastBuildReport) + arguments.Add("-report"); + + if (FastBuildSettings.FastBuildNoSummaryOnError) + arguments.Add("-nosummaryonerror"); + + if (FastBuildSettings.FastBuildSummary) + arguments.Add("-summary"); + + if (FastBuildSettings.FastBuildVerbose) + arguments.Add("-verbose"); + + if (FastBuildSettings.FastBuildMonitor) + arguments.Add("-monitor"); + + // Configuring cache mode if that configuration is allowed to use caching + if (conf.FastBuildCacheAllowed) + { + // Setting the appropriate cache type commandline for that target. + switch (FastBuildSettings.CacheType) + { + case FastBuildSettings.CacheTypes.CacheRead: + arguments.Add("-cacheread"); + break; + case FastBuildSettings.CacheTypes.CacheWrite: + arguments.Add("-cachewrite"); + break; + case FastBuildSettings.CacheTypes.CacheReadWrite: + arguments.Add("-cache"); + break; + default: + break; + } + } + + if (FastBuildSettings.FastBuildDistribution && conf.FastBuildDistribution) + arguments.Add("-dist"); + + if (FastBuildSettings.FastBuildWait) + arguments.Add("-wait"); + + if (FastBuildSettings.FastBuildNoStopOnError) + arguments.Add("-nostoponerror"); + + if (FastBuildSettings.FastBuildFastCancel) + arguments.Add("-fastcancel"); + + if (FastBuildSettings.FastBuildNoUnity) + arguments.Add("-nounity"); + + if (!string.IsNullOrEmpty(conf.FastBuildCustomArgs)) + arguments.Add(conf.FastBuildCustomArgs); + return arguments; + } } From 1e7d1490e51a07a10b30d5d031bd68a3e0bb72e3 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Fri, 16 Sep 2022 17:13:03 +0200 Subject: [PATCH 34/37] [RiderJson] Fix system include paths for win32 --- Sharpmake.Generators/Generic/RiderJson.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Generic/RiderJson.cs index 445a9b014..ccefcb2ca 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Generic/RiderJson.cs @@ -332,6 +332,12 @@ private void GenerateConfiguration(RiderGenerationContext context, List } var platformVcxproj = PlatformRegistry.Query(context.Configuration.Platform); + if (context.DevelopmentEnvironment.IsVisualStudio()) + { + var winIncludePath = context.DevelopmentEnvironment.GetWindowsIncludePath(); + includePaths.AddRange(winIncludePath.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); + } + includePaths.AddRange(platformVcxproj.GetPlatformIncludePaths(context)); defines.AddRange(platformVcxproj.GetImplicitlyDefinedSymbols(context)); From 62991c02becc2f83fd72b5e0aefa4f9008fb313f Mon Sep 17 00:00:00 2001 From: SmelJey Date: Thu, 26 Jan 2023 13:59:41 +0100 Subject: [PATCH 35/37] [RiderJson] Move RiderJson classes to separate folder --- Sharpmake.Application/CommandLineArguments.cs | 2 +- Sharpmake.Application/Program.cs | 2 +- Sharpmake.Generators/{Generic => Rider}/RiderJson.Template.cs | 2 +- Sharpmake.Generators/{Generic => Rider}/RiderJson.Util.cs | 2 +- Sharpmake.Generators/{Generic => Rider}/RiderJson.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename Sharpmake.Generators/{Generic => Rider}/RiderJson.Template.cs (96%) rename Sharpmake.Generators/{Generic => Rider}/RiderJson.Util.cs (99%) rename Sharpmake.Generators/{Generic => Rider}/RiderJson.cs (99%) diff --git a/Sharpmake.Application/CommandLineArguments.cs b/Sharpmake.Application/CommandLineArguments.cs index 1e3a1141b..7d29d42d6 100644 --- a/Sharpmake.Application/CommandLineArguments.cs +++ b/Sharpmake.Application/CommandLineArguments.cs @@ -6,7 +6,7 @@ using System.IO; using System.Runtime.Serialization; using System.Text.RegularExpressions; -using Sharpmake.Generators.Generic; +using Sharpmake.Generators.Rider; namespace Sharpmake.Application { diff --git a/Sharpmake.Application/Program.cs b/Sharpmake.Application/Program.cs index 84508c7fc..6f2ac81c1 100644 --- a/Sharpmake.Application/Program.cs +++ b/Sharpmake.Application/Program.cs @@ -12,7 +12,7 @@ using System.Threading; using System.Threading.Tasks; using Sharpmake.Generators; -using Sharpmake.Generators.Generic; +using Sharpmake.Generators.Rider; using Sharpmake.Generators.VisualStudio; namespace Sharpmake.Application diff --git a/Sharpmake.Generators/Generic/RiderJson.Template.cs b/Sharpmake.Generators/Rider/RiderJson.Template.cs similarity index 96% rename from Sharpmake.Generators/Generic/RiderJson.Template.cs rename to Sharpmake.Generators/Rider/RiderJson.Template.cs index 393e585e5..1a6839883 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Template.cs +++ b/Sharpmake.Generators/Rider/RiderJson.Template.cs @@ -1,4 +1,4 @@ -namespace Sharpmake.Generators.Generic +namespace Sharpmake.Generators.Rider { public partial class RiderJson { diff --git a/Sharpmake.Generators/Generic/RiderJson.Util.cs b/Sharpmake.Generators/Rider/RiderJson.Util.cs similarity index 99% rename from Sharpmake.Generators/Generic/RiderJson.Util.cs rename to Sharpmake.Generators/Rider/RiderJson.Util.cs index a162713f2..a57faf60e 100644 --- a/Sharpmake.Generators/Generic/RiderJson.Util.cs +++ b/Sharpmake.Generators/Rider/RiderJson.Util.cs @@ -3,7 +3,7 @@ using System.Linq; using Sharpmake.Generators.VisualStudio; -namespace Sharpmake.Generators.Generic +namespace Sharpmake.Generators.Rider { public static class RiderJsonUtil { diff --git a/Sharpmake.Generators/Generic/RiderJson.cs b/Sharpmake.Generators/Rider/RiderJson.cs similarity index 99% rename from Sharpmake.Generators/Generic/RiderJson.cs rename to Sharpmake.Generators/Rider/RiderJson.cs index ccefcb2ca..63e68efc1 100644 --- a/Sharpmake.Generators/Generic/RiderJson.cs +++ b/Sharpmake.Generators/Rider/RiderJson.cs @@ -8,7 +8,7 @@ using Sharpmake.Generators.FastBuild; using Sharpmake.Generators.VisualStudio; -namespace Sharpmake.Generators.Generic +namespace Sharpmake.Generators.Rider { /// /// Generator for Rider project model json files. From 747f63e2903c452518390470e360d00708ebd47e Mon Sep 17 00:00:00 2001 From: Alexander Pirogov Date: Tue, 31 Jan 2023 18:01:20 +0200 Subject: [PATCH 36/37] Add C++20 flag --- Sharpmake.Generators/Rider/RiderJson.Util.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sharpmake.Generators/Rider/RiderJson.Util.cs b/Sharpmake.Generators/Rider/RiderJson.Util.cs index a57faf60e..553a63aa8 100644 --- a/Sharpmake.Generators/Rider/RiderJson.Util.cs +++ b/Sharpmake.Generators/Rider/RiderJson.Util.cs @@ -11,6 +11,7 @@ public static class CppLanguageStandard { public const string Cpp14 = "Cpp14"; public const string Cpp17 = "Cpp17"; + public const string Cpp20 = "Cpp20"; public const string Latest = "Latest"; public const string Default = Cpp14; @@ -107,6 +108,7 @@ public static string GetCppStandard(this IGenerationContext context) Options.Option(Options.Vc.Compiler.CppLanguageStandard.GNU14, () => res = CppLanguageStandard.Cpp14), Options.Option(Options.Vc.Compiler.CppLanguageStandard.CPP17, () => res = CppLanguageStandard.Cpp17), Options.Option(Options.Vc.Compiler.CppLanguageStandard.GNU17, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.Vc.Compiler.CppLanguageStandard.CPP20, () => res = CppLanguageStandard.Cpp20), Options.Option(Options.Vc.Compiler.CppLanguageStandard.Latest, () => res = CppLanguageStandard.Latest) ); return res; @@ -147,7 +149,9 @@ public static string GetCppStandard(this IGenerationContext context) Options.Option(Options.XCode.Compiler.CppLanguageStandard.CPP14, () => res = CppLanguageStandard.Cpp14), Options.Option(Options.XCode.Compiler.CppLanguageStandard.GNU14, () => res = CppLanguageStandard.Cpp14), Options.Option(Options.XCode.Compiler.CppLanguageStandard.CPP17, () => res = CppLanguageStandard.Cpp17), - Options.Option(Options.XCode.Compiler.CppLanguageStandard.GNU17, () => res = CppLanguageStandard.Cpp17) + Options.Option(Options.XCode.Compiler.CppLanguageStandard.GNU17, () => res = CppLanguageStandard.Cpp17), + Options.Option(Options.XCode.Compiler.CppLanguageStandard.CPP20, () => res = CppLanguageStandard.Cpp20), + Options.Option(Options.XCode.Compiler.CppLanguageStandard.GNU20, () => res = CppLanguageStandard.Cpp20) ); return res; } From ed90d61376ae461cebd4279118dbd635a1a68600 Mon Sep 17 00:00:00 2001 From: SmelJey Date: Thu, 9 Mar 2023 17:59:50 +0100 Subject: [PATCH 37/37] [RiderJson] Add DevEnv value for Rider and cleanup --- Sharpmake.Application/CommandLineArguments.cs | 9 - Sharpmake.Application/Program.cs | 5 - .../Properties/launchSettings.json | 5 + Sharpmake.Generators/GeneratorManager.cs | 20 ++ .../Rider/RiderJson.Template.cs | 5 +- Sharpmake.Generators/Rider/RiderJson.Util.cs | 7 +- Sharpmake.Generators/Rider/RiderJson.cs | 211 ++++++++---------- .../VisualStudio/ProjectOptionsGenerator.cs | 14 +- .../Windows/Win64Platform.cs | 42 ++-- Sharpmake/Options.Rider.cs | 33 +++ Sharpmake/Target.cs | 5 + Sharpmake/Util.cs | 7 +- samples/RiderJson/RiderJson.sharpmake.cs | 15 +- 13 files changed, 220 insertions(+), 158 deletions(-) create mode 100644 Sharpmake/Options.Rider.cs diff --git a/Sharpmake.Application/CommandLineArguments.cs b/Sharpmake.Application/CommandLineArguments.cs index 7d29d42d6..40b019f42 100644 --- a/Sharpmake.Application/CommandLineArguments.cs +++ b/Sharpmake.Application/CommandLineArguments.cs @@ -63,7 +63,6 @@ public enum InputType public string DebugSolutionStartArguments = string.Empty; public string DebugSolutionPath = string.Empty; public DevEnv DebugSolutionDevEnv = DebugProjectGenerator.DefaultDevEnv; - public bool GenerateRdJson = false; [CommandLine.Option("sources", @"sharpmake sources files: ex: /sources( ""project1.sharpmake"", ""..\..\project2.sharpmake"" )")] public void SetSources(params string[] files) @@ -363,14 +362,6 @@ public void CommandLineForceCleanup(string autocleanupDb) Exit = true; } - [CommandLine.Option("rdjson", @"Generate Rider project files")] - public void CommandLineGenerateRdJson(bool minimize = false, bool ignoreDefaults = false) - { - GenerateRdJson = true; - RiderJson.Minimize = minimize; - RiderJson.IgnoreDefaults = ignoreDefaults; - } - public void Validate() { if (Assemblies.Length == 0 && Sources.Length == 0) diff --git a/Sharpmake.Application/Program.cs b/Sharpmake.Application/Program.cs index 6f2ac81c1..61b73c9c9 100644 --- a/Sharpmake.Application/Program.cs +++ b/Sharpmake.Application/Program.cs @@ -658,11 +658,6 @@ public static Builder CreateBuilder(BuildContext.BaseBuildContext context, Argum + $" Make sure to have a static entry point method flagged with [{typeof(Main).FullName}] attribute, and add 'arguments.Generate<[your_class]>();' in it."); builder.Context.ConfigureOrder = builder.Arguments.ConfigureOrder; - if (parameters.GenerateRdJson) - { - builder.EventPostGenerationReport += RiderJson.PostGenerationCallback; - } - // Call all configuration's methods and resolve project/solution member's values using (Builder.Instance.CreateProfilingScope("Build")) builder.BuildProjectAndSolution(); diff --git a/Sharpmake.Application/Properties/launchSettings.json b/Sharpmake.Application/Properties/launchSettings.json index 463c0e209..06f06b2b9 100644 --- a/Sharpmake.Application/Properties/launchSettings.json +++ b/Sharpmake.Application/Properties/launchSettings.json @@ -116,6 +116,11 @@ "commandLineArgs": "/sources(@\u0027QTFileCustomBuild.sharpmake.cs\u0027)", "workingDirectory": "$(ProjectDir)\\..\\samples\\QTFileCustomBuild" }, + "Sample (RiderJson)": { + "commandName": "Project", + "commandLineArgs": "/sources(@\u0027RiderJson.sharpmake.cs\u0027)", + "workingDirectory": "$(ProjectDir)\\..\\samples\\RiderJson" + }, "Sample (SimpleExeLibDependency)": { "commandName": "Project", "commandLineArgs": "/sources(@\u0027SimpleExeLibDependency.sharpmake.cs\u0027)", diff --git a/Sharpmake.Generators/GeneratorManager.cs b/Sharpmake.Generators/GeneratorManager.cs index 9055263af..e68fde9b4 100644 --- a/Sharpmake.Generators/GeneratorManager.cs +++ b/Sharpmake.Generators/GeneratorManager.cs @@ -5,6 +5,7 @@ using Sharpmake.Generators.Apple; using Sharpmake.Generators.FastBuild; using Sharpmake.Generators.Generic; +using Sharpmake.Generators.Rider; using Sharpmake.Generators.VisualStudio; namespace Sharpmake.Generators @@ -25,6 +26,9 @@ public class GeneratorManager : IGeneratorManager private MakeApplication _makeApplicationGenerator = null; public MakeApplication MakeApplicationGenerator => _makeApplicationGenerator ?? (_makeApplicationGenerator = new MakeApplication()); + public RiderJson _riderJsonGenerator = null; + public RiderJson RiderJsonGenerator => _riderJsonGenerator ?? (_riderJsonGenerator = new RiderJson()); + // Project generators private CSproj _csprojGenerator = null; public CSproj CsprojGenerator => _csprojGenerator ?? (_csprojGenerator = new CSproj()); @@ -104,6 +108,11 @@ public void Generate(Builder builder, BffGenerator.Generate(builder, project, configurations, projectFile, generatedFiles, skipFiles); break; } + case DevEnv.rider: + { + BffGenerator.Generate(builder, project, configurations, projectFile, generatedFiles, skipFiles); + break; + } default: { throw new Error("Generate called with unknown DevEnv: " + devEnv); @@ -158,6 +167,17 @@ public void Generate(Builder builder, SlnGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); break; } + case DevEnv.rider: + { + if (UtilityMethods.HasFastBuildConfig(configurations)) + { + var masterBff = new MasterBff(); + masterBff.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); + } + + RiderJsonGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); + break; + } default: { throw new Error("Generate called with unknown DevEnv: " + devEnv); diff --git a/Sharpmake.Generators/Rider/RiderJson.Template.cs b/Sharpmake.Generators/Rider/RiderJson.Template.cs index 1a6839883..e07dc8d1e 100644 --- a/Sharpmake.Generators/Rider/RiderJson.Template.cs +++ b/Sharpmake.Generators/Rider/RiderJson.Template.cs @@ -1,4 +1,7 @@ -namespace Sharpmake.Generators.Rider +// Copyright (c) Ubisoft. All Rights Reserved. +// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information. + +namespace Sharpmake.Generators.Rider { public partial class RiderJson { diff --git a/Sharpmake.Generators/Rider/RiderJson.Util.cs b/Sharpmake.Generators/Rider/RiderJson.Util.cs index 553a63aa8..1987487e5 100644 --- a/Sharpmake.Generators/Rider/RiderJson.Util.cs +++ b/Sharpmake.Generators/Rider/RiderJson.Util.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Ubisoft. All Rights Reserved. +// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information. + +using System; using System.Collections; using System.Linq; using Sharpmake.Generators.VisualStudio; @@ -81,7 +84,7 @@ public static string GetCompiler(this IGenerationContext context) return Compiler.Clang; } - switch (context.Configuration.Compiler) + switch (toolset.GetDefaultDevEnvForToolset()) { case DevEnv.vs2015: return Compiler.Vs15; diff --git a/Sharpmake.Generators/Rider/RiderJson.cs b/Sharpmake.Generators/Rider/RiderJson.cs index 63e68efc1..7024f9582 100644 --- a/Sharpmake.Generators/Rider/RiderJson.cs +++ b/Sharpmake.Generators/Rider/RiderJson.cs @@ -1,5 +1,7 @@ -using System; -using System.Collections.Concurrent; +// Copyright (c) Ubisoft. All Rights Reserved. +// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information. + +using System; using System.Collections.Generic; using System.Collections.Specialized; using System.IO; @@ -13,74 +15,12 @@ namespace Sharpmake.Generators.Rider /// /// Generator for Rider project model json files. /// - public partial class RiderJson : IProjectGenerator, ISolutionGenerator + public partial class RiderJson : ISolutionGenerator { public static bool Minimize = false; public static bool IgnoreDefaults = false; - /// - /// Callback which should be added to in order to generate Rider project model. - /// - public static void PostGenerationCallback(List projects, List solutions, ConcurrentDictionary generationReport) - { - var builder = Builder.Instance; - var generator = new RiderJson(); - - builder.LogWriteLine(" RdJson files generated:"); - - foreach (var project in projects) - { - foreach (var config in project.Configurations) - { - if (!generator._projectsInfo.ContainsKey(config.Target)) - { - generator._projectsInfo.Add(config.Target, new Dictionary()); - } - - if (!generator._projectsInfo[config.Target].ContainsKey(project.Name)) - { - generator._projectsInfo[config.Target].Add(project.Name, new RiderProjectInfo(project)); - } - - var riderProjInfo = generator._projectsInfo[config.Target][project.Name]; - riderProjInfo.ReadConfiguration(config); - } - } - - foreach (var solution in solutions) - { - foreach (var solutionFileEntry in solution.SolutionFilesMapping) - { - var solutionFolder = Path.GetDirectoryName(solutionFileEntry.Key); - - var generationOutput = generationReport[solution.GetType()]; - var fileWithExtension = Path.Combine(solutionFileEntry.Key + ".rdjson"); - - var configurations = solutionFileEntry.Value - .Where(it => PlatformRegistry.Has(it.Platform)).ToList(); - - generator.Generate(builder, solution, configurations, fileWithExtension, generationOutput.Generated, - generationOutput.Skipped); - - builder.LogWriteLine(" {0,5}", fileWithExtension); - - var solutionFileName = Path.GetFileName(solutionFileEntry.Key); - - foreach (var projectInfo in configurations.SelectMany(solutionConfig => solutionConfig.IncludedProjectInfos)) - { - if (projectInfo.Project.SharpmakeProjectType != Project.ProjectTypeAttribute.Generate) - { - continue; - } - - var projectOutput = generationReport[projectInfo.Project.GetType()]; - generator.Generate(builder, projectInfo.Project, - new List {projectInfo.Configuration}, - Path.Combine(solutionFolder, $".{solutionFileName}"), projectOutput.Generated, projectOutput.Skipped); - } - } - } - } + private const string RiderJsonFileExtension = ".rdjson"; /// /// Helper class to keep all the project information for "Modules" section of json file. @@ -140,12 +80,6 @@ public OrderedDictionary ToDictionary() } } - /// - /// Maps projects information for later usage in "Modules" section. - /// - private readonly Dictionary> _projectsInfo - = new Dictionary>(); - /// /// Helper class for storing all the project-related information. /// @@ -171,7 +105,7 @@ private class RiderGenerationContext : IGenerationContext public FastBuildMakeCommandGenerator FastBuildMakeCommandGenerator { get; } public string FastBuildArguments { get; } - + public RiderGenerationContext(Builder builder, Project project, Project.Configuration configuration, string projectPath, string solutionName) { @@ -223,12 +157,25 @@ public void SelectOptionWithFallback(Action fallbackAction, params Options.Optio public void Generate(Builder builder, Solution solution, List configurations, string solutionFile, List generatedFiles, List skipFiles) { - var projects = new OrderedDictionary(); + var configurationMapping = new Dictionary>(); + var fileInfo = new FileInfo(solutionFile); + var solutionPath = fileInfo.Directory.FullName; + + var solutionFileName = fileInfo.Name; + var file = new FileInfo( + Util.GetCapitalizedPath(solutionPath + Path.DirectorySeparatorChar + solutionFileName + RiderJsonFileExtension)); + var projects = new OrderedDictionary(); + foreach (var solutionConfig in configurations) { foreach (var proj in solutionConfig.IncludedProjectInfos) { + if (proj.Project.SharpmakeProjectType != Project.ProjectTypeAttribute.Generate) + { + continue; + } + var solutionFolder = string.IsNullOrEmpty(proj.SolutionFolder) ? proj.Configuration.GetSolutionFolder(solution.Name) : proj.SolutionFolder; @@ -237,28 +184,25 @@ public void Generate(Builder builder, Solution solution, List>()); } - + var projObject = projects[projectEntry] as Dictionary>; var projConfig = new Dictionary(); + var projectConfigurations = configurationMapping.GetValueOrAdd(proj.Project, new List()); + projectConfigurations.Add(proj.Configuration); + projConfig.Add("ProjectConfig", proj.Configuration.Name); projConfig.Add("SolutionConfig", solutionConfig.Name); projConfig.Add("DoBuild", (proj.ToBuild != Solution.Configuration.IncludedProjectInfo.Build.No).ToString()); - if (!projObject.ContainsKey(proj.Configuration.Platform.ToString())) - { - projObject.Add(proj.Configuration.Platform.ToString(), new List()); - } - - projObject[proj.Configuration.Platform.ToString()].Add(projConfig); + var platformConfigurations = projObject.GetValueOrAdd(proj.Configuration.Platform.ToString(), new List()); + platformConfigurations.Add(projConfig); } } - - var file = new FileInfo(solutionFile); using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream, new UTF8Encoding(false))) - using (var serializer = new Util.JsonSerializer(writer) { IsOutputFormatted = true }) + using (var serializer = new Util.JsonSerializer(writer) {IsOutputFormatted = true}) { serializer.IsOutputFormatted = !Minimize; serializer.Serialize(projects); @@ -266,33 +210,42 @@ public void Generate(Builder builder, Solution solution, List(); + foreach (var projectInfo in configurations + .SelectMany(solutionConfig => solutionConfig.IncludedProjectInfos)) + { + if (projectInfo.Project.SharpmakeProjectType != Project.ProjectTypeAttribute.Generate) + { + continue; } + + GenerateConfiguration(builder, projectInfo.Project, projectInfos, projectInfo.Configuration, + Path.Combine(solutionPath, $".{solutionFileName}"), generatedFiles, skipFiles); } } - /// - /// Generates all -related configuration files. - /// - public void Generate(Builder builder, Project project, List configurations, string projectFile, + private static void GenerateConfiguration(Builder builder, Project project, Dictionary projectInfos, Project.Configuration configuration, string projectFile, List generatedFiles, List skipFiles) { - foreach (var config in configurations) - { - var context = new RiderGenerationContext(builder, project, config, projectFile, - Path.GetFileName(projectFile).Substring(1)); + var context = new RiderGenerationContext(builder, project, configuration, projectFile, + Path.GetFileName(projectFile).Substring(1)); - var projectOptionsGen = new ProjectOptionsGenerator(); - projectOptionsGen.GenerateOptions(context); - GenerateConfiguration(context, generatedFiles, skipFiles); - } + var projectOptionsGen = new ProjectOptionsGenerator(); + projectOptionsGen.GenerateOptions(context); + GenerateConfiguration(context, projectInfos, generatedFiles, skipFiles); } - private void GenerateConfiguration(RiderGenerationContext context, List generatedFiles, List skipFiles) + private static void GenerateConfiguration(RiderGenerationContext context, Dictionary projectInfos, List generatedFiles, List skipFiles) { var info = new OrderedDictionary(); var includePaths = new Strings(); @@ -337,20 +290,43 @@ private void GenerateConfiguration(RiderGenerationContext context, List var winIncludePath = context.DevelopmentEnvironment.GetWindowsIncludePath(); includePaths.AddRange(winIncludePath.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); } - - includePaths.AddRange(platformVcxproj.GetPlatformIncludePaths(context)); + var platformIncludes = platformVcxproj.GetPlatformIncludePaths(context); + var includesString = context.Options["IncludePath"]; + if (includesString != FileGeneratorUtilities.RemoveLineTag) + { + var includesEntries = includesString.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries); + includePaths.AddRange(includesEntries); + } + + includePaths.AddRange(platformIncludes); + defines.AddRange(platformVcxproj.GetImplicitlyDefinedSymbols(context)); defines.AddRange(context.Options.ExplicitDefines); - var curProjectInfo = _projectsInfo[context.Configuration.Target][context.Project.Name]; + RiderProjectInfo GetOrCreateProjectInfo(Project.Configuration configuration) + { + var projectName = configuration.Project.Name; + if (projectInfos.TryGetValue(projectName, out RiderProjectInfo projectInfo)) + { + return projectInfo; + } + + var newProjectInfo = new RiderProjectInfo(configuration.Project); + newProjectInfo.ReadConfiguration(configuration); + projectInfos.Add(projectName, newProjectInfo); + + return projectInfos[projectName]; + } + + var curProjectInfo = GetOrCreateProjectInfo(context.Configuration); modules.Add(curProjectInfo.Name, curProjectInfo.ToDictionary()); foreach (var dependency in context.Configuration.ResolvedDependencies) { - var projectName = dependency.Project.GetQualifiedName(); - var dependencyInfo = _projectsInfo[dependency.Target][dependency.Project.Name]; - modules.Add(projectName, dependencyInfo.ToDictionary()); + var dependencyInfo = GetOrCreateProjectInfo(dependency); + var dependencyName = dependency.Project.GetQualifiedName(); + modules.Add(dependencyName, dependencyInfo.ToDictionary()); } var sourceRoots = new Strings {context.Project.SourceRootPath}; @@ -406,7 +382,7 @@ private struct BuildCommands public string Clean; } - private BuildCommands GetBuildCommands(RiderGenerationContext context) + private static BuildCommands GetBuildCommands(RiderGenerationContext context) { if (context.Configuration.IsFastBuild) { @@ -438,10 +414,19 @@ private BuildCommands GetBuildCommands(RiderGenerationContext context) }; } - using (context.Resolver.NewScopedParameter("ProjectFile", context.Configuration.ProjectFullFileNameWithExtension)) - using (context.Resolver.NewScopedParameter("ConfigurationName", context.Configuration.Name)) - using (context.Resolver.NewScopedParameter("PlatformName", - Util.GetPlatformString(context.Configuration.Platform, context.Project, context.Configuration.Target))) + var msBuildProjectFile = Options.PathOption.Get(context.Configuration, fallback: null); + if (msBuildProjectFile == null) + { + throw new Error( + $"`Options.Rider.MsBuildOverrideProjectFile` should be overriden in \n {context.Configuration} in order to use MSBuild with Rider"); + } + + var msBuildConfiguration = Options.StringOption.Get(context.Configuration) ?? context.Configuration.Name; + var msBuildPlatform = Options.StringOption.Get(context.Configuration) ?? Util.GetPlatformString(context.Configuration.Platform, context.Project, context.Configuration.Target); + + using (context.Resolver.NewScopedParameter("ProjectFile", msBuildProjectFile)) + using (context.Resolver.NewScopedParameter("ConfigurationName", msBuildConfiguration)) + using (context.Resolver.NewScopedParameter("PlatformName", msBuildPlatform)) { return new BuildCommands { @@ -452,7 +437,7 @@ private BuildCommands GetBuildCommands(RiderGenerationContext context) } } - private string GetFastBuildCommand(RiderGenerationContext context, FastBuildMakeCommandGenerator.BuildType commandType) + private static string GetFastBuildCommand(RiderGenerationContext context, FastBuildMakeCommandGenerator.BuildType commandType) { var unresolvedCommand = Template.FastBuildBuildCommand; using (context.Resolver.NewScopedParameter("BuildCommand", @@ -466,7 +451,7 @@ private string GetFastBuildCommand(RiderGenerationContext context, FastBuildMake } } - private string GetFastBuildClean(RiderGenerationContext context) + private static string GetFastBuildClean(RiderGenerationContext context) { var unresolvedOutput = Template.FastBuildCleanCommand; if (context.Options["IntermediateDirectory"] == FileGeneratorUtilities.RemoveLineTag @@ -483,7 +468,7 @@ private string GetFastBuildClean(RiderGenerationContext context) } } - private string GetMsBuildCommand(RiderGenerationContext context, string buildCommand) + private static string GetMsBuildCommand(RiderGenerationContext context, string buildCommand) { var unresolvedCommand = Template.MsBuildBuildCommand; diff --git a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs index ded0604ba..1d14065a1 100644 --- a/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs +++ b/Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs @@ -1833,12 +1833,22 @@ private void GenerateLinkerOptions(IGenerationContext context, ProjectOptionsGen private void GenerateManifestToolOptions(IGenerationContext context, ProjectOptionsGenerationContext optionsContext) { + DevEnv compilerDevEnv = context.DevelopmentEnvironment; if (!context.DevelopmentEnvironment.IsVisualStudio()) // TODO: ideally this option generator should be split between VS / non-VS - return; + { + var platformToolset = Options.GetObject(context.Configuration); + var platformDevEnv = platformToolset.GetDefaultDevEnvForToolset(); + if (!platformDevEnv.HasValue) + { + return; + } + + compilerDevEnv = platformDevEnv.Value; + } Strings manifestInputs = new Strings(); - string vsManifestFilesPath = Util.SimplifyPath(Path.Combine(context.DevelopmentEnvironment.GetVisualStudioVCRootPath(), "Include", "Manifest")); + string vsManifestFilesPath = Util.SimplifyPath(Path.Combine(compilerDevEnv.GetVisualStudioVCRootPath(), "Include", "Manifest")); //EnableDpiAwareness context.SelectOption diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs index c72f49d90..9bd3a528f 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Windows/Win64Platform.cs @@ -100,7 +100,12 @@ Project.Configuration conf CompilerSettings compilerSettings = GetMasterCompilerSettings(masterCompilerSettings, compilerName, devEnv, projectRootPath, platformToolset, false); compilerSettings.PlatformFlags |= Platform.win64; - SetConfiguration(conf, compilerSettings.Configurations, CppConfigName(conf), projectRootPath, devEnv, false); + SetConfiguration(conf, compilerSettings.Configurations, CppConfigName(conf), projectRootPath, devEnv, platformToolset, false); + } + + private static DevEnv? GetCompilerFromToolset(DevEnv devEnv, Options.Vc.General.PlatformToolset platformToolset) + { + return platformToolset == Options.Vc.General.PlatformToolset.Default ? devEnv : platformToolset.GetDefaultDevEnvForToolset(); } public CompilerSettings GetMasterCompilerSettings( @@ -120,33 +125,22 @@ bool useCCompiler } else { - DevEnv? compilerDevEnv = null; string platformToolSetPath = null; string pathToCompiler = null; string compilerExeName = null; var compilerFamily = Sharpmake.CompilerFamily.Auto; var fastBuildSettings = PlatformRegistry.Get(Platform.win64); + var compilerDevEnv = GetCompilerFromToolset(devEnv, platformToolset); - switch (platformToolset) + if (platformToolset.IsLLVMToolchain()) { - case Options.Vc.General.PlatformToolset.Default: - compilerDevEnv = devEnv; - break; - case Options.Vc.General.PlatformToolset.LLVM: - case Options.Vc.General.PlatformToolset.ClangCL: - - platformToolSetPath = platformToolset == Options.Vc.General.PlatformToolset.ClangCL ? ClangForWindows.Settings.LLVMInstallDirVsEmbedded(devEnv) : ClangForWindows.Settings.LLVMInstallDir; - pathToCompiler = Path.Combine(platformToolSetPath, "bin"); - compilerExeName = "clang-cl.exe"; - - var compilerFamilyKey = new FastBuildWindowsCompilerFamilyKey(devEnv, platformToolset); - if (!fastBuildSettings.CompilerFamily.TryGetValue(compilerFamilyKey, out compilerFamily)) - compilerFamily = Sharpmake.CompilerFamily.ClangCl; + platformToolSetPath = platformToolset == Options.Vc.General.PlatformToolset.ClangCL ? ClangForWindows.Settings.LLVMInstallDirVsEmbedded(devEnv) : ClangForWindows.Settings.LLVMInstallDir; + pathToCompiler = Path.Combine(platformToolSetPath, "bin"); + compilerExeName = "clang-cl.exe"; - break; - default: - compilerDevEnv = platformToolset.GetDefaultDevEnvForToolset(); - break; + var compilerFamilyKey = new FastBuildWindowsCompilerFamilyKey(devEnv, platformToolset); + if (!fastBuildSettings.CompilerFamily.TryGetValue(compilerFamilyKey, out compilerFamily)) + compilerFamily = Sharpmake.CompilerFamily.ClangCl; } if (compilerDevEnv.HasValue) @@ -254,7 +248,7 @@ bool useCCompiler string executable = Path.Combine("$ExecutableRootPath$", compilerExeName); - compilerSettings = new CompilerSettings(compilerName, compilerFamily, Platform.win64, extraFiles, executable, pathToCompiler, devEnv, new Dictionary()); + compilerSettings = new CompilerSettings(compilerName, compilerFamily, Platform.win64, extraFiles, executable, pathToCompiler, compilerDevEnv ?? devEnv, new Dictionary()); masterCompilerSettings.Add(compilerName, compilerSettings); } @@ -267,6 +261,7 @@ private void SetConfiguration( string configName, string projectRootPath, DevEnv devEnv, + Options.Vc.General.PlatformToolset platformToolset, bool useCCompiler) { if (configurations.ContainsKey(configName)) @@ -275,12 +270,13 @@ private void SetConfiguration( string linkerPathOverride = null; string linkerExeOverride = null; string librarianExeOverride = null; + var compilerDevEnv = GetCompilerFromToolset(devEnv, platformToolset) ?? devEnv; GetLinkerExecutableInfo(conf, out linkerPathOverride, out linkerExeOverride, out librarianExeOverride); var fastBuildCompilerSettings = PlatformRegistry.Get(Platform.win64); string binPath; if (!fastBuildCompilerSettings.BinPath.TryGetValue(devEnv, out binPath)) - binPath = devEnv.GetVisualStudioBinPath(Platform.win64); + binPath = compilerDevEnv.GetVisualStudioBinPath(Platform.win64); string linkerPath; if (!string.IsNullOrEmpty(linkerPathOverride)) @@ -302,7 +298,7 @@ private void SetConfiguration( string resCompiler; if (!fastBuildCompilerSettings.ResCompiler.TryGetValue(devEnv, out resCompiler)) - resCompiler = devEnv.GetWindowsResourceCompiler(Platform.win64); + resCompiler = compilerDevEnv.GetWindowsResourceCompiler(Platform.win64); string capitalizedBinPath = Util.GetCapitalizedPath(Util.PathGetAbsolute(projectRootPath, binPath)); configurations.Add( diff --git a/Sharpmake/Options.Rider.cs b/Sharpmake/Options.Rider.cs new file mode 100644 index 000000000..02fe7d32f --- /dev/null +++ b/Sharpmake/Options.Rider.cs @@ -0,0 +1,33 @@ +// Copyright (c) Ubisoft. All Rights Reserved. +// Licensed under the Apache 2.0 License. See LICENSE.md in the project root for license information. + +namespace Sharpmake +{ + public static partial class Options + { + public static class Rider + { + /// + /// Specify vcxproj for MSBuild + /// + public class MsBuildOverrideProjectFile : PathOption + { + public MsBuildOverrideProjectFile(string path) : base(path) { } + } + + public class MsBuildOverrideConfigurationName : StringOption + { + public static readonly string Default = null; + public MsBuildOverrideConfigurationName(string path) : base(path) {} + } + + public class MsBuildOverridePlatformName : StringOption + { + public static readonly string Default = null; + public MsBuildOverridePlatformName(string path) : base(path) {} + } + } + } +} + + diff --git a/Sharpmake/Target.cs b/Sharpmake/Target.cs index 06679096b..095ce1bd4 100644 --- a/Sharpmake/Target.cs +++ b/Sharpmake/Target.cs @@ -59,6 +59,11 @@ public enum DevEnv /// GNU Makefiles. /// make = 1 << 9, + + /// + /// Rider project files + /// + rider = 1 << 10, /// /// All supported Visual Studio versions. diff --git a/Sharpmake/Util.cs b/Sharpmake/Util.cs index 302cb27e9..88e05ad12 100644 --- a/Sharpmake/Util.cs +++ b/Sharpmake/Util.cs @@ -1437,7 +1437,9 @@ public static bool IsDotNet(Project.Configuration conf) public static bool IsCpp(Project.Configuration conf) { string extension = Path.GetExtension(conf.ProjectFullFileNameWithExtension); - return (string.Compare(extension, ".vcxproj", StringComparison.OrdinalIgnoreCase) == 0); + return (string.Compare(extension, ".vcxproj", StringComparison.OrdinalIgnoreCase) == 0) || + // RiderJson project files + (string.Compare(extension, ".json", StringComparison.OrdinalIgnoreCase) == 0); } public static string GetProjectFileExtension(Project.Configuration conf) @@ -1472,6 +1474,9 @@ public static string GetProjectFileExtension(Project.Configuration conf) case DevEnv.make: return ".make"; + case DevEnv.rider: + return ".json"; + default: throw new NotImplementedException("GetProjectFileExtension called with unknown DevEnv: " + devEnv); } diff --git a/samples/RiderJson/RiderJson.sharpmake.cs b/samples/RiderJson/RiderJson.sharpmake.cs index d24dafc25..9a51b5825 100644 --- a/samples/RiderJson/RiderJson.sharpmake.cs +++ b/samples/RiderJson/RiderJson.sharpmake.cs @@ -9,7 +9,7 @@ public BaseProject() { AddTargets(new Target( Platform.win64, - DevEnv.vs2017 | DevEnv.vs2019, + DevEnv.rider | DevEnv.vs2022, Optimization.Debug | Optimization.Release, OutputType.Lib, Blob.FastBuildUnitys, @@ -27,6 +27,17 @@ public virtual void ConfigureAll(Configuration conf, Target target) conf.FastBuildBlobbed = target.Blob == Blob.FastBuildUnitys; conf.AdditionalCompilerOptions.Add("/FS"); conf.Options.Add(Options.Vc.Compiler.CppLanguageStandard.CPP17); + + if (conf.Compiler == DevEnv.rider) + { + if (target.BuildSystem == BuildSystem.MSBuild) + { + conf.TargetPath = @"[conf.ProjectPath]\..\vs2022\output\[target.Platform]\[conf.Name]"; + conf.Options.Add(new Options.Rider.MsBuildOverrideProjectFile(@"[conf.ProjectPath]\..\vs2022\[project.Name].vcxproj")); + } + + conf.Options.Add(Options.Vc.General.PlatformToolset.v143); + } } } @@ -111,7 +122,7 @@ public BaseSolution() { AddTargets(new Target( Platform.win64, - DevEnv.vs2019 | DevEnv.vs2017, + DevEnv.rider | DevEnv.vs2022, Optimization.Debug | Optimization.Release, OutputType.Lib, Blob.FastBuildUnitys,