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,