in Sharpmake.Generators/VisualStudio/ProjectOptionsGenerator.cs [1922:2116]
private void GeneratePostBuildOptions(IGenerationContext context, ProjectOptionsGenerationContext optionsContext)
{
string eventSeparator = Vcxproj.EventSeparator;
if (context.Configuration.EventPreBuild.Count == 0)
{
context.Options["PreBuildEvent"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["PreBuildEventDescription"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["PreBuildEventEnable"] = FileGeneratorUtilities.RemoveLineTag;
}
else
{
context.Options["PreBuildEvent"] = (context.Configuration.EventPreBuild.JoinStrings(eventSeparator) + eventSeparator).Replace(@"""", @""");
context.Options["PreBuildEventDescription"] = context.Configuration.EventPreBuildDescription != string.Empty ? context.Configuration.EventPreBuildDescription : FileGeneratorUtilities.RemoveLineTag;
context.Options["PreBuildEventEnable"] = context.Configuration.EventPreBuildExcludedFromBuild ? "false" : "true";
}
if (context.Configuration.EventPreLink.Count == 0)
{
context.Options["PreLinkEvent"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["PreLinkEventDescription"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["PreLinkEventEnable"] = FileGeneratorUtilities.RemoveLineTag;
}
else
{
context.Options["PreLinkEvent"] = (context.Configuration.EventPreLink.JoinStrings(eventSeparator) + eventSeparator).Replace(@"""", @""");
context.Options["PreLinkEventDescription"] = context.Configuration.EventPreLinkDescription != string.Empty ? context.Configuration.EventPreLinkDescription : FileGeneratorUtilities.RemoveLineTag;
context.Options["PreLinkEventEnable"] = context.Configuration.EventPreLinkExcludedFromBuild ? "false" : "true";
}
if (context.Configuration.EventPrePostLink.Count == 0)
{
context.Options["PrePostLinkEvent"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["PrePostLinkEventDescription"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["PrePostLinkEventEnable"] = FileGeneratorUtilities.RemoveLineTag;
}
else
{
context.Options["PrePostLinkEvent"] = (context.Configuration.EventPrePostLink.JoinStrings(eventSeparator) + eventSeparator).Replace(@"""", @""");
context.Options["PrePostLinkEventDescription"] = context.Configuration.EventPrePostLinkDescription != string.Empty ? context.Configuration.EventPrePostLinkDescription : FileGeneratorUtilities.RemoveLineTag;
context.Options["PrePostLinkEventEnable"] = context.Configuration.EventPrePostLinkExcludedFromBuild ? "false" : "true";
}
if (!context.Configuration.IsFastBuild)
{
if (context.Configuration.Output == Project.Configuration.OutputType.Exe || context.Configuration.ExecuteTargetCopy)
{
foreach (var customEvent in context.Configuration.ResolvedEventPreBuildExe)
{
if (customEvent is Project.Configuration.BuildStepExecutable)
{
var execEvent = (Project.Configuration.BuildStepExecutable)customEvent;
string relativeExecutableFile = Util.PathGetRelative(context.ProjectDirectory, execEvent.ExecutableFile);
string eventString = string.Format(
"{0} {1}",
Util.SimplifyPath(relativeExecutableFile),
execEvent.ExecutableOtherArguments
);
context.Configuration.EventPreBuild.Add(eventString);
}
else if (customEvent is Project.Configuration.BuildStepCopy)
{
var copyEvent = (Project.Configuration.BuildStepCopy)customEvent;
context.Configuration.EventPreBuild.Add(copyEvent.GetCopyCommand(context.ProjectDirectory, optionsContext.Resolver));
}
else
{
throw new Error("Unsupported type of build event found in Prebuild steps: " + customEvent.GetType().Name);
}
}
foreach (var customEvent in context.Configuration.ResolvedEventPostBuildExe)
{
if (customEvent is Project.Configuration.BuildStepExecutable)
{
var execEvent = (Project.Configuration.BuildStepExecutable)customEvent;
string relativeExecutableFile = Util.PathGetRelative(context.ProjectDirectory, execEvent.ExecutableFile);
string eventString = string.Format(
"{0} {1}",
Util.SimplifyPath(relativeExecutableFile),
execEvent.ExecutableOtherArguments
);
if (!context.Configuration.EventPostBuild.Contains(eventString))
context.Configuration.EventPostBuild.Add(eventString);
}
else if (customEvent is Project.Configuration.BuildStepCopy)
{
var copyEvent = (Project.Configuration.BuildStepCopy)customEvent;
string eventString = copyEvent.GetCopyCommand(context.ProjectDirectory, optionsContext.Resolver);
if (!context.Configuration.EventPostBuild.Contains(eventString))
context.Configuration.EventPostBuild.Add(eventString);
}
else
{
throw new Error("Unsupported type of build event found in PostBuild steps: " + customEvent.GetType().Name);
}
}
}
if (context.Configuration.Output == Project.Configuration.OutputType.Exe || context.Configuration.Output == Project.Configuration.OutputType.Dll)
{
if (context.Configuration.PostBuildStepTest != null)
{
// First, execute tests
context.Configuration.EventPostBuild.Insert(0,
string.Format(
"{0} {1}",
Util.SimplifyPath(Util.PathGetRelative(context.ProjectDirectory, context.Configuration.PostBuildStepTest.TestExecutable)),
context.Configuration.PostBuildStepTest.TestArguments
)
);
}
if (context.Configuration.PostBuildStampExe != null || context.Configuration.PostBuildStampExes.Any())
{
// NO, first, execute stamp !
var stampEnumerator = context.Configuration.PostBuildStampExes.Prepend(context.Configuration.PostBuildStampExe).Where(x => x != null);
List<string> stampStrings = stampEnumerator.Select(
stampExe => string.Format(
"{0} {1} {2} {3}",
Util.SimplifyPath(Util.PathGetRelative(context.ProjectDirectory, stampExe.ExecutableFile)),
stampExe.ExecutableInputFileArgumentOption,
stampExe.ExecutableOutputFileArgumentOption,
stampExe.ExecutableOtherArguments
)).ToList();
context.Configuration.EventPostBuild.InsertRange(0, stampStrings);
}
}
}
if (context.Configuration.EventPreBuild.Count == 0)
{
context.Options["PreBuildEvent"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["PreBuildEventDescription"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["PreBuildEventEnable"] = FileGeneratorUtilities.RemoveLineTag;
}
else
{
context.Options["PreBuildEvent"] = context.Configuration.EventPreBuild.JoinStrings(eventSeparator, escapeXml: true) + eventSeparator;
context.Options["PreBuildEventDescription"] = context.Configuration.EventPreBuildDescription != string.Empty ? context.Configuration.EventPreBuildDescription : FileGeneratorUtilities.RemoveLineTag;
context.Options["PreBuildEventEnable"] = context.Configuration.EventPreBuildExcludedFromBuild ? "false" : "true";
}
if (context.Configuration.EventPostBuild.Count == 0)
{
context.Options["PostBuildEvent"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["PostBuildEventDescription"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["PostBuildEventEnable"] = FileGeneratorUtilities.RemoveLineTag;
}
else
{
context.Options["PostBuildEvent"] = Util.JoinStrings(context.Configuration.EventPostBuild, eventSeparator, escapeXml: true) + eventSeparator;
context.Options["PostBuildEventDescription"] = context.Configuration.EventPostBuildDescription != string.Empty ? context.Configuration.EventPostBuildDescription : FileGeneratorUtilities.RemoveLineTag;
context.Options["PostBuildEventEnable"] = context.Configuration.EventPostBuildExcludedFromBuild ? "false" : "true";
}
if (context.Configuration.EventCustomBuild.Count == 0)
{
context.Options["CustomBuildEvent"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["CustomBuildEventDescription"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["CustomBuildEventOutputs"] = FileGeneratorUtilities.RemoveLineTag;
}
else
{
context.Options["CustomBuildEvent"] = (context.Configuration.EventCustomBuild.JoinStrings(eventSeparator, escapeXml: true) + eventSeparator);
context.Options["CustomBuildEventDescription"] = context.Configuration.EventCustomBuildDescription != string.Empty ? context.Configuration.EventCustomBuildDescription : FileGeneratorUtilities.RemoveLineTag;
context.Options["CustomBuildEventOutputs"] = context.Configuration.EventCustomBuildOutputs != string.Empty ? context.Configuration.EventCustomBuildOutputs : FileGeneratorUtilities.RemoveLineTag;
}
if (context.Configuration.CustomBuildStep.Count == 0)
{
context.Options["CustomBuildStep"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["CustomBuildStepDescription"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["CustomBuildStepOutputs"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["CustomBuildStepInputs"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["CustomBuildStepBeforeTargets"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["CustomBuildStepAfterTargets"] = FileGeneratorUtilities.RemoveLineTag;
context.Options["CustomBuildStepTreatOutputAsContent"] = FileGeneratorUtilities.RemoveLineTag;
}
else
{
context.Options["CustomBuildStep"] = (Util.JoinStrings(context.Configuration.CustomBuildStep, eventSeparator, escapeXml: true) + eventSeparator);
context.Options["CustomBuildStepDescription"] = context.Configuration.CustomBuildStepDescription != string.Empty ? context.Configuration.CustomBuildStepDescription : FileGeneratorUtilities.RemoveLineTag;
context.Options["CustomBuildStepOutputs"] = context.Configuration.CustomBuildStepOutputs.Count == 0 ? FileGeneratorUtilities.RemoveLineTag : (context.Configuration.CustomBuildStepOutputs.JoinStrings(";", escapeXml: true));
context.Options["CustomBuildStepInputs"] = context.Configuration.CustomBuildStepInputs.Count == 0 ? FileGeneratorUtilities.RemoveLineTag : (context.Configuration.CustomBuildStepInputs.JoinStrings(";", escapeXml: true));
context.Options["CustomBuildStepBeforeTargets"] = context.Configuration.CustomBuildStepBeforeTargets != string.Empty ? context.Configuration.CustomBuildStepBeforeTargets : FileGeneratorUtilities.RemoveLineTag;
context.Options["CustomBuildStepAfterTargets"] = context.Configuration.CustomBuildStepAfterTargets != string.Empty ? context.Configuration.CustomBuildStepAfterTargets : FileGeneratorUtilities.RemoveLineTag;
context.Options["CustomBuildStepTreatOutputAsContent"] = context.Configuration.CustomBuildStepTreatOutputAsContent != string.Empty ? context.Configuration.CustomBuildStepTreatOutputAsContent : FileGeneratorUtilities.RemoveLineTag;
}
}