Skip to content

Commit

Permalink
Merge branch '183-xcode-add-dynamic-library-install-name-option' into…
Browse files Browse the repository at this point in the history
… 'main'

Resolve "XCode add Dynamic Library Install Name option"

See merge request Sharpmake/sharpmake!522
  • Loading branch information
jspelletier committed Jun 6, 2024
2 parents ca08fc9 + d3a86b2 commit 4d216e4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sharpmake.Generators/Apple/XCodeProj.Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ private static class Template
GCC_WARN_UNINITIALIZED_AUTOS = [item.Options.WarningUniniatializedAutos];
GCC_WARN_UNUSED_FUNCTION = [item.Options.WarningUnusedFunction];
GCC_WARN_UNUSED_VARIABLE = [item.Options.WarningUnusedVariable];
LD_DYLIB_INSTALL_NAME = ""[item.Options.DyLibInstallName]"";
ONLY_ACTIVE_ARCH = [item.Options.OnlyActiveArch];
OTHER_CPLUSPLUSFLAGS = [item.Options.CompilerOptions];
OTHER_LDFLAGS = [item.Options.LinkerOptions];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public abstract partial class BaseApplePlatform
// Additional linker options
//--------------------------
+ ' [options.AdditionalLinkerOptions]'
+ ' [cmdLineOptions.DyLibInstallName]'
";

private const string _compilerExtraOptionsGeneral = @"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ public virtual void SelectCompilerOptions(IGenerationContext context)
else
options["CodeSigningIdentity"] = FileGeneratorUtilities.RemoveLineTag;

options["DyLibInstallName"] = XCodeUtil.ResolveProjectVariable(project, Options.StringOption.Get<Options.XCode.Linker.DyLibInstallName>(conf));

context.SelectOption(
Options.Option(Options.XCode.Compiler.OnlyActiveArch.Disable, () => options["OnlyActiveArch"] = "NO"),
Options.Option(Options.XCode.Compiler.OnlyActiveArch.Enable, () => options["OnlyActiveArch"] = "YES")
Expand Down Expand Up @@ -1217,6 +1219,12 @@ public virtual void SelectLinkerOptions(IGenerationContext context)
options["PreLinkedLibraries"] = prelinkedLibrary;
}

var dylibInstallName = XCodeUtil.ResolveProjectVariable(context.Project, Options.StringOption.Get<Options.XCode.Linker.DyLibInstallName>(conf));
if (!string.IsNullOrEmpty(dylibInstallName))
{
cmdLineOptions["DyLibInstallName"] = $"-install_name \"{dylibInstallName}\"";
}

OrderableStrings systemFrameworks = new OrderableStrings(conf.XcodeSystemFrameworks);
systemFrameworks.AddRange(conf.XcodeDependenciesSystemFrameworks);
cmdLineOptions["SystemFrameworks"] = systemFrameworks.Any() ? "-framework " + systemFrameworks.JoinStrings(" -framework ") : FileGeneratorUtilities.RemoveLineTag;
Expand Down
11 changes: 11 additions & 0 deletions Sharpmake/Options.XCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,17 @@ public enum LinkObjC
[Default]
Enable
}

/// <summary>
/// Sets an internal install path (LC_ID_DYLIB) in a dynamic library. Any clients linked against the library will record that path as the way dyld should locate this library.
/// </summary>
public class DyLibInstallName : StringOption
{
public DyLibInstallName(string value) : base(value)
{
}
}

}

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions samples/HelloXCode/codebase/dll1/dll1.sharpmake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@ public override void ConfigureAll(Configuration conf, CommonTarget target)

conf.AddPrivateDependency<StaticLib1Project>(target);
}

public override void ConfigureMac(Configuration conf, CommonTarget target)
{
base.ConfigureMac(conf, target);

conf.Options.Add(new Options.XCode.Linker.DyLibInstallName(@"@executable_path/libdll1.dylib"));
}
}
}

0 comments on commit 4d216e4

Please sign in to comment.