2

I would like to add a custom preprocessor for .cpp files in my Visual C++ MSBuild project.

Currently I am using a custom buildstep to find all .cpp files and rewrite them (destroying the original content) before they a being compiled. This is no longer acceptable as the preprocessor should make changes "invisible" to the developer (converting lines with a scripting language to real C++ code).

The preprocessing should be done "On the fly". Dependencies should not be affected at all. The custom preprocessor is able to create #line preprocessor directive so compiler errors can be redirected to the original file.

It seems to me that build events and custom build steps are no viable way to do this so.

I tried to replace to compiler binary with my own which calls the custom preprocessor and feeds the output into the original compiler, but this was more of a "proof of concept" and is surely not a production-ready solution.

Q1: Where do I have to look for what I am trying to achieve?

Q2: and is there a possibility to do this in a solution without changing the Visual C++ installation (The custom preprocessor is also part of the solution and compiled before any of the other projects)

Andreas H.
  • 1,757
  • 12
  • 24
  • 1
    How about overriding the compile command or the path to the compiler executable used? That's cleaner than simply replacing the compiler binary and is relatively easy to do, and since your proof of concept already seems to bu usable it will be quick to implement as well. See e.g. https://stackoverflow.com/questions/45835043/how-to-override-compile-command-of-visual-studio-2017-community. – stijn Apr 27 '18 at 08:29
  • The answer you wrote on 4585043 would also be perfect for my question :) I'll try overwriting when I'm back in the office. Is there a possibility to get path and filename of the original compiler? Perhaps some MSBuild or enironment variable? However, thanks a lot for your answer! – Andreas H. Apr 27 '18 at 12:06
  • Couple of ways.. `where cl` on the command line, and I assume within msbuild CLToolExe is set to the same path, before you override it. And there's definitely other properties pointing to the VC bin directory but can't check as I don't have access to build tools atm. – stijn Apr 27 '18 at 19:49

0 Answers0