Sharpmake icon indicating copy to clipboard operation
Sharpmake copied to clipboard

Adding a CustomBuildStep

Open kelleyma49 opened this issue 6 years ago • 2 comments

I'm trying to add a custom build steps to compile my shader files, but the custom build properties are empty.

I derive from Project.Configuration.CustomFileBuildStep and fill in the properties of the class:

public class ShaderCompileBuildStep : Project.Configuration.CustomFileBuildStep
 {
     ShaderCompileBuildStep(string sourceFileName)
      {
          // fill in KeyInput, Executable, etc.
      }

I add the extension to the project's supported extensions:

SourceFilesExtensions.Add(".fx");

I then override Project.ExcludeOutputFiles():

protected override void ExcludeOutputFiles()
{
    base.ExcludeOutputFiles();
    GenerateShaderCustomBuildSteps();
}

In GenerateShaderCustomBuildSteps(), I add the custom build steps to the project configuration:

 private void GenerateShaderCustomBuildSteps()
 {
     foreach (var f in ResolvedSourceFiles.Where(f => System.IO.Path.GetExtension(f).ToLower() == ".fx"))
    {
        foreach (Project.Configuration conf in Configurations)
        {
            conf.CustomFileBuildSteps.Add(new ShaderCompileBuildStep(f));
         }
    }
}

In Visual Studio, my .fx files have the proper "Item Type" of "Custom Build Tool", but all of the properties in "Custom Build Tool" are empty.

What am I doing wrong?

kelleyma49 avatar Aug 02 '19 22:08 kelleyma49

I managed to add support for hlsl files and included a link to it, hoping it can help other help people. https://github.com/sammyfreg/netImgui/blob/master/Build/netImgui.sharpmake.cs

I have tweaked mine to generate a c header file with the compiled shader, but can easily be adapted to other needs, by looking up the fxc commandline compile options.

sammyfreg avatar Aug 29 '20 06:08 sammyfreg

@sammyfreg That's a really useful example, thank you so much!

Linkeragon59 avatar Nov 13 '20 03:11 Linkeragon59