@@ -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 = $ ""{ activeConfiguration . Target . Name } "";
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 )
0 commit comments