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); + } } } } 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 { 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/ExtensionMethods.cs b/Sharpmake/ExtensionMethods.cs index 55b629be5..e8474e1e3 100644 --- a/Sharpmake/ExtensionMethods.cs +++ b/Sharpmake/ExtensionMethods.cs @@ -25,6 +25,10 @@ public static bool IsPC(this Platform platform) { return platform == Platform.win32 || platform == Platform.win64; } + public static bool IsMac(this Platform platform) + { + return platform == Platform.ios || platform == Platform.mac; + } public static bool IsMicrosoft(this Platform platform) { 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 }