Sharpmake icon indicating copy to clipboard operation
Sharpmake copied to clipboard

Target fragment combination filtering

Open sammyfreg opened this issue 3 years ago • 0 comments

The fragment feature to generate multiple build target combination at the same times works really well.

I have a local improvement in my generations files (without modifying Sharpmake) that I think could be beneficial to be supported natively. It is the ability to filter out certain fragments combination, before adding the target.

Example: I request the support of...

  • DevEnv: VS2022, Makefile
  • Platform: Win64, Linux But I do not want Linux to generate a VS2022 solution...

Now, I could just create 2 differents Targets to accommodate this, but in more complex case, it ends up having to specify individually each supported Target combination.

My suggestion is to have a virtual method that Sharpmake queries just before internally adding each target combination (or could use the tagging method similar to [configure]). Here's an example of what it could look like:

public class CustomTarget : Target
{
	public override bool IsValidTarget()
	{
		if(  (Platform& Platform.Linux) != 0 && DevEnv.IsVisualStudio() ){
			return false;
		}	

		return base.IsValidTarget();
	}
}

public class SomeBase : Project
{
	public ProjectBase()
	: base(typeof(CustomTarget))
	{
		Name = "SomeProject";		
		outTargets.Add(new CustomTarget(
							DevEnv.vs2022 | DevEnv.make, 
							Platform.win64|Platform.linux, 
							Optimization.Debug | Optimization.Release | Optimization.Retail));
	}
}

This would allow user to easily defines their own conditions and also handle their custom fragments.

sammyfreg avatar Sep 04 '22 11:09 sammyfreg