c++visual-studio-2015custom-build-step

How do I set up this visual studio (2015) custom build step (tool?). Basically I want a pre-preprocessor step that modifies header files (c++)


I want a run a build step that looks at a .h file, adds some code based on some external params, and hands the resulting file to the preprocessor.

I see the "Custom Build Step" in the project properties. It seems to need an output file. I just want to forward the results to the preprocessor.

It seems like the custom build step wants to do a 1-time process, not per-file or by file type.

The problem is that I don't know how to send my external executable the file currently being processed (eg, "HelloWorld.cpp"). $(InputName) and %(Filename) are blank and docs say it's deprecated. How do I send the filename to my external executable?

But even if I get that working, I don't want to set this per-file. I want all header files to go through this process.

Any ideas?

I've looked at:

https://msdn.microsoft.com/en-us/library/dd293663.aspx?f=255&MSPPError=-2147217396

https://msdn.microsoft.com/en-us/library/hefydhhy(v=vs.90).aspx

https://msdn.microsoft.com/en-us/library/ff770593(v=vs.140).aspx

working on a debug, x64 config on windows.


Solution

  • First of all, No, you cannot modify a file and pass along the results to the next stage (that I could see). I'd need some sort of Program Transformation System.

    So I need an intermediate file. That file has to be added to the project, even if it gets overwritten by your code generator. I can associate c++ header files with a custom build tool, and they will all get called one-by-one in the stage of the build specified in the Custom Build Step. The custom build tool will modify the intermediate file(s), and all is well.

    The VS 2015 name for the current file being processed is %(Filename). In older versions it has been $(ProjectName) and $(InputName).