From 2acc088ffb648a637ef9843d47cf0dc8c356d366 Mon Sep 17 00:00:00 2001 From: Chris Savoie Date: Tue, 25 Jun 2019 23:19:42 -0700 Subject: [PATCH 1/3] [Mac] Move mac solution generation into DevEnv switch case * Fixes solution makefile generation for mac. --- Sharpmake.Generators/GeneratorManager.cs | 65 ++++++++++++------------ 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/Sharpmake.Generators/GeneratorManager.cs b/Sharpmake.Generators/GeneratorManager.cs index e48ad7354..92804c933 100644 --- a/Sharpmake.Generators/GeneratorManager.cs +++ b/Sharpmake.Generators/GeneratorManager.cs @@ -129,45 +129,44 @@ public void Generate(Builder builder, List generatedFiles, List skipFiles) { - if (configurations[0].Platform == Platform.ios || configurations[0].Platform == Platform.mac) + DevEnv devEnv = configurations[0].Target.GetFragment(); + switch (devEnv) { - XCWorkspaceGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); - if (UtilityMethods.HasFastBuildConfig(configurations)) - { - MasterBffGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); - } - } - else - { - DevEnv devEnv = configurations[0].Target.GetFragment(); - switch (devEnv) - { - case DevEnv.make: + case DevEnv.make: + { + if (configurations[0].Platform == Platform.android) + MakeApplicationGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); + else + MakefileGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); + break; + } + case DevEnv.vs2015: + case DevEnv.vs2017: + case DevEnv.vs2019: + case DevEnv.vs2022: + { + if (UtilityMethods.HasFastBuildConfig(configurations)) { - if (configurations[0].Platform == Platform.android) - MakeApplicationGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); - else - MakefileGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); - break; + MasterBffGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); } - case DevEnv.vs2015: - case DevEnv.vs2017: - case DevEnv.vs2019: - case DevEnv.vs2022: - { - if (UtilityMethods.HasFastBuildConfig(configurations)) - { - MasterBffGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); - } - SlnGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); - break; - } - default: + SlnGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); + break; + } + case DevEnv.xcode4ios: + { + if (UtilityMethods.HasFastBuildConfig(configurations)) { - throw new Error("Generate called with unknown DevEnv: " + devEnv); + MasterBffGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); } - } + + XCWorkspaceGenerator.Generate(builder, solution, configurations, solutionFile, generatedFiles, skipFiles); + break; + } + default: + { + throw new Error("Generate called with unknown DevEnv: " + devEnv); + } } } } From 7de200b21d4198cfb905278a2698e99d55c47430 Mon Sep 17 00:00:00 2001 From: Chris Savoie Date: Wed, 9 Feb 2022 22:19:14 -0800 Subject: [PATCH 2/3] [Mac] Add, and make default, a Library Standard option CompilerDefault which will omit any specific command line to set the cpp standard. --- .../Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs | 2 ++ Sharpmake/Options.XCode.cs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs index 1ece4469c..bf524e63e 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs @@ -619,6 +619,7 @@ public virtual void SelectCompilerOptions(IGenerationContext context) ); context.SelectOption( + Options.Option(Options.XCode.Compiler.LibraryStandard.CompilerDefault, () => { options["LibraryStandard"] = FileGeneratorUtilities.RemoveLineTag; cmdLineOptions["LibraryStandard"] = FileGeneratorUtilities.RemoveLineTag; }), Options.Option(Options.XCode.Compiler.LibraryStandard.CppStandard, () => { options["LibraryStandard"] = "libstdc++"; cmdLineOptions["LibraryStandard"] = "-stdlib=libstdc++"; }), Options.Option(Options.XCode.Compiler.LibraryStandard.LibCxx, () => { options["LibraryStandard"] = "libc++"; cmdLineOptions["LibraryStandard"] = "-stdlib=libc++"; }) ); @@ -645,6 +646,7 @@ public virtual void SelectCompilerOptions(IGenerationContext context) ); context.SelectOption( + Options.Option(Options.XCode.Compiler.LibraryStandard.CompilerDefault, () => { options["LibraryStandard"] = FileGeneratorUtilities.RemoveLineTag; }), Options.Option(Options.XCode.Compiler.LibraryStandard.CppStandard, () => options["LibraryStandard"] = "libstdc++"), Options.Option(Options.XCode.Compiler.LibraryStandard.LibCxx, () => options["LibraryStandard"] = "libc++") ); diff --git a/Sharpmake/Options.XCode.cs b/Sharpmake/Options.XCode.cs index 997e43fe8..88f85ed49 100644 --- a/Sharpmake/Options.XCode.cs +++ b/Sharpmake/Options.XCode.cs @@ -263,8 +263,9 @@ public IPhoneOSDeploymentTarget(string minimumVersion) public enum LibraryStandard { - CppStandard, [Default] + CompilerDefault, + CppStandard, LibCxx } From da13c6d2f58d26787ec31d4012500d69071a8e8a Mon Sep 17 00:00:00 2001 From: Chris Savoie Date: Tue, 15 Feb 2022 23:52:53 -0800 Subject: [PATCH 3/3] [Mac] Fix makefiles to pass in library paths without -l and to only allow -l format on mac since -l: is not supported. --- Sharpmake.Generators/Generic/Makefile.cs | 54 +++++++++++++++--------- Sharpmake/ExtensionMethods.cs | 4 ++ 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/Sharpmake.Generators/Generic/Makefile.cs b/Sharpmake.Generators/Generic/Makefile.cs index 372b696fb..60ee6341a 100644 --- a/Sharpmake.Generators/Generic/Makefile.cs +++ b/Sharpmake.Generators/Generic/Makefile.cs @@ -561,19 +561,8 @@ private Options.ExplicitOptions GenerateOptions(Project.Configuration conf, File // OutputFile options["OutputFile"] = conf.TargetFileFullNameWithExtension.Replace(" ", @"\ "); - // DependenciesLibraryFiles - var dependenciesLibraryFiles = new OrderableStrings(conf.DependenciesLibraryFiles); - FixupLibraryNames(dependenciesLibraryFiles); - dependenciesLibraryFiles.InsertPrefix("-l:"); - dependenciesLibraryFiles.Sort(); - options["DependenciesLibraryFiles"] = dependenciesLibraryFiles.JoinStrings(" "); - // LibraryFiles - OrderableStrings libraryFiles = new OrderableStrings(conf.LibraryFiles); - FixupLibraryNames(libraryFiles); - libraryFiles.InsertPrefix("-l:"); - libraryFiles.Sort(); - options["LibraryFiles"] = libraryFiles.JoinStrings(" "); + options["LibraryFiles"] = GenerateLibraryReferences(conf.LibraryFiles, conf); // LibraryPaths OrderableStrings libraryPaths = new OrderableStrings(); @@ -608,6 +597,10 @@ private Options.ExplicitOptions GenerateOptions(Project.Configuration conf, File depsRelative.Sort(); options["LDDEPS"] = depsRelative.JoinStrings(" "); + // DependenciesLibraryFiles + options["DependenciesLibraryFiles"] = GenerateLibraryReferences(conf.DependenciesOtherLibraryFiles, conf, depsRelative); + + // LinkCommand if (conf.Output == Project.Configuration.OutputType.Lib) { @@ -697,20 +690,41 @@ private string GetOutputDirectory(Project.Configuration conf, FileInfo projectFi return Util.PathGetRelative(projectFileInfo.DirectoryName, conf.TargetPath); } - private static void FixupLibraryNames(IList paths) + private static string GenerateLibraryReferences(OrderableStrings paths, Project.Configuration conf, OrderableStrings pathsToMerge = null) { for (int i = 0; i < paths.Count; ++i) { string libraryName = PathMakeUnix(paths[i]); - // We've got two kinds of way of listing a library: - // - With a filename without extension we must add the potential prefix and potential extension. - // - With a filename with a static or shared lib extension (eg. .a/.so), we shouldn't touch it as it's already set by the script. - string extension = Path.GetExtension(libraryName).ToLowerInvariant(); - if (extension != ".a" && extension != ".so") - paths[i] = "lib" + libraryName + ".a"; + if (File.Exists(libraryName)) + { + // If this is a full path to an existing file then do nothing, the linker can accept + // it as a direct argument instead of having to go through -l + } + else if (conf.Platform.IsMac()) + { + // Mac ld only supports -l