From 0d4f3f461032631a99df6bcd794bad3bd59b6f46 Mon Sep 17 00:00:00 2001 From: Sylvain Audi Date: Wed, 24 Jul 2024 12:23:43 -0400 Subject: [PATCH] XCode: Allow forcing linking a library without "-l", using regular input file This is to avoid conflicts with "-lname" where the folder contains both libname.a and libname.dylib This is done by setting a full path with extension to the library, like conf.AddLibrary(@"/path/to/libnname.a") It is also applied to dependencies to Lib/Dll projects of [Export] generation type. --- Sharpmake.Generators/Apple/XCodeProj.cs | 16 +++++++++--- .../Apple/BaseApplePlatform.cs | 26 ++----------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/Sharpmake.Generators/Apple/XCodeProj.cs b/Sharpmake.Generators/Apple/XCodeProj.cs index c8125b475..923fa09a7 100644 --- a/Sharpmake.Generators/Apple/XCodeProj.cs +++ b/Sharpmake.Generators/Apple/XCodeProj.cs @@ -1501,17 +1501,25 @@ private Options.ExplicitOptions GenerateOptions(XCodeGenerationContext context) // linker(ld) of Xcode: only accept libfilename without prefix and suffix. linkerOptions.AddRange(libFiles.Select(library => { + bool hasLibraryExtension = Path.HasExtension(library) && + ((Path.GetExtension(library).EndsWith(".a", StringComparison.OrdinalIgnoreCase) || + Path.GetExtension(library).EndsWith(".dylib", StringComparison.OrdinalIgnoreCase) + )); + // deal with full library path: add libdir and libname if (Path.IsPathFullyQualified(library)) { + // Special case with full path: pass them as is. + // This is to leave the possibility to force the extension, + // preventing conflict if the folder contains both .a and .dylib version. + if (hasLibraryExtension) + return library; + conf.LibraryPaths.Add(Path.GetDirectoryName(library)); library = Path.GetFileName(library); } - if (Path.HasExtension(library) && - ((Path.GetExtension(library).EndsWith(".a", StringComparison.OrdinalIgnoreCase) || - Path.GetExtension(library).EndsWith(".dylib", StringComparison.OrdinalIgnoreCase) - ))) + if (hasLibraryExtension) { library = Path.GetFileNameWithoutExtension(library); if (library.StartsWith("lib")) diff --git a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs index cb213ed39..497777b15 100644 --- a/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs +++ b/Sharpmake.Platforms/Sharpmake.CommonPlatforms/Apple/BaseApplePlatform.cs @@ -360,21 +360,10 @@ public void SetupDynamicLibraryPaths(Project.Configuration configuration, Depend dependency.TargetFileFullNameWithExtension, dependency.TargetFileOrderNumber); } - else if (dependency.Project.SharpmakeProjectType == Project.ProjectTypeAttribute.Export && configuration.IsFastBuild) - { - if (dependencySetting.HasFlag(DependencySetting.LibraryFiles)) - configuration.AddDependencyBuiltTargetLibraryFile(Path.Combine(dependency.TargetLibraryPath, dependency.TargetFileFullNameWithExtension), dependency.TargetFileOrderNumber); - } else { - if (dependencySetting.HasFlag(DependencySetting.LibraryPaths)) - configuration.DependenciesOtherLibraryPaths.Add(dependency.TargetPath, dependency.TargetLibraryPathOrderNumber); if (dependencySetting.HasFlag(DependencySetting.LibraryFiles)) - configuration.DependenciesOtherLibraryFiles.Add( - dependency.PreferRelativePaths ? - dependency.TargetFileName : - dependency.TargetFileFullNameWithExtension, - dependency.TargetFileOrderNumber); + configuration.AddDependencyBuiltTargetLibraryFile(Path.Combine(dependency.TargetLibraryPath, dependency.TargetFileFullNameWithExtension), dependency.TargetFileOrderNumber); } } @@ -392,21 +381,10 @@ public void SetupStaticLibraryPaths(Project.Configuration configuration, Depende dependency.TargetFileFullNameWithExtension, dependency.TargetFileOrderNumber); } - else if (dependency.Project.SharpmakeProjectType == Project.ProjectTypeAttribute.Export && configuration.IsFastBuild) - { - if (dependencySetting.HasFlag(DependencySetting.LibraryFiles)) - configuration.DependenciesOtherLibraryFiles.Add(Path.Combine(dependency.TargetLibraryPath, dependency.TargetFileFullNameWithExtension), dependency.TargetFileOrderNumber); - } else { - if (dependencySetting.HasFlag(DependencySetting.LibraryPaths)) - configuration.DependenciesOtherLibraryPaths.Add(dependency.TargetLibraryPath, dependency.TargetLibraryPathOrderNumber); if (dependencySetting.HasFlag(DependencySetting.LibraryFiles)) - configuration.DependenciesOtherLibraryFiles.Add( - dependency.PreferRelativePaths ? - dependency.TargetFileName : - dependency.TargetFileFullNameWithExtension, - dependency.TargetFileOrderNumber); + configuration.DependenciesOtherLibraryFiles.Add(Path.Combine(dependency.TargetLibraryPath, dependency.TargetFileFullNameWithExtension), dependency.TargetFileOrderNumber); } }