From d3a86b2844da1689512c7ca02c94de56c5ed36ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Laberge?= Date: Thu, 6 Jun 2024 12:58:52 +0000 Subject: [PATCH] XCode add Dynamic Library Install Name option --- Sharpmake.Generators/Apple/XCodeProj.Template.cs | 1 + .../Apple/BaseApplePlatform.Bff.Template.cs | 1 + .../Apple/BaseApplePlatform.cs | 8 ++++++++ Sharpmake/Options.XCode.cs | 11 +++++++++++ samples/HelloXCode/codebase/dll1/dll1.sharpmake.cs | 7 +++++++ 5 files changed, 28 insertions(+) diff --git a/Sharpmake.Generators/Apple/XCodeProj.Template.cs b/Sharpmake.Generators/Apple/XCodeProj.Template.cs index 3e4108996..b9aaf65f2 100644 --- a/Sharpmake.Generators/Apple/XCodeProj.Template.cs +++ b/Sharpmake.Generators/Apple/XCodeProj.Template.cs @@ -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]; diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.Bff.Template.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.Bff.Template.cs index eaad19820..45478fb8a 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.Bff.Template.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.Bff.Template.cs @@ -30,6 +30,7 @@ public abstract partial class BaseApplePlatform // Additional linker options //-------------------------- + ' [options.AdditionalLinkerOptions]' + + ' [cmdLineOptions.DyLibInstallName]' "; private const string _compilerExtraOptionsGeneral = @" diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs index 979dd8e5d..4d19b9625 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs @@ -617,6 +617,8 @@ public virtual void SelectCompilerOptions(IGenerationContext context) else options["CodeSigningIdentity"] = FileGeneratorUtilities.RemoveLineTag; + options["DyLibInstallName"] = XCodeUtil.ResolveProjectVariable(project, Options.StringOption.Get(conf)); + context.SelectOption( Options.Option(Options.XCode.Compiler.OnlyActiveArch.Disable, () => options["OnlyActiveArch"] = "NO"), Options.Option(Options.XCode.Compiler.OnlyActiveArch.Enable, () => options["OnlyActiveArch"] = "YES") @@ -1217,6 +1219,12 @@ public virtual void SelectLinkerOptions(IGenerationContext context) options["PreLinkedLibraries"] = prelinkedLibrary; } + var dylibInstallName = XCodeUtil.ResolveProjectVariable(context.Project, Options.StringOption.Get(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; diff --git a/Sharpmake/Options.XCode.cs b/Sharpmake/Options.XCode.cs index d5fc92264..4a591a684 100644 --- a/Sharpmake/Options.XCode.cs +++ b/Sharpmake/Options.XCode.cs @@ -1152,6 +1152,17 @@ public enum LinkObjC [Default] Enable } + + /// + /// 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. + /// + public class DyLibInstallName : StringOption + { + public DyLibInstallName(string value) : base(value) + { + } + } + } /// diff --git a/samples/HelloXCode/codebase/dll1/dll1.sharpmake.cs b/samples/HelloXCode/codebase/dll1/dll1.sharpmake.cs index f6787b85d..28d1e6702 100644 --- a/samples/HelloXCode/codebase/dll1/dll1.sharpmake.cs +++ b/samples/HelloXCode/codebase/dll1/dll1.sharpmake.cs @@ -32,5 +32,12 @@ public override void ConfigureAll(Configuration conf, CommonTarget target) conf.AddPrivateDependency(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")); + } } }