0

So I've look at a few questions here which popped up after a search, but I still haven't managed to get this to work.

My project has two files, main.cpp and shader.comp.

The shader needs to be compiled before the main program is ran and I have a small .bat script that does just that. It's set to run as a pre-build event.

However, if I edit shader.comp and leave main.cpp unmodified since I last ran the project, there is no need to rebuild the project (according to VS anyway), so there is no need to run any pre-build events and my shader doesn't get compiled.

Is there a way to tell VS2017 (or VS2019) that if some file is modified, then run something, or at least a way to add an arbitrary file to list of files that VS checks against when deciding whether to run the build or not?

I've tried setting "Exclude from build" to "No" in the file properties, but no matter what "Item type" I choose, editing just the shader won't trigger the rebuild.

Karlovsky120
  • 6,212
  • 8
  • 41
  • 94

2 Answers2

1

It's possible to define the shader that needs to be compiled as Custom Build Tool in the properties of the file (as Item Type). This will open another menu in the properties where cmd script and similar can be written.

In this particular case, value for Command Line was:

glslangValidator.exe -V -o "%(RootDir)%(Directory)%(Filename).spv" "%(FullPath)"

And the Outputs:

%(RootDir)%(Directory)%(Filename).spv

In short, if file defined in Outputs doesn't exists or is older than the owner of this property (the file that needs to be compiled), the Command Line argument will be ran in cmd.

Official documentation has more info on this.

Karlovsky120
  • 6,212
  • 8
  • 41
  • 94
  • Hi friend, thanks for your sharing and please mark your reply as answer and that will help other community members who easier search this useful information, it just a reminder :) – LoLance Aug 20 '19 at 07:25
  • Yeah, I was waiting for the 2 day timer to run out. :) – Karlovsky120 Aug 20 '19 at 07:37
0

Maybe you can get some help from this issue. You can specify the files for VS Up-To-Date check.

<Project...>
...
  <ItemGroup>
    <UpToDateCheckInput Include="shader.comp" />  <!--when this file is in the project folder-->
    <!--<UpToDateCheckInput Include="path/shader.comp" />-->
  </ItemGroup>
</Project>

And this script into your project file. Then if there's any change to shader.comp file,VS will build your project.

Note: In this way, if you only change the shader.comp file , but not change the source file(xx,cpp), the build will start but vs will skip the compile target of C++ source code. Only when you modify the source code main.cpp, then VS will run the pre-build event and compile the code. Let me know if it's what you want, hope i didn't misunderstand anything :)

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • You weren't all that clear. Let's say I do all this and that my project is up to date. I then change shader.comp and hit run. Will the prebuild event be executed or not? I want it to be. – Karlovsky120 Aug 17 '19 at 21:23
  • I think I understand what you did actually. Yeah, this would work as a general solution. The answer I gave works better in this particular case, since it's a VS feature that was explicitly designed for this. – Karlovsky120 Aug 17 '19 at 22:52