Skip to content

Commit 69b7043

Browse files
committed
Merge branch 'xcode-scheme-improvements' into 'main'
XCode scheme improvements See merge request Sharpmake/sharpmake!562
2 parents 20e3708 + 6325045 commit 69b7043

File tree

3 files changed

+84
-20
lines changed

3 files changed

+84
-20
lines changed

Sharpmake.Generators/Apple/XCodeProj.Template.cs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -491,19 +491,33 @@ private static class Template
491491
};
492492

493493
public static string CommandLineArgumentsBegin =
494-
@"
495-
<CommandLineArguments>";
494+
@" <CommandLineArguments>
495+
";
496496

497497
public static string CommandLineArgument =
498-
@"
499-
<CommandLineArgument
498+
@" <CommandLineArgument
500499
argument = ""[argument]""
501500
isEnabled = ""YES"">
502-
</CommandLineArgument>";
501+
</CommandLineArgument>
502+
";
503503

504504
public static string CommandLineArgumentsEnd =
505-
@"
506-
</CommandLineArguments>";
505+
@" </CommandLineArguments>";
506+
507+
public static string EnvironmentVariablesBegin =
508+
@" <EnvironmentVariables>
509+
";
510+
511+
public static string EnvironmentVariablesEnd =
512+
@" </EnvironmentVariables>";
513+
514+
public static string EnvironmentVariable =
515+
@" <EnvironmentVariable
516+
key = ""[name]""
517+
value = ""[value]""
518+
isEnabled = ""YES"">
519+
</EnvironmentVariable>
520+
";
507521

508522
public static string SchemeTestableReference =
509523
@"
@@ -522,26 +536,26 @@ private static class Template
522536
/// This section is used to configure the executable to run for native projects.
523537
/// </summary>
524538
public static string SchemeRunnableNativeProject =
525-
@"
526-
<BuildableProductRunnable>
539+
@" <BuildableProductRunnable>
527540
<BuildableReference
528541
BuildableIdentifier = ""primary""
529542
BlueprintIdentifier = ""[item.Uid]""
530543
BuildableName = ""[item.OutputFile.BuildableName]""
531544
BlueprintName = ""[item.Identifier]""
532545
ReferencedContainer = ""container:[projectFile].xcodeproj"">
533546
</BuildableReference>
534-
</BuildableProductRunnable>";
547+
</BuildableProductRunnable>
548+
";
535549

536550
/// <summary>
537551
/// This section is used to configure the executable to run for makefile projects.
538552
/// </summary>
539553
public static string SchemeRunnableMakeFileProject =
540-
@"
541-
<PathRunnable
554+
@" <PathRunnable
542555
runnableDebuggingMode = ""0""
543556
FilePath = ""[runnableFilePath]"">
544-
</PathRunnable>";
557+
</PathRunnable>
558+
";
545559

546560
/// <summary>
547561
/// First part of schema file
@@ -595,13 +609,15 @@ private static class Template
595609
debugDocumentVersioning = ""YES""
596610
enableGPUFrameCaptureMode = ""[options.EnableGpuFrameCaptureMode]""
597611
enableGPUValidationMode = ""[options.MetalAPIValidation]""
598-
allowLocationSimulation = ""YES"">";
612+
allowLocationSimulation = ""YES"">
613+
";
599614

600615
/// <summary>
601616
/// Secondpart of schema file
602617
/// </summary>
603618
public static string SchemeFileTemplatePart2 =
604619
@"[commandLineArguments]
620+
[environmentVariables]
605621
<AdditionalOptions>
606622
</AdditionalOptions>
607623
</LaunchAction>

Sharpmake.Generators/Apple/XCodeProj.cs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ string projectFile
286286
// Setup resolvers
287287
var fileGenerator = new FileGenerator();
288288

289+
var defaultConfiguration = configurations.Where(conf => conf.UseAsDefaultForXCode == true).FirstOrDefault();
290+
Project.Configuration activeConfiguration = defaultConfiguration != null ? defaultConfiguration : configurations[0];
291+
289292
// Build testable elements
290293
var testableTargets = _nativeOrLegacyTargets.Values.Where(target => target.OutputFile.OutputType == Project.Configuration.OutputType.IosTestBundle);
291294
var testableElements = new StringBuilder();
@@ -299,7 +302,7 @@ string projectFile
299302
}
300303

301304
// Build commandLineArguments
302-
var debugArguments = Options.GetObject<Options.XCode.Scheme.DebugArguments>(configurations[0]);
305+
var debugArguments = Options.GetObject<Options.XCode.Scheme.DebugArguments>(activeConfiguration);
303306
var commandLineArguments = new StringBuilder();
304307
if (debugArguments != null)
305308
{
@@ -311,34 +314,60 @@ string projectFile
311314
}
312315
commandLineArguments.Append(Template.CommandLineArgumentsEnd);
313316
}
317+
else
318+
{
319+
commandLineArguments.Append(RemoveLineTag);
320+
}
314321

315322
// Write the scheme file
316323
var defaultTarget = _nativeOrLegacyTargets.Values.Where(target => target.OutputFile.OutputType != Project.Configuration.OutputType.IosTestBundle).FirstOrDefault();
317324

318325
var options = new Options.ExplicitOptions();
319-
Options.SelectOption(configurations[0],
326+
Options.SelectOption(activeConfiguration,
320327
Options.Option(Options.XCode.Compiler.EnableGpuFrameCaptureMode.AutomaticallyEnable, () => options["EnableGpuFrameCaptureMode"] = RemoveLineTag),
321328
Options.Option(Options.XCode.Compiler.EnableGpuFrameCaptureMode.MetalOnly, () => options["EnableGpuFrameCaptureMode"] = "1"),
322329
Options.Option(Options.XCode.Compiler.EnableGpuFrameCaptureMode.OpenGLOnly, () => options["EnableGpuFrameCaptureMode"] = "2"),
323330
Options.Option(Options.XCode.Compiler.EnableGpuFrameCaptureMode.Disable, () => options["EnableGpuFrameCaptureMode"] = "3")
324331
);
325332
// An empty line means ON, "1" means OFF
326333
// https://gitlab.kitware.com/cmake/cmake/-/issues/23857
327-
Options.SelectOption(configurations[0],
334+
Options.SelectOption(activeConfiguration,
328335
Options.Option(Options.XCode.Scheme.MetalAPIValidation.Enable, () => options["MetalAPIValidation"] = RemoveLineTag),
329336
Options.Option(Options.XCode.Scheme.MetalAPIValidation.Disable, () => options["MetalAPIValidation"] = "1")
330337
);
331338

332-
var defaultConfiguration = configurations.Where(conf => conf.UseAsDefaultForXCode == true).FirstOrDefault();
333-
Project.Configuration activeConfiguration = defaultConfiguration != null ? defaultConfiguration : configurations[0];
334339
string targetName = $"&quot;{activeConfiguration.Target.Name}&quot;";
335340
string buildImplicitDependencies = activeConfiguration.IsFastBuild ? "NO" : "YES";
336341
bool useBuildableProductRunnableSection = true;
337342
string runnableFilePath = string.Empty;
338343
if (activeConfiguration.IsFastBuild && activeConfiguration.Output == Project.Configuration.OutputType.AppleApp && !activeConfiguration.XcodeUseNativeProjectForFastBuildApp)
339344
{
340345
useBuildableProductRunnableSection = false;
341-
runnableFilePath = Path.Combine(activeConfiguration.TargetPath, activeConfiguration.TargetFileFullNameWithExtension);
346+
var customRunnablePath = Options.GetObject<Options.XCode.Scheme.CustomRunnablePath>(activeConfiguration);
347+
if (customRunnablePath != null)
348+
runnableFilePath = customRunnablePath.Path;
349+
else
350+
runnableFilePath = Path.Combine(activeConfiguration.TargetPath, activeConfiguration.TargetFileFullNameWithExtension);
351+
}
352+
353+
var environmentVariables = Options.GetObject<Options.XCode.Scheme.EnvironmentVariables>(activeConfiguration);
354+
var environmentVariablesBuilder = new StringBuilder();
355+
if (environmentVariables != null)
356+
{
357+
environmentVariablesBuilder.Append(Template.EnvironmentVariablesBegin);
358+
foreach (var variable in environmentVariables.Variables)
359+
{
360+
using (fileGenerator.Declare("name", variable.Key))
361+
using (fileGenerator.Declare("value", variable.Value))
362+
{
363+
environmentVariablesBuilder.Append(fileGenerator.Resolver.Resolve(Template.EnvironmentVariable));
364+
}
365+
}
366+
environmentVariablesBuilder.Append(Template.EnvironmentVariablesEnd);
367+
}
368+
else
369+
{
370+
environmentVariablesBuilder.Append(RemoveLineTag);
342371
}
343372

344373
using (fileGenerator.Declare("projectFile", projectFile))
@@ -347,8 +376,12 @@ string projectFile
347376
using (fileGenerator.Declare("testableElements", testableElements))
348377
using (fileGenerator.Declare("DefaultTarget", targetName))
349378
using (fileGenerator.Declare("commandLineArguments", commandLineArguments))
379+
using (fileGenerator.Declare("environmentVariables", environmentVariablesBuilder))
350380
using (fileGenerator.Declare("buildImplicitDependencies", buildImplicitDependencies))
351381
using (fileGenerator.Declare("runnableFilePath", runnableFilePath))
382+
using (fileGenerator.Declare("project", activeConfiguration.Project))
383+
using (fileGenerator.Declare("target", activeConfiguration.Target))
384+
using (fileGenerator.Declare("conf", activeConfiguration))
352385
{
353386
fileGenerator.Write(Template.SchemeFileTemplatePart1);
354387
if (useBuildableProductRunnableSection)

Sharpmake/Options.XCode.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,21 @@ public DebugArguments(List<string> args)
11991199
{
12001200
}
12011201
}
1202+
1203+
public class EnvironmentVariables
1204+
{
1205+
public Dictionary<string, string> Variables { get; set; } = new Dictionary<string, string>();
1206+
}
1207+
1208+
/// <summary>
1209+
/// This option can be used to set a custom runnable path in the scheme file for fastbuild targets
1210+
/// </summary>
1211+
public class CustomRunnablePath : PathOption
1212+
{
1213+
public CustomRunnablePath(string path) : base(path)
1214+
{
1215+
}
1216+
}
12021217
}
12031218
}
12041219
}

0 commit comments

Comments
 (0)