Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mac] Roundup of fixes for building on mac #182

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 32 additions & 33 deletions Sharpmake.Generators/GeneratorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,45 +129,44 @@ public void Generate(Builder builder,
List<string> generatedFiles,
List<string> skipFiles)
{
if (configurations[0].Platform == Platform.ios || configurations[0].Platform == Platform.mac)
DevEnv devEnv = configurations[0].Target.GetFragment<DevEnv>();
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<DevEnv>();
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);
}
}
}
}
Expand Down
54 changes: 34 additions & 20 deletions Sharpmake.Generators/Generic/Makefile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -697,20 +690,41 @@ private string GetOutputDirectory(Project.Configuration conf, FileInfo projectFi
return Util.PathGetRelative(projectFileInfo.DirectoryName, conf.TargetPath);
}

private static void FixupLibraryNames(IList<string> 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<name
paths[i] = "-l" + libraryName;
}
else
paths[i] = libraryName;
{
// 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] = "-l:lib" + libraryName + ".a";
else
paths[i] = "-l:" + libraryName;
}
}

if (pathsToMerge != null)
{
paths.AddRange(pathsToMerge);
}

paths.Sort();
return paths.JoinStrings(" ");
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++"; })
);
Expand All @@ -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++")
);
Expand Down
4 changes: 4 additions & 0 deletions Sharpmake/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion Sharpmake/Options.XCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ public IPhoneOSDeploymentTarget(string minimumVersion)

public enum LibraryStandard
{
CppStandard,
[Default]
CompilerDefault,
CppStandard,
LibCxx
}

Expand Down